name: CI
on: [push, pull_request]

permissions:
  contents: read

env:
  RUSTDOCFLAGS: -Dwarnings
  RUSTFLAGS: -Dwarnings

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - "1.32" # msrv
          - stable
          - beta
          - nightly
    steps:
      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      - name: Install Rust ${{ matrix.rust }}
        run: |
          rustup self update
          rustup update ${{ matrix.rust }}
          rustup default ${{ matrix.rust }}
          rustc -vV
      - name: Run tests
        run: |
          set -eux
          # Remove `-Dwarnings` at the MSRV since lints may be different
          [ "${{ matrix.rust }}" = "1.32" ] && export RUSTFLAGS="--cfg msrv_test"
          cargo test

  rustfmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      - name: Install Rust Stable
        run: |
          rustup update stable
          rustup default stable
          rustup component add rustfmt
      - name: Run rustfmt
        run: cargo fmt -- --check
