name: PR

on:
  pull_request:
  push:
    branches: [main]

jobs:
  format:
    name: Format
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@1.80
        with:
          components: rustfmt

      - run: cargo fmt --all --check

  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@1.80
        with:
          components: clippy

      - uses: Swatinem/rust-cache@v2

      - uses: actions-rs/clippy-check@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

  test:
    name: Test
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@1.80

      - uses: Swatinem/rust-cache@v2

      - run: cargo test --workspace --no-fail-fast
