3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-04-05 21:24:07 +00:00
This commit is contained in:
Arpad Borsos 2021-01-28 18:42:00 +01:00
parent 958028d559
commit 83aad8d470
2 changed files with 41 additions and 19 deletions

32
dist/restore/index.js vendored
View file

@ -55713,10 +55713,11 @@ if (cwd) {
const stateKey = "RUST_CACHE_KEY"; const stateKey = "RUST_CACHE_KEY";
const stateHash = "RUST_CACHE_HASH"; const stateHash = "RUST_CACHE_HASH";
const home = external_os_default().homedir(); const home = external_os_default().homedir();
const cargoHome = process.env.CARGO_HOME || external_path_default().join(home, ".cargo");
const paths = { const paths = {
index: external_path_default().join(home, ".cargo/registry/index"), index: external_path_default().join(cargoHome, "registry/index"),
cache: external_path_default().join(home, ".cargo/registry/cache"), cache: external_path_default().join(cargoHome, "registry/cache"),
git: external_path_default().join(home, ".cargo/git"), git: external_path_default().join(cargoHome, "git"),
target: "target", target: "target",
}; };
const RefKey = "GITHUB_REF"; const RefKey = "GITHUB_REF";
@ -55730,13 +55731,19 @@ async function getCacheConfig() {
core.saveState(stateHash, lockHash); core.saveState(stateHash, lockHash);
} }
let key = `v0-rust-`; let key = `v0-rust-`;
let inputKey = core.getInput("key"); const sharedKey = core.getInput("sharedKey");
if (inputKey) { if (sharedKey) {
key += `${inputKey}-`; key += `${sharedKey}-`;
} }
const job = process.env.GITHUB_JOB; else {
if (job) { const inputKey = core.getInput("key");
key += `${job}-`; if (inputKey) {
key += `${inputKey}-`;
}
const job = process.env.GITHUB_JOB;
if (job) {
key += `${job}-`;
}
} }
key += await getRustKey(); key += await getRustKey();
return { return {
@ -55858,6 +55865,7 @@ async function run() {
core.exportVariable("CARGO_INCREMENTAL", 0); core.exportVariable("CARGO_INCREMENTAL", 0);
const { paths, key, restoreKeys } = await getCacheConfig(); const { paths, key, restoreKeys } = await getCacheConfig();
core.info(`Restoring paths:\n ${paths.join("\n ")}`); core.info(`Restoring paths:\n ${paths.join("\n ")}`);
core.info(`In directory:\n ${process.cwd()}`);
core.info(`Using keys:\n ${[key, ...restoreKeys].join("\n ")}`); core.info(`Using keys:\n ${[key, ...restoreKeys].join("\n ")}`);
const restoreKey = await cache.restoreCache(paths, key, restoreKeys); const restoreKey = await cache.restoreCache(paths, key, restoreKeys);
if (restoreKey) { if (restoreKey) {
@ -55868,15 +55876,21 @@ async function run() {
const packages = await getPackages(); const packages = await getPackages();
await cleanTarget(packages); await cleanTarget(packages);
} }
setCacheHitOutput(restoreKey === key);
} }
else { else {
core.info("No cache found."); core.info("No cache found.");
setCacheHitOutput(false);
} }
} }
catch (e) { catch (e) {
setCacheHitOutput(false);
core.info(`[warning] ${e.message}`); core.info(`[warning] ${e.message}`);
} }
} }
function setCacheHitOutput(cacheHit) {
core.setOutput("cache-hit", cacheHit.toString());
}
run(); run();

28
dist/save/index.js vendored
View file

@ -55713,10 +55713,11 @@ if (cwd) {
const stateKey = "RUST_CACHE_KEY"; const stateKey = "RUST_CACHE_KEY";
const stateHash = "RUST_CACHE_HASH"; const stateHash = "RUST_CACHE_HASH";
const home = external_os_default().homedir(); const home = external_os_default().homedir();
const cargoHome = process.env.CARGO_HOME || external_path_default().join(home, ".cargo");
const paths = { const paths = {
index: external_path_default().join(home, ".cargo/registry/index"), index: external_path_default().join(cargoHome, "registry/index"),
cache: external_path_default().join(home, ".cargo/registry/cache"), cache: external_path_default().join(cargoHome, "registry/cache"),
git: external_path_default().join(home, ".cargo/git"), git: external_path_default().join(cargoHome, "git"),
target: "target", target: "target",
}; };
const RefKey = "GITHUB_REF"; const RefKey = "GITHUB_REF";
@ -55730,13 +55731,19 @@ async function getCacheConfig() {
core.saveState(stateHash, lockHash); core.saveState(stateHash, lockHash);
} }
let key = `v0-rust-`; let key = `v0-rust-`;
let inputKey = core.getInput("key"); const sharedKey = core.getInput("sharedKey");
if (inputKey) { if (sharedKey) {
key += `${inputKey}-`; key += `${sharedKey}-`;
} }
const job = process.env.GITHUB_JOB; else {
if (job) { const inputKey = core.getInput("key");
key += `${job}-`; if (inputKey) {
key += `${inputKey}-`;
}
const job = process.env.GITHUB_JOB;
if (job) {
key += `${job}-`;
}
} }
key += await getRustKey(); key += await getRustKey();
return { return {
@ -55882,7 +55889,8 @@ async function run() {
} }
catch { } catch { }
core.info(`Saving paths:\n ${savePaths.join("\n ")}`); core.info(`Saving paths:\n ${savePaths.join("\n ")}`);
core.info(`Using key "${key}".`); core.info(`In directory:\n ${process.cwd()}`);
core.info(`Using key:\n ${key}`);
await cache.saveCache(savePaths, key); await cache.saveCache(savePaths, key);
} }
catch (e) { catch (e) {