name: CI

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

env:
  CARGO_TERM_COLOR: always

# Reusable shell snippet for cloning every sibling crate dev-tools
# depends on as a path-dep. Keep this list in sync with the optional
# deps in Cargo.toml.
#
# YAML anchors aren't supported in `run:` blocks, so this block is
# repeated below. Update all copies together.

jobs:
  test:
    name: Test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v5
      - name: Check out sibling crates (path deps)
        run: |
          git clone --depth 1 https://github.com/jamesgober/dev-report.git ../dev-report
          git clone --depth 1 https://github.com/jamesgober/dev-fixtures.git ../dev-fixtures
          git clone --depth 1 https://github.com/jamesgober/dev-bench.git ../dev-bench
          git clone --depth 1 https://github.com/jamesgober/dev-async.git ../dev-async
          git clone --depth 1 https://github.com/jamesgober/dev-stress.git ../dev-stress
          git clone --depth 1 https://github.com/jamesgober/dev-chaos.git ../dev-chaos
          git clone --depth 1 https://github.com/jamesgober/dev-coverage.git ../dev-coverage
          git clone --depth 1 https://github.com/jamesgober/dev-security.git ../dev-security
          git clone --depth 1 https://github.com/jamesgober/dev-deps.git ../dev-deps
          git clone --depth 1 https://github.com/jamesgober/dev-ci.git ../dev-ci
          git clone --depth 1 https://github.com/jamesgober/dev-fuzz.git ../dev-fuzz
          git clone --depth 1 https://github.com/jamesgober/dev-flaky.git ../dev-flaky
          git clone --depth 1 https://github.com/jamesgober/dev-mutate.git ../dev-mutate
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      # Default features (fixtures + bench).
      - name: Build (default features)
        run: cargo build --verbose
      - name: Test (default features)
        run: cargo test --verbose

      # No default features (report-only).
      - name: Build (no default features)
        run: cargo build --no-default-features --verbose
      - name: Test (no default features)
        run: cargo test --no-default-features --verbose

      # All features (full).
      - name: Build (all features)
        run: cargo build --all-features --verbose
      - name: Test (all features)
        run: cargo test --all-features --verbose

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - name: Check out sibling crates (path deps)
        run: |
          git clone --depth 1 https://github.com/jamesgober/dev-report.git ../dev-report
          git clone --depth 1 https://github.com/jamesgober/dev-fixtures.git ../dev-fixtures
          git clone --depth 1 https://github.com/jamesgober/dev-bench.git ../dev-bench
          git clone --depth 1 https://github.com/jamesgober/dev-async.git ../dev-async
          git clone --depth 1 https://github.com/jamesgober/dev-stress.git ../dev-stress
          git clone --depth 1 https://github.com/jamesgober/dev-chaos.git ../dev-chaos
          git clone --depth 1 https://github.com/jamesgober/dev-coverage.git ../dev-coverage
          git clone --depth 1 https://github.com/jamesgober/dev-security.git ../dev-security
          git clone --depth 1 https://github.com/jamesgober/dev-deps.git ../dev-deps
          git clone --depth 1 https://github.com/jamesgober/dev-ci.git ../dev-ci
          git clone --depth 1 https://github.com/jamesgober/dev-fuzz.git ../dev-fuzz
          git clone --depth 1 https://github.com/jamesgober/dev-flaky.git ../dev-flaky
          git clone --depth 1 https://github.com/jamesgober/dev-mutate.git ../dev-mutate
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - name: Clippy (all features)
        run: cargo clippy --all-targets --all-features -- -D warnings
      - name: Clippy (no default features)
        run: cargo clippy --all-targets --no-default-features -- -D warnings

  fmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all -- --check

  docs:
    name: Doc build
    runs-on: ubuntu-latest
    env:
      RUSTDOCFLAGS: "-D warnings"
    steps:
      - uses: actions/checkout@v5
      - name: Check out sibling crates (path deps)
        run: |
          git clone --depth 1 https://github.com/jamesgober/dev-report.git ../dev-report
          git clone --depth 1 https://github.com/jamesgober/dev-fixtures.git ../dev-fixtures
          git clone --depth 1 https://github.com/jamesgober/dev-bench.git ../dev-bench
          git clone --depth 1 https://github.com/jamesgober/dev-async.git ../dev-async
          git clone --depth 1 https://github.com/jamesgober/dev-stress.git ../dev-stress
          git clone --depth 1 https://github.com/jamesgober/dev-chaos.git ../dev-chaos
          git clone --depth 1 https://github.com/jamesgober/dev-coverage.git ../dev-coverage
          git clone --depth 1 https://github.com/jamesgober/dev-security.git ../dev-security
          git clone --depth 1 https://github.com/jamesgober/dev-deps.git ../dev-deps
          git clone --depth 1 https://github.com/jamesgober/dev-ci.git ../dev-ci
          git clone --depth 1 https://github.com/jamesgober/dev-fuzz.git ../dev-fuzz
          git clone --depth 1 https://github.com/jamesgober/dev-flaky.git ../dev-flaky
          git clone --depth 1 https://github.com/jamesgober/dev-mutate.git ../dev-mutate
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo doc --all-features --no-deps

  msrv:
    name: MSRV (Rust 1.85)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - name: Check out sibling crates (path deps)
        run: |
          git clone --depth 1 https://github.com/jamesgober/dev-report.git ../dev-report
          git clone --depth 1 https://github.com/jamesgober/dev-fixtures.git ../dev-fixtures
          git clone --depth 1 https://github.com/jamesgober/dev-bench.git ../dev-bench
          git clone --depth 1 https://github.com/jamesgober/dev-async.git ../dev-async
          git clone --depth 1 https://github.com/jamesgober/dev-stress.git ../dev-stress
          git clone --depth 1 https://github.com/jamesgober/dev-chaos.git ../dev-chaos
          git clone --depth 1 https://github.com/jamesgober/dev-coverage.git ../dev-coverage
          git clone --depth 1 https://github.com/jamesgober/dev-security.git ../dev-security
          git clone --depth 1 https://github.com/jamesgober/dev-deps.git ../dev-deps
          git clone --depth 1 https://github.com/jamesgober/dev-ci.git ../dev-ci
          git clone --depth 1 https://github.com/jamesgober/dev-fuzz.git ../dev-fuzz
          git clone --depth 1 https://github.com/jamesgober/dev-flaky.git ../dev-flaky
          git clone --depth 1 https://github.com/jamesgober/dev-mutate.git ../dev-mutate
      - uses: dtolnay/rust-toolchain@1.85
      - uses: Swatinem/rust-cache@v2
      - run: cargo build --all-features --verbose
