name: CI

on:
  push:
  pull_request:

jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: 1.88
          components: rustfmt, clippy

      - name: Cache Cargo
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-

      - name: Fmt
        run: cargo fmt -- --check

      - name: Clippy
        run: cargo clippy -- -D warnings

      - name: Cargo Deny (licenses, bans, advisories, sources)
        uses: EmbarkStudios/cargo-deny-action@v2

      - name: Install cargo-audit
        uses: taiki-e/install-action@v2
        with:
          tool: cargo-audit

      - name: Cargo Audit
        run: cargo audit

      - name: Test
        run: cargo test

      - name: Test (all features)
        run: cargo test --all-features

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

      - name: Install cargo-tarpaulin
        uses: taiki-e/install-action@v2
        with:
          tool: cargo-tarpaulin

      - name: Code Coverage
        run: cargo tarpaulin --all-features --out Xml --output-dir target/coverage

      - name: Upload Coverage to Codecov
        uses: codecov/codecov-action@v7
        with:
          files: target/coverage/cobertura.xml
          fail_ci_if_error: false

      - name: Bench (report only)
        run: cargo bench --bench strategy_eval --features strategy -- --noplot
