name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  actions: write

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  check:
    name: Check
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo check --all-targets 
  test:
    name: Test
    runs-on: ${{ matrix.os }}
    timeout-minutes: 30
    env:
      RUST_BACKTRACE: 1
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      # v0_12_2_apis.rs uses 5 shared `static AtomicU32` counters, so parallel
      # test execution race-counts and intermittently fails (PIPELINE_BEGIN_CALLS
      # observes 2 when 1 is expected). Run all tests with --test-threads=1 to
      # serialize across files. Slower but deterministic; matrix already runs
      # two OSes in parallel.
      - run: cargo test --locked --no-fail-fast -- --test-threads=1

  doc:
    name: Doc
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - env:
          RUSTDOCFLAGS: -D warnings
        # Build docs with all features so intra-doc links into cfg-gated items
        # (e.g. JIT-only types behind `feature = "jit"`) resolve.
        run: cargo doc --no-deps --all-features 