name: CI

on:
  push:
    branches: [master]
  pull_request:

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  check:
    name: Build, lint, audit, test
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy

      - uses: Swatinem/rust-cache@v2

      - uses: taiki-e/install-action@cargo-hack

      # Build first — catches template include_str! failures and compile errors
      # before running the slower test step.
      - name: Build
        run: cargo build --release

      - name: Check formatting
        run: cargo fmt --check

      - name: Run clippy
        run: cargo clippy --all-targets -- -D warnings

      - name: Cargo audit
        uses: rustsec/audit-check@858dc40f52ca2b8570b7a997c1c4e35c6fc9a432
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      # Integration tests invoke the binary and compile the generated C.
      # gcc is pre-installed on ubuntu-latest.
      - name: Run test suite
        run: cargo test --release

      - name: Check Rust version compatibility
        run: cargo hack check --rust-version --all-targets
