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:/); +});