MCPcopy Create free account
hub / github.com/delinoio/oss / toolCacheContexts

Function toolCacheContexts

scripts/ci/cache-context.mjs:28–53  ·  view source on GitHub ↗
(cwd = process.cwd(), run = spawnSync)

Source from the content-addressed store, hash-verified

26}
27
28export function toolCacheContexts(cwd = process.cwd(), run = spawnSync) {
29 const version = (command, args, env = process.env) => {
30 const result = run(command, args, { encoding: "utf8", shell: false, env });
31 return result.status === 0 ? result.stdout.trim() : "unavailable";
32 };
33 let rustPin;
34 try {
35 rustPin = readFileSync(resolve(cwd, "rust-toolchain"), "utf8").trim();
36 } catch {
37 rustPin = "unavailable";
38 }
39 // Metadata queries must never download compilers in JS-only jobs. rustup run
40 // requires an installed toolchain unless --install is explicitly supplied.
41 const rust =
42 rustPin === "unavailable"
43 ? "unavailable"
44 : version("rustup", ["run", rustPin, "rustc", "--version"]);
45 return {
46 CI_GO_CACHE_CONTEXT: version("go", ["version"], {
47 ...process.env,
48 GOTOOLCHAIN: "local",
49 }),
50 CI_RUST_CACHE_CONTEXT: rust,
51 CI_PROTO_CACHE_CONTEXT: version("buf", ["--version"]),
52 };
53}
54
55export function cachePolicy(env = process.env) {
56 if (!env.CI) return undefined;

Callers 2

run-affected.mjsFile · 0.90
cache.test.mjsFile · 0.90

Calls 3

versionFunction · 0.85
cwdMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected