.github/workflows/rust-ci.yml

GitHub
name: Rust CI

on:
  push:
    branches: [main]
    paths-ignore:
      - "playground/**"
      - "website/**"
      - "*.md"
      - "docs/**"
  pull_request:
    branches: [main]
    paths-ignore:
      - "playground/**"
      - "website/**"
      - "*.md"
      - "docs/**"

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always
  INSTA_UPDATE: "no"

jobs:
  workflow-policy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - name: Reject privileged PR workflows
        shell: bash
        run: |
          pattern="^[[:space:]]*pull_request""_target[[:space:]]*:"
          if grep -R --line-number --include='*.yml' --include='*.yaml' -E "$pattern" .github/workflows; then
            echo "::error::Privileged PR workflows are not allowed. Use pull_request for PR code."
            exit 1
          fi

  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - name: Install pinned Rust toolchain
        run: rustc --version
      - name: Format check
        run: cargo fmt --check

  check:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - name: Install pinned Rust toolchain
        run: rustc --version
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@nextest
      - name: Clippy
        # --all-targets matches the local Definition of Done gate: it also
        # lints tests, which plain `cargo clippy` skips.
        run: cargo clippy --workspace --all-targets -- -D warnings
      - name: Test
        run: cargo nextest run --workspace --profile ci
      - name: Doctests
        # nextest does not run doctests; keep them covered (none today, but
        # this guards against a future doctest being silently skipped).
        run: cargo test --workspace --doc