name: CI

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

env:
  CARGO_TERM_COLOR: always

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
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: Build (default features)
        run: cargo build --verbose
      - name: Test (default features)
        run: cargo test --verbose

      # block-detect pulls pin-project-lite.
      - 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
      - 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 (default features)
        run: cargo clippy --all-targets -- -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
      - 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
      - uses: dtolnay/rust-toolchain@1.85
      - uses: Swatinem/rust-cache@v2
      - run: cargo build --all-features --verbose
