name: build
on: [push]
env:
  # A fixed version used for testing, so that the builds don't
  # spontaneously break after a few years.
  RUST_VERSION: "1.90.0"
  CARGO_TERM_COLOR: always

jobs:
  # Checks syntax formatting.
  fmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    env:
      RUSTFLAGS: "-D warnings"
    steps:
      - uses: actions/checkout@v4
      - name: Install rust version
        run: rustup install ${RUST_VERSION}
      - name: Add rustfmt
        run: rustup +${RUST_VERSION} component add rustfmt
      - name: Check formatting
        run: cargo +${RUST_VERSION} fmt -- --check

  # Run basic code validity check.
  check:
    needs: fmt
    name: Check
    runs-on: ubuntu-latest
    env:
      RUSTFLAGS: "-D warnings"
    steps:
      - uses: actions/checkout@v4
      - name: Install rust version
        run: rustup install ${RUST_VERSION}
      - name: check
        run: cargo +${RUST_VERSION} check

  # Run tests.
  test:
    needs: check
    name: Test Suite (linux)
    runs-on: ubuntu-latest
    env:
      RUSTFLAGS: "-D warnings"
    steps:
      - uses: actions/checkout@v4
      - name: Install rust version
        run: rustup install ${RUST_VERSION}
      - name: check
        run: cargo +${RUST_VERSION} test

  # Run tests on macOS.
  test-macos:
    needs: check
    name: Test Suite (macOS)
    runs-on: macos-latest
    env:
      RUSTFLAGS: "-D warnings"
    steps:
      - uses: actions/checkout@v4
      - name: Install rust version
        run: rustup install ${RUST_VERSION}
      - name: check
        run: cargo +${RUST_VERSION} test

  # Checks code style.
  clippy:
    needs: check
    name: Clippy
    runs-on: ubuntu-latest
    env:
      RUSTFLAGS: "-D warnings"
    steps:
      - uses: actions/checkout@v4
      - name: Install rust version
        run: rustup install ${RUST_VERSION}
      - name: Add clippy
        run: rustup +${RUST_VERSION} component add clippy
      - name: check
        run: cargo +${RUST_VERSION} clippy
