name: check
permissions:
  contents: read
# This configuration allows maintainers of this repo to create a branch and pull request based on
# the new branch. Restricting the push trigger to the main branch ensures that the PR only gets
# built once.
on:
  push:
    branches:
      - main
      - latest
  pull_request:

# If new code is pushed to a PR branch, then cancel in progress workflows for that PR.
concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

defaults:
  run:
    shell: bash -xe {0}

jobs:
  fmt:
    name: cargo fmt
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8

      - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035
        with:
          github_access_token: ${{ secrets.GITHUB_TOKEN }}
      - name: Populate the nix store
        run: nix develop --command echo

      - name: cargo fmt
        run: nix develop --command cargo fmt --check

  check-dev-deps:
    name: Check dev-deps.txt
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
      - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035
        with:
          github_access_token: ${{ secrets.GITHUB_TOKEN }}
      - name: Populate the nix store
        run: nix develop --command echo

      - run: nix develop --command ./scripts/dev-deps.sh
      - run: |
          if git diff --quiet; then
              echo "No changes"
          else
              echo "::error::Changes in dev-deps.txt detected"
              git diff
              exit 1
          fi

  clippy:
    name: clippy
    runs-on: ubuntu-24.04
    strategy:
      fail-fast: false
    steps:
      - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8

      - uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035
        with:
          github_access_token: ${{ secrets.GITHUB_TOKEN }}

      - name: Populate the nix store
        run: nix develop --command echo

      - name: cargo clippy
        run: nix develop --command cargo clippy --workspace --all-targets -- -D warnings
