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
54 changes: 52 additions & 2 deletions scripts/cache-save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,34 @@ NODE
node --input-type=module - "$PWD/$arm_dir/package.json" <<'NODE'
import { createRequire } from "node:module";

// `@actions/cache` publishes an `exports` map with no "." entry, so requiring it
// by package name fails outright. Resolving its manifest and requiring the file
// its `main` points at goes around the map, and keeps working whichever version
// a given setup-java ref happens to pin.
function loadCacheClient(require, manifest) {
const { readFileSync } = require("node:fs");
const { dirname, join } = require("node:path");
let manifestPath;
try {
manifestPath = require.resolve("@actions/cache/package.json");
} catch {
// Some versions do not expose "./package.json" through the map either, in
// which case the install layout is the only thing left to go on.
manifestPath = join(
dirname(manifest),
"node_modules",
"@actions",
"cache",
"package.json",
);
}
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
return require(join(dirname(manifestPath), manifest.main ?? "lib/cache.js"));
Comment on lines +239 to +240
}

const [manifest] = process.argv.slice(2);
const require = createRequire(manifest);
require.resolve("@actions/cache");
loadCacheClient(require, manifest);
NODE
;;
save)
Expand All @@ -236,10 +261,35 @@ NODE
import { createRequire } from "node:module";
import { pathToFileURL } from "node:url";

// `@actions/cache` publishes an `exports` map with no "." entry, so requiring it
// by package name fails outright. Resolving its manifest and requiring the file
// its `main` points at goes around the map, and keeps working whichever version
// a given setup-java ref happens to pin.
function loadCacheClient(require, manifest) {
const { readFileSync } = require("node:fs");
const { dirname, join } = require("node:path");
let manifestPath;
try {
manifestPath = require.resolve("@actions/cache/package.json");
} catch {
// Some versions do not expose "./package.json" through the map either, in
// which case the install layout is the only thing left to go on.
manifestPath = join(
dirname(manifest),
"node_modules",
"@actions",
"cache",
"package.json",
);
}
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
return require(join(dirname(manifestPath), manifest.main ?? "lib/cache.js"));
}

const [manifest, fixtureDir, key, resultsFile, sample, arm, slot] =
process.argv.slice(2);
const require = createRequire(manifest);
const cache = require("@actions/cache");
const cache = loadCacheClient(require, manifest);

const started = Date.now();
const cacheId = await cache.saveCache([fixtureDir], key);
Expand Down
8 changes: 4 additions & 4 deletions scripts/check-cache-keys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ export function markdown(metadata, result) {
}

export async function main(env = process.env) {
const runId = requireEnv(env, "GITHUB_RUN_ID");
requireEnv(env, ["GITHUB_RUN_ID", "SETUP_JAVA_REPOSITORY", "SETUP_JAVA_REF"]);
const metadata = {
runId,
setupJavaRepository: requireEnv(env, "SETUP_JAVA_REPOSITORY"),
setupJavaRef: requireEnv(env, "SETUP_JAVA_REF"),
runId: env.GITHUB_RUN_ID,
setupJavaRepository: env.SETUP_JAVA_REPOSITORY,
setupJavaRef: env.SETUP_JAVA_REF,
generatedAt: new Date().toISOString(),
};
const rows = parseKeys(await readKeyFiles());
Expand Down
17 changes: 12 additions & 5 deletions scripts/report-cache-value.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,18 @@ export function markdown(metadata, analysis, caches) {
}

export async function main(env = process.env) {
const token = requireEnv(env, "GH_TOKEN");
const runId = requireEnv(env, "GITHUB_RUN_ID");
const setupJavaRepository = requireEnv(env, "SETUP_JAVA_REPOSITORY");
const setupJavaRef = requireEnv(env, "SETUP_JAVA_REF");
const [owner, repo] = requireEnv(env, "GITHUB_REPOSITORY").split("/");
requireEnv(env, [
"GH_TOKEN",
"GITHUB_RUN_ID",
"SETUP_JAVA_REPOSITORY",
"SETUP_JAVA_REF",
"GITHUB_REPOSITORY",
]);
const token = env.GH_TOKEN;
const runId = env.GITHUB_RUN_ID;
const setupJavaRepository = env.SETUP_JAVA_REPOSITORY;
const setupJavaRef = env.SETUP_JAVA_REF;
const [owner, repo] = env.GITHUB_REPOSITORY.split("/");
if (!owner || !repo) {
throw new Error(
`GITHUB_REPOSITORY must be owner/repo, got "${env.GITHUB_REPOSITORY}"`,
Expand Down