From 37e28d66ef095bedb0560fb1358828e2f54b028c Mon Sep 17 00:00:00 2001 From: tignear Date: Tue, 27 Oct 2026 18:55:06 +0900 Subject: [PATCH] ci: protect Rust test caches from release target churn Rust Tests lost its 2 GB cache while multi-target NAPI release caches occupied about 6.2 GiB of repository cache storage. The same restore key hit at 07:47 UTC and missed at 08:46 UTC; compilation grew from 12m35s to 31m20s while test execution remained roughly 14 minutes. Keep only downloaded Cargo dependencies for NAPI publication, share the cache across targets, and save only on the default branch to avoid develop duplicates. Use a new prefix so old compiled-target caches cannot be restored under the download-only policy. Release builds trade compiled-dependency reuse for preserving pull-request CI capacity. Run the existing dependency warmer hourly as well as on dependency changes and manual dispatch. Eviction alone changes no Cargo files, so the previous path-filtered trigger could not recover the missing cache. Exact hits still skip all compilation; warming never executes the test suite. Preserve trusted default-branch checks and existing Rust Tests cache keys. Validation: 38 CI workflow/classifier tests pass, both workflow YAML files parse successfully, and diff checks pass. Regression coverage enforces download-only release caching, default-branch-only writes, scheduled recovery and hit-gated builds. Change-Id: I39b2469c2fece08abdd5cfc4d2738411605b98f7 --- .github/workflows/ci-napi.yml | 14 ++++++++------ .github/workflows/rust-cache.yml | 6 +++++- scripts/ci-workflow.test.mjs | 26 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-napi.yml b/.github/workflows/ci-napi.yml index 76645afad97..947190c258c 100644 --- a/.github/workflows/ci-napi.yml +++ b/.github/workflows/ci-napi.yml @@ -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 diff --git a/.github/workflows/rust-cache.yml b/.github/workflows/rust-cache.yml index b60213d58e9..43539a20be3 100644 --- a/.github/workflows/rust-cache.yml +++ b/.github/workflows/rust-cache.yml @@ -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] @@ -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: diff --git a/scripts/ci-workflow.test.mjs b/scripts/ci-workflow.test.mjs index ce4381e8131..e18b2ef2713 100644 --- a/scripts/ci-workflow.test.mjs +++ b/scripts/ci-workflow.test.mjs @@ -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:/); +});