Skip to content

Commit d44aeda

Browse files
committed
ci: decide in ci.yaml that only main persists caches
The Nix sticky disks are keyed by job, not by ref, so pull request and merge group runs mount the same disk main commits and release builds read. What keeps their changes out of it is the stickydisk `commit` flag, and setup-nix-cache derived that flag on its own from the ref. A merge_group run checks out the queued commit, so that local action is the queued code's own copy, and nothing in ci.yaml stated the rule. ci.yaml now sets PERSIST_CACHES from `github.ref == 'refs/heads/main'` and passes it to every Nix store and Cargo cache save. Non-main runs still mount main's warm disk, so pull requests keep their cache hits, but they mount it without committing and the clone is discarded. This cannot stop a queued commit that edits ci.yaml itself; review before queuing is that boundary. It stops a change to a local action, or an unreviewed-code path, from writing a store that main reads.
1 parent 311f1ba commit d44aeda

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ on:
1212

1313
permissions: read-all
1414

15+
env:
16+
# Only runs of main may persist the Nix stores and the Cargo cache: the
17+
# sticky disks these jobs mount are the ones main and release builds read.
18+
# Pull requests and merge groups mount them without committing, so their
19+
# changes are discarded. This is decided here rather than only inside the
20+
# local actions, so the gate sits next to the triggers. It cannot stop a
21+
# queued commit that edits this file; review before queuing does that.
22+
PERSIST_CACHES: ${{ github.ref == 'refs/heads/main' }}
23+
1524
jobs:
1625
changes:
1726
name: Detect code changes
@@ -48,6 +57,8 @@ jobs:
4857
ref: ${{ github.event.pull_request.head.sha || github.sha }}
4958
persist-credentials: false
5059
- uses: ./.github/actions/setup-nix-cache
60+
with:
61+
save: ${{ env.PERSIST_CACHES }}
5162
- name: Install tirith
5263
run: nix profile install .#tirith
5364
# One pass produces the SARIF report and sets the gate exit code. tirith's
@@ -156,6 +167,8 @@ jobs:
156167
ref: ${{ github.event.pull_request.head.sha || github.sha }}
157168
persist-credentials: false
158169
- uses: ./.github/actions/setup-nix-cache
170+
with:
171+
save: ${{ env.PERSIST_CACHES }}
159172
- name: Secret scan and workflow lint
160173
run: nix build --print-build-logs .#checks.x86_64-linux.gitleaks .#checks.x86_64-linux.treefmt
161174

@@ -174,6 +187,8 @@ jobs:
174187
ref: ${{ github.event.pull_request.head.sha || github.sha }}
175188
persist-credentials: false
176189
- uses: ./.github/actions/setup-nix-cache
190+
with:
191+
save: ${{ env.PERSIST_CACHES }}
177192
- parallel:
178193
- name: Run nix flake check
179194
run: nix flake check --print-build-logs
@@ -255,17 +270,20 @@ jobs:
255270
# get no token.
256271
nix-github-token: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
257272
cache-scope: ${{ matrix.name }}
273+
save-nix-cache: ${{ env.PERSIST_CACHES }}
258274
- uses: ./.github/actions/build-macos-nix-native-package
259275
if: matrix.platform == 'darwin'
260276
with:
261277
arch: ${{ matrix.arch }}
262278
binary: ${{ matrix.binary }}
263279
cache-scope: ${{ matrix.name }}
280+
save-nix-cache: ${{ env.PERSIST_CACHES }}
264281
- uses: ./.github/actions/build-windows-native-package
265282
if: matrix.platform == 'win32'
266283
with:
267284
arch: ${{ matrix.arch }}
268285
binary: ${{ matrix.binary }}
286+
save-cargo-cache: ${{ env.PERSIST_CACHES }}
269287

270288
npm-publish-dry-run-and-upload-pkg-pr-now:
271289
# preflight gates the publish rather than the builds: a leaked secret must
@@ -288,6 +306,8 @@ jobs:
288306
with:
289307
persist-credentials: false
290308
- uses: ./.github/actions/setup-nix-cache
309+
with:
310+
save: ${{ env.PERSIST_CACHES }}
291311
# Packing only repackages the native binaries restored from the build
292312
# matrix below (no Rust build happens here), so the full `nix develop` dev
293313
# shell is unnecessary. The package checks bring Nu through their Nix
@@ -506,6 +526,7 @@ jobs:
506526
# disk, so both legs read test's instead: it installs `just` and the
507527
# same flake inputs on every push to main.
508528
disk-job: test
529+
save: ${{ env.PERSIST_CACHES }}
509530
# This job only benchmarks the prebuilt ccusage binary bundled in the
510531
# installed pkg.pr.new package (no Rust build happens here), so the full
511532
# `nix develop` dev shell is unnecessary. Install just the tools the perf

0 commit comments

Comments
 (0)