name: CI

on:
  push:
    branches: ["develop"]
  pull_request:
    branches: ["develop"]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
        rust: [default, msrv]

    steps:
      - uses: actions/checkout@v5

      - name: Install Nix
        uses: nixbuild/nix-quick-install-action@v34

      - name: Setup Nix cache
        uses: nix-community/cache-nix-action@v6
        with:
          primary-key: nix-${{ runner.os }}-${{ matrix.rust }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
          restore-prefixes-first-match: nix-${{ runner.os }}-${{ matrix.rust }}-

      - name: Build
        run: nix develop .#${{ matrix.rust }} --command cargo build --verbose

      - name: Run cargo tests
        run: nix develop .#${{ matrix.rust }} --command cargo test --verbose

      - name: Run integration tests
        run: nix develop .#${{ matrix.rust }} --command tests/integration.sh

      - name: Check formatting
        run: nix develop .#${{ matrix.rust }} --command cargo fmt --check

      - name: Lint with clippy
        run: nix develop .#${{ matrix.rust }} --command cargo clippy
