name: CI

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

env:
  CARGO_TERM_COLOR: always

permissions:
  contents: read
  checks: write

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
        with:
          toolchain: stable
          components: clippy, rustfmt

      - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
        with:
          token: ${{secrets.GITHUB_TOKEN}}

      - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2

      - name: Install Nextest
        run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C /usr/local/bin

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

      - name: Test
        run: |
          cargo nextest run
          cargo nextest run --all-features

      - name: Cargo doctests
        run: |
          cargo test --doc
          cargo test --doc --all-features

      - name: Clippy
        uses: auguwu/clippy-action@94a9ff2f6920180b89e5c03d121d0af04a9d3e03 # 1.4.0
        with:
          token: ${{secrets.GITHUB_TOKEN}}

      - name: Cargo fmt
        run: cargo fmt --check
