Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

ci: gate rust caches to main and share one per OS to fit the 10 GB cap (#3323)

Maximilian Roos225b232b511f
diff --git a/.github/actions/test-setup/action.yaml b/.github/actions/test-setup/action.yaml
index 0fd4f93c3..c097f9ba9 100644
--- a/.github/actions/test-setup/action.yaml
+++ b/.github/actions/test-setup/action.yaml
@@ -4,6 +4,17 @@ description: |
Used by the test matrix and the cargo-affected jobs (which add their own
cargo-affected + llvm-tools steps after this).
+inputs:
+ save-cache:
+ description: >-
+ Whether this job may save the shared rust cache (and then only on main).
+ `test` is the canonical saver and leaves this at the default; everyone
+ else (collect-affected, affected-tests, release-target) passes 'false' so
+ they restore main's cache but never write — keeps instrumented
+ (collect-affected) and cross-compiled (release-target) artifacts out of
+ the shared cache, and stops PR runs depositing single-use caches.
+ default: "true"
+
runs:
using: composite
steps:
@@ -31,6 +42,16 @@ runs:
cache-bin: false
# Bumped to invalidate caches that already include the stale bin.
prefix-key: v1-rust
+ # One shared cache per OS (rust-cache appends os/arch) across the test
+ # family — `test`, `affected-tests`, `collect-affected`. The PR-only
+ # `affected-tests` job restores `test`'s main cache instead of a cache
+ # of its own (it never runs on main, so a per-job key would have no
+ # baseline and miss every time).
+ shared-key: shared
+ # Only `test` on main writes the shared cache; see the `save-cache`
+ # input. PRs restore main's cache and never deposit single-use ones,
+ # which is what keeps the repo under the 10 GB cache cap.
+ save-if: ${{ inputs.save-cache == 'true' && github.ref == 'refs/heads/main' }}
- name: Install shells (zsh, fish) - Ubuntu
if: runner.os == 'Linux'
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 6371e3317..caee92541 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -35,6 +35,11 @@ jobs:
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
+ with:
+ # Own cache (clippy builds check artifacts the shared test cache can't
+ # supply), gated to main so PRs restore but never write.
+ cache-bin: "false"
+ save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install lychee
uses: baptiste0928/cargo-install@v3
@@ -58,6 +63,11 @@ jobs:
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
+ with:
+ # Own cache (its `--no-default-features` builds want a smaller dep set
+ # than the shared test cache), gated to main.
+ cache-bin: "false"
+ save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Library builds without any features
run: cargo check --lib --no-default-features
@@ -168,6 +178,12 @@ jobs:
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
+ with:
+ # Own cache — `cargo msrv verify` builds with older toolchains whose
+ # rustc hash never matches the shared (stable) test cache. Gated to
+ # main; this job only runs when Cargo/toolchain files change.
+ cache-bin: "false"
+ save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: baptiste0928/cargo-install@v3
with:
@@ -272,6 +288,11 @@ jobs:
fetch-depth: 0
- uses: ./.github/actions/test-setup
+ with:
+ # Restore-only: collect builds coverage-instrumented artifacts (it adds
+ # llvm-tools below), which must not overwrite the shared cache that
+ # `test` saves for everyone else.
+ save-cache: "false"
- name: "Use fast D: drive for temp files (Windows)"
if: runner.os == 'Windows'
@@ -362,6 +383,11 @@ jobs:
echo "merge-base with origin/main: $sha"
- uses: ./.github/actions/test-setup
+ with:
+ # PR-only job: restore `test`'s shared main cache, never save. This is
+ # the job that most needs the shared key — a per-job cache would have
+ # no main baseline (it never runs on main) and cold-build every PR.
+ save-cache: "false"
- name: "Use fast D: drive for temp files (Windows)"
if: runner.os == 'Windows'
@@ -437,6 +463,9 @@ jobs:
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
with:
+ # Own cache — coverage-instrumented builds differ from the shared test
+ # cache. Already main-gated; cache-bin:false matches everywhere else.
+ cache-bin: "false"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install shells (zsh, fish)
diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml
index d157e62b6..2268a99c3 100644
--- a/.github/workflows/nightly.yaml
+++ b/.github/workflows/nightly.yaml
@@ -110,6 +110,14 @@ jobs:
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
+ with:
+ # Restore the shared `test` cache (registry + deps), never save.
+ # Nightly-only jobs riding main's cache aren't worth their own entry
+ # against the 10 GB repo cap.
+ prefix-key: v1-rust
+ shared-key: shared
+ cache-bin: "false"
+ save-if: false
- name: Install cargo-hack
uses: taiki-e/[email protected]
@@ -173,6 +181,11 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y musl-tools
- uses: ./.github/actions/test-setup
+ with:
+ # Cross-compiles musl/Intel targets the shared cache never builds, so
+ # it restore-misses anyway — and we don't want these one-off release
+ # triples writing their own caches against the 10 GB cap.
+ save-cache: "false"
- name: Add target
run: rustup target add ${{ matrix.target }}
@@ -196,6 +209,14 @@ jobs:
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
+ with:
+ # Restore the shared `test` cache (registry + deps), never save —
+ # `cargo bench` is release-profile so it rebuilds its own artifacts,
+ # but the dependency download/extract is still worth restoring.
+ prefix-key: v1-rust
+ shared-key: shared
+ cache-bin: "false"
+ save-if: false
- name: Install shells (zsh, fish)
uses: awalsh128/[email protected]
@@ -260,6 +281,13 @@ jobs:
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
+ with:
+ # Never save. Runs on the nightly toolchain, whose rustc hash can't
+ # match the shared (stable) cache, so a per-job cache would only ever
+ # serve the next nightly — near-zero hit under the 10 GB cap. Cold
+ # builds here are absorbed by the nightly cadence.
+ cache-bin: "false"
+ save-if: false
- uses: baptiste0928/cargo-install@v3
with:
@@ -289,7 +317,11 @@ jobs:
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
with:
- key: minimal-versions
+ # Never save — nightly toolchain (can't match the shared stable cache)
+ # plus a minimized lockfile that's unique to this run, so a saved cache
+ # would never be reused.
+ cache-bin: "false"
+ save-if: false
- name: Resolve to minimum versions
# `direct`, not full `-Z minimal-versions`: minimize only worktrunk's own
@@ -324,6 +356,12 @@ jobs:
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
+ with:
+ # Restore the shared `test` cache (registry + deps), never save.
+ prefix-key: v1-rust
+ shared-key: shared
+ cache-bin: "false"
+ save-if: false
- name: 🧪 Build crates.io archive without .git
run: cargo test --test integration crate_io_archive_builds_and_versions_without_git -- --ignored