name: CI

on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-Dwarnings"

jobs:
  check:
    name: fmt + clippy + test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

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

      - uses: Swatinem/rust-cache@v2

      - name: cargo fmt --check
        run: cargo fmt --all -- --check

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

      - name: cargo test
        run: cargo test --locked --all-targets

      - name: cargo test (doc-tests)
        run: cargo test --locked --doc

      # Verify the library compiles without the CLI feature — proves we
      # haven't accidentally leaked clap / anstream / etc. into the lib path.
      - name: cargo build --no-default-features
        run: cargo build --locked --no-default-features
