diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 227149c..8bbeb70 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 @@ -22,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 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