# Every hook defined in .pre-commit-config.yaml: file hygiene, spelling, # workflow analysis, link checking, the cargo-deny audit, and rustfmt. Runs the # same `cargo xtask check hooks` a contributor runs. # # This is its own workflow rather than a job in ci.yaml so that it can run on # every change -- including docs-only pushes, which ci.yaml skips -- without # dragging the build and test matrix along with it. name: "Pre-commit hooks" on: pull_request: push: branches: - main env: CARGO_INCREMENTAL: 0 RUST_BACKTRACE: 1 CARGO_TERM_COLOR: always CLICOLOR: 1 CLICOLOR_FORCE: 1 permissions: contents: read # Only allow one run of the workflow per branch / PR at a time. concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: hooks: name: "Pre-commit hooks" runs-on: ubuntu-26.04 timeout-minutes: 15 steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: Set up rust toolchain run: rustup toolchain install --profile minimal - name: Enable cargo cache uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: Install prek uses: taiki-e/install-action@68a389c788b2cd04016ce8c80ee23b80d2ab3d68 # v2.88.1 with: tool: prek - name: Cache hook environments uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ~/.cache/prek key: prek-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }} restore-keys: prek-${{ runner.os }}- - name: Prepare hooks run: prek prepare-hooks env: # Pass through the token in case 'cargo binstall' needs it GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run pre-commit hooks run: cargo xtask check hooks # The fixing hooks rewrite files in place and then fail. Show what they # changed so the required fix is visible in the log. - name: Show changes made by hooks if: failure() run: git diff