Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/ci-napi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ jobs:

- uses: Swatinem/rust-cache@v2
with:
# Keep compiled dependencies, but start a separate publication cache.
prefix-key: celox-napi-release-v1
shared-key: napi-${{ matrix.target }}
# Reinstall Cargo tools instead of restoring executable binaries.
# Release target matrices previously consumed most of the repository
# quota and evicted the shared Rust Tests cache. Share downloads only;
# never retain target/ artifacts for each release target and lane.
prefix-key: celox-napi-downloads-v1
shared-key: napi-downloads
cache-targets: false
cache-bin: false
# Tag/ad-hoc branch runs may restore, but only release lanes populate it.
save-if: ${{ (github.event_name == 'repository_dispatch' && github.ref == 'refs/heads/master') || (github.event_name == 'workflow_dispatch' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop')) }}
# All lanes can restore the default-branch cache. Avoid develop copies.
save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}

- name: Install ziglang (musl targets)
if: matrix.zigbuild
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/rust-cache.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Warm Rust dependency cache

# PR merge-ref caches cannot be reused by other PRs. Populate the default
# branch cache once per toolchain/dependency key, without running tests twice.
# branch cache on dependency changes and periodically repair eviction. Cache hits
# skip compilation, and warming never executes the test suite.
on:
push:
branches: [master]
Expand All @@ -14,6 +15,9 @@ on:
- ".github/workflows/rust-cache.yml"
- ".github/workflows/ci.yml"
- "scripts/run-vtest.mjs"
# Eviction does not change Cargo files, so push path filters cannot repair it.
schedule:
- cron: "17 * * * *"
workflow_dispatch:

permissions:
Expand Down
26 changes: 26 additions & 0 deletions scripts/ci-workflow.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,29 @@ test("sv-tests generates the pinned main corpus before running and retains its s
assert.ok(sv.indexOf("conformance/sv-tests/prepare.py") < sv.indexOf("conformance/sv-tests/run.py"));
assert.match(sv, /sv-tests-report\.summary\.json/);
});


test("release builds share download-only caches and cannot retain target matrices", () => {
const release = readFileSync(new URL("../.github/workflows/ci-napi.yml", import.meta.url), "utf8");
const caches = [...release.matchAll(/ - uses: Swatinem\/rust-cache@v2\n([\s\S]*?)(?=\n -|$)/g)];
assert.equal(caches.length, 1);
const cache = caches[0][1];
assert.match(cache, /prefix-key: celox-napi-downloads-v1/);
assert.match(cache, /shared-key: napi-downloads/);
assert.match(cache, /cache-targets: false/);
assert.match(cache, /cache-bin: false/);
assert.match(cache, /save-if: \$\{\{ github.ref == format\('refs\/heads\/\{0\}', github.event.repository.default_branch\) \}\}/);
assert.doesNotMatch(cache, /matrix.target|refs\/heads\/develop/);
});

test("evicted default-branch dependency caches recover without dependency changes", () => {
const warm = readFileSync(new URL("../.github/workflows/rust-cache.yml", import.meta.url), "utf8");
assert.match(warm, /schedule:\n - cron: "17 \* \* \* \*"/);
assert.match(warm, /workflow_dispatch:/);
for (const id of ["rust-tests", "rust-default-tests", "napi-windows"]) {
const block = warm.split(` ${id}:\n`)[1].split(/\n [a-z][a-z-]*:/)[0];
assert.match(block, /if: github.ref == format\('refs\/heads\/\{0\}', github.event.repository.default_branch\)/);
assert.match(block, /if: steps.cache.outputs.cache-hit != 'true'/);
}
assert.doesNotMatch(warm, /pull_request_target:|workflow_run:/);
});
Loading