From 0b8c17eb3ccc5892e36a09177230aa00e20d84d6 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Sat, 31 Oct 2026 09:02:31 -0400 Subject: [PATCH 1/2] ci: run push checks only on main A push sends new commits to GitHub. The workspace and security checks run for a push only when it goes to the main branch. Other branches are checked through their pull request, so each update to a pull request is checked once. Each run belongs to a group: the name GitHub uses to decide which runs may cancel each other. When a pull request gets another update, any run that is checking an earlier update of the same pull request is cancelled, so only the latest update is checked. Runs on main, scheduled runs and manual runs each get their own group, so they are never cancelled. The security check runs for a push to main or a pull request update only when the change touches a file in its path filters, the file list that decides whether a check runs. It also runs every Monday and when started by hand. --- .github/workflows/security.yml | 9 +++++++++ .github/workflows/workspace.yml | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 227149c..2f34063 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -1,7 +1,9 @@ name: security on: + # Pull request branches are checked through pull_request, so they do not run twice. push: + branches: [main] paths: - "**/Cargo.toml" - Cargo.lock @@ -15,6 +17,13 @@ on: - cron: "17 9 * * 1" workflow_dispatch: +# A newer update to the same pull request stops the older run. +# Every other run (main pushes, scheduled and manual runs) gets its own +# group so it is never stopped. +concurrency: + group: ci-${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + permissions: contents: read diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index 4fff553..d8c089b 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -1,9 +1,18 @@ name: workspace on: + # Pull request branches are checked through pull_request, so they do not run twice. push: + branches: [main] pull_request: +# A newer update to the same pull request stops the older run. +# Every other run, such as a push to main, gets its own group so it is +# never stopped. +concurrency: + group: ci-${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + permissions: contents: read From b2895c7edd978932dea333fa95bf9b925c14fb3f Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Sat, 31 Oct 2026 09:02:31 -0400 Subject: [PATCH 2/2] ci: cache the cargo-audit program The security check uses cargo-audit 0.22.2, a program that compares our dependencies, the outside libraries this project uses, with a public list of known security problems. The program has its own cache: a saved copy kept between runs so the program is not rebuilt each time. The cache name covers the program version, the system and processor type, and the exact Rust compiler. After the Rust compiler and tools are set up, the check restores the cache and makes sure the program reports version 0.22.2. If the cache is empty or the program does not match, the check builds cargo-audit and saves it to the cache. On every run, cargo-audit downloads the latest list of known security problems. --- .github/workflows/security.yml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 2f34063..8bbeb70 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -31,10 +31,40 @@ jobs: rustsec: runs-on: ubuntu-24.04 timeout-minutes: 30 + env: + CARGO_AUDIT_VERSION: 0.22.2 steps: - uses: actions/checkout@v7.0.1 - uses: dtolnay/rust-toolchain@stable + - name: Hash the Rust compiler + id: rustc + run: | + hash=$(rustc -vV | sha256sum | cut -d ' ' -f 1) + echo "hash=$hash" >> "$GITHUB_OUTPUT" + # Cache only the program folder; .cargo/bin holds toolchain shims. + - uses: actions/cache/restore@v6.1.0 + id: cargo-audit-cache + with: + path: ~/.cache/cargo-audit-${{ env.CARGO_AUDIT_VERSION }} + key: cargo-audit-${{ env.CARGO_AUDIT_VERSION }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.rustc.outputs.hash }} - name: Install cargo-audit - run: cargo install cargo-audit --version 0.22.2 --locked + id: install-cargo-audit + run: | + dir="$HOME/.cache/cargo-audit-$CARGO_AUDIT_VERSION" + if [ -x "$dir/bin/cargo-audit" ] && + [ "$("$dir/bin/cargo-audit" --version)" = "cargo-audit $CARGO_AUDIT_VERSION" ]; then + echo "installed=false" >> "$GITHUB_OUTPUT" + else + rm -rf "$dir" + cargo install cargo-audit --version "$CARGO_AUDIT_VERSION" --locked --root "$dir" + [ "$("$dir/bin/cargo-audit" --version)" = "cargo-audit $CARGO_AUDIT_VERSION" ] + echo "installed=true" >> "$GITHUB_OUTPUT" + fi + echo "$dir/bin" >> "$GITHUB_PATH" + - uses: actions/cache/save@v6.1.0 + if: steps.install-cargo-audit.outputs.installed == 'true' + with: + path: ~/.cache/cargo-audit-${{ env.CARGO_AUDIT_VERSION }} + key: ${{ steps.cargo-audit-cache.outputs.cache-primary-key }} - name: Check RustSec advisories run: cargo audit