name: CI

on:
  push:
    branches: [main]
  pull_request:

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0

jobs:
  # Gate: workspace must build and the full test suite must pass.
  # Includes a compile-check of the criterion benches so a broken
  # bench doesn't go unnoticed between manual `cargo bench` runs.
  test:
    name: build + test
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo + target
        uses: Swatinem/rust-cache@v2

      - name: Build workspace
        run: cargo build --workspace --all-targets

      - name: Run tests
        run: cargo test --workspace

      - name: Compile-check benches
        run: cargo build --workspace --benches

  # Gate: codebase is fmt-clean as of v0.1.0; keep it that way.
  fmt:
    name: fmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all --check

  # Informational: clippy lints with default severity. Same deal as
  # fmt — when the codebase is lint-clean, drop continue-on-error and
  # add `-- -D warnings` to make this a real gate.
  clippy:
    name: clippy (informational)
    runs-on: ubuntu-latest
    continue-on-error: true
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo clippy --workspace --all-targets
