name: CI

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

env:
  CARGO_TERM_COLOR: always

jobs:
  fmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - name: Check formatting
        run: cargo fmt --all -- --check

  check:
    name: Cargo Check
    strategy:
      matrix:
        features:
          - ""
          - "dbg-pls"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      - name: Setup Rust cache
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.features }}
      - name: Check with no features
        if: matrix.features == ''
        run: cargo check --verbose
      - name: Check with features
        if: matrix.features != ''
        run: cargo check --verbose --features "${{ matrix.features }}"

  test:
    name: Tests
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      - name: Setup Rust cache
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.os }}-${{ matrix.features }}-test
      - name: Install nextest
        uses: taiki-e/install-action@nextest
      - name: Run tests
        run: cargo nextest run --verbose --all-features
      - name: Run doc tests
        run: cargo test --all-features --doc
