fix(ci): include the cache retention helper dependency (#14689)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-11-26 09:07:14 +00:00
1 parent 673e85ffdb
commit 8d302d2dad
2 files changed
+18 -9

No files matched your search

+1
View File
@@ -46,6 +46,7 @@ jobs:
sparse-checkout: |
/.nvmrc
/scripts/ci/cache-retention.mjs
/scripts/ci/github-api.mjs
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
ref: ${{ github.event.workflow_run.head_sha }}
@@ -9,7 +9,7 @@ import {
readdir,
writeFile,
} from "node:fs/promises";
import { delimiter, join } from "node:path";
import { delimiter, dirname, join } from "node:path";
import { runInNewContext } from "node:vm";
import { beforeAll, describe, expect, it } from "vitest";
@@ -224,6 +224,7 @@ const retentionKeyFiles = [
async function exerciseTrustedRetentionWithLegacyTarget(
retentionRun: unknown,
retentionEnv: Record<string, string>,
trustedSparseCheckout: string,
) {
const runnerWorkspace = await createTestTempDirectory(
"rea-ci-retention-trusted-checkout-",
@@ -243,13 +244,14 @@ async function exerciseTrustedRetentionWithLegacyTarget(
trustedSource,
"scripts/ci/cache-retention.mjs",
);
await mkdir(join(trustedSource, "scripts/ci"), { recursive: true });
for (const filename of ["cache-retention.mjs", "github-api.mjs"]) {
await copyFile(
join(repository, "scripts/ci", filename),
join(trustedSource, "scripts/ci", filename),
);
for (const pattern of trustedSparseCheckout.trim().split("\n")) {
expect(pattern).toMatch(/^\/(?:\.nvmrc|scripts\/ci\/[\w-]+\.mjs)$/u);
const filename = pattern.slice(1);
const destination = join(trustedSource, filename);
await mkdir(dirname(destination), { recursive: true });
await copyFile(join(repository, filename), destination);
}
await expect(access(join(trustedSource, ".nvmrc"))).resolves.toBeUndefined();
await expect(
access(join(legacyTarget, "scripts/ci/cache-retention.mjs")),
).rejects.toMatchObject({ code: "ENOENT" });
@@ -649,7 +651,6 @@ it("deletes superseded caches only from the trusted follow-up workflow", async (
path: "trusted-retention",
"persist-credentials": false,
"sparse-checkout-cone-mode": false,
"sparse-checkout": "/.nvmrc\n/scripts/ci/cache-retention.mjs\n",
});
const targetCheckout = checkouts[1];
expect(targetCheckout?.with).toMatchObject({
@@ -687,7 +688,14 @@ it("deletes superseded caches only from the trusted follow-up workflow", async (
expect(retentionEnv.GH_TOKEN).toBe("${{ github.token }}");
// Exercise the selected trusted helper against a legacy target tree.
await exerciseTrustedRetentionWithLegacyTarget(retention?.run, retentionEnv);
const trustedInputs = z
.object({ "sparse-checkout": z.string() })
.parse(trustedCheckout?.with);
await exerciseTrustedRetentionWithLegacyTarget(
retention?.run,
retentionEnv,
trustedInputs["sparse-checkout"],
);
const ci = workflows.find(({ file }) => file === "ci.yml")?.workflow;
if (ci === undefined) throw new Error("Missing CI workflow");
expect(ci.permissions).toMatchObject({ contents: "read" });