name: CI

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

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0
  RUSTFLAGS: "-Dwarnings"
  RUST_BACKTRACE: 1
  CARGO_PROFILE_DEV_DEBUG: 0
  CARGO_UNSTABLE_SPARSE_REGISTRY: true
  CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
  CACHE_ON_FAILURE: true

jobs:
  test:
    name: Test Suite
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    
    steps:
    - uses: actions/checkout@v6

    - name: Install Rust
      uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        components: rustfmt, clippy

    - name: Install nextest
      uses: taiki-e/install-action@nextest

    - name: Run tests
      run: cargo nextest run --all-features

    - name: Run doc tests
      run: cargo test --doc --all-features

    - name: Run clippy
      run: cargo clippy --all-targets --all-features -- -D warnings
    
    - name: Check formatting
      run: cargo fmt --all -- --check
    
    - name: Check documentation
      run: cargo doc --no-deps --document-private-items

  check:
    name: Cargo Check
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6

    - name: Install Rust
      uses: actions-rust-lang/setup-rust-toolchain@v1

    - name: Check all targets
      run: cargo check --all-targets --all-features

  examples:
    name: Build Examples
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6

    - name: Install Rust
      uses: actions-rust-lang/setup-rust-toolchain@v1

    - name: Build all examples
      run: cargo build --examples --all-features
