name: CI

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: -Dwarnings

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

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

      - name: Clippy
        run: cargo clippy --all-targets

      - name: Build
        run: cargo build

      - name: Test
        run: cargo test

      - name: Doc tests
        run: cargo test --doc

      # Feature-gated deps (sbits, ans) tested only when published versions match local
      - name: Clippy (ans feature)
        run: cargo clippy --all-targets --features ans

      - name: Test (ans feature)
        run: cargo test --features ans

  msrv:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@1.75.0
      - uses: Swatinem/rust-cache@v2

      - name: Check MSRV
        run: |
          rm -f Cargo.lock  # v4 lock file requires Cargo 1.83+
          cargo check
