3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-06-07 09:03:26 +00:00
This commit is contained in:
Jonathan Kelley 2025-01-28 21:27:46 -08:00
parent 70758ffdc7
commit 8c8c35255e
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
2 changed files with 47 additions and 20 deletions

35
dist/restore/index.js vendored
View file

@ -86765,8 +86765,12 @@ class CacheConfig {
constructor() { constructor() {
/** All the paths we want to cache */ /** All the paths we want to cache */
this.cachePaths = []; this.cachePaths = [];
/** All the paths we want to cache for incremental builds */
this.incrementalPaths = [];
/** The primary cache key */ /** The primary cache key */
this.cacheKey = ""; this.cacheKey = "";
/** The primary cache key for incremental builds */
this.incrementalKey = "";
/** /**
* The secondary (restore) key that only contains the prefix and environment * The secondary (restore) key that only contains the prefix and environment
* This should be used if the primary cacheKey is not available - IE pulling from main on a branch * This should be used if the primary cacheKey is not available - IE pulling from main on a branch
@ -86950,13 +86954,14 @@ class CacheConfig {
let lockHash = digest(hasher); let lockHash = digest(hasher);
keyFiles.push(...parsedKeyFiles); keyFiles.push(...parsedKeyFiles);
self.keyFiles = sort_and_uniq(keyFiles); self.keyFiles = sort_and_uniq(keyFiles);
// todo(jon): make sure we differentiate incrementals on different branches
// we can use just a single cache per incremental branch
if (self.incremental) {
key += `-incremental`;
}
key += `-${lockHash}`; key += `-${lockHash}`;
self.cacheKey = key; self.cacheKey = key;
if (self.incremental) {
// wire the incremental key to be just for this branch
const branchName = lib_core.getInput("incremental-key") || "-shared";
const incrementalKey = key + `-incremental` + branchName;
self.incrementalKey = incrementalKey;
}
self.cachePaths = [external_path_default().join(config_CARGO_HOME, "registry"), external_path_default().join(config_CARGO_HOME, "git")]; self.cachePaths = [external_path_default().join(config_CARGO_HOME, "registry"), external_path_default().join(config_CARGO_HOME, "git")];
if (self.cacheBin) { if (self.cacheBin) {
self.cachePaths = [ self.cachePaths = [
@ -86977,7 +86982,7 @@ class CacheConfig {
if (self.incremental) { if (self.incremental) {
if (cacheTargets === "true") { if (cacheTargets === "true") {
for (const target of self.workspaces.map((ws) => ws.target)) { for (const target of self.workspaces.map((ws) => ws.target)) {
self.cachePaths.push(external_path_default().join(target, "incremental")); self.incrementalPaths.push(external_path_default().join(target, "incremental"));
} }
} }
} }
@ -87176,7 +87181,10 @@ async function cleanProfileTarget(profileDir, packages, checkTimestamp, incremen
}; };
await fillModifiedTimes(incrementalDir); await fillModifiedTimes(incrementalDir);
// Write the modified times to the incremental folder // Write the modified times to the incremental folder
lib_core.debug(`writing incremental-restore.json for ${incrementalDir} with ${modifiedTimes} files`); lib_core.debug(`writing incremental-restore.json for ${incrementalDir} files`);
for (const file of modifiedTimes.keys()) {
lib_core.debug(` ${file} -> ${modifiedTimes.get(file)}`);
}
const contents = JSON.stringify({ modifiedTimes }); const contents = JSON.stringify({ modifiedTimes });
await external_fs_default().promises.writeFile(external_path_default().join(incrementalDir, "incremental-restore.json"), contents); await external_fs_default().promises.writeFile(external_path_default().join(incrementalDir, "incremental-restore.json"), contents);
} }
@ -87452,16 +87460,17 @@ async function run() {
// Pass a copy of cachePaths to avoid mutating the original array as reported by: // Pass a copy of cachePaths to avoid mutating the original array as reported by:
// https://github.com/actions/toolkit/pull/1378 // https://github.com/actions/toolkit/pull/1378
// TODO: remove this once the underlying bug is fixed. // TODO: remove this once the underlying bug is fixed.
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], { const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], { lookupOnly });
lookupOnly,
});
if (restoreKey) { if (restoreKey) {
const match = restoreKey === key; const match = restoreKey === key;
lib_core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`); lib_core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
if (config.incremental) { if (config.incremental) {
lib_core.debug("restoring incremental builds"); const incrementalKey = await cacheProvider.cache.restoreCache(config.incrementalPaths.slice(), config.incrementalKey, [config.restoreKey], { lookupOnly });
for (const workspace of config.workspaces) { lib_core.debug(`restoring incremental builds from ${incrementalKey}`);
await restoreIncremental(workspace.target); if (incrementalKey) {
for (const workspace of config.workspaces) {
await restoreIncremental(workspace.target);
}
} }
} }
if (!match || config.isIncrementalMissing()) { if (!match || config.isIncrementalMissing()) {

32
dist/save/index.js vendored
View file

@ -86765,8 +86765,12 @@ class CacheConfig {
constructor() { constructor() {
/** All the paths we want to cache */ /** All the paths we want to cache */
this.cachePaths = []; this.cachePaths = [];
/** All the paths we want to cache for incremental builds */
this.incrementalPaths = [];
/** The primary cache key */ /** The primary cache key */
this.cacheKey = ""; this.cacheKey = "";
/** The primary cache key for incremental builds */
this.incrementalKey = "";
/** /**
* The secondary (restore) key that only contains the prefix and environment * The secondary (restore) key that only contains the prefix and environment
* This should be used if the primary cacheKey is not available - IE pulling from main on a branch * This should be used if the primary cacheKey is not available - IE pulling from main on a branch
@ -86950,13 +86954,14 @@ class CacheConfig {
let lockHash = digest(hasher); let lockHash = digest(hasher);
keyFiles.push(...parsedKeyFiles); keyFiles.push(...parsedKeyFiles);
self.keyFiles = sort_and_uniq(keyFiles); self.keyFiles = sort_and_uniq(keyFiles);
// todo(jon): make sure we differentiate incrementals on different branches
// we can use just a single cache per incremental branch
if (self.incremental) {
key += `-incremental`;
}
key += `-${lockHash}`; key += `-${lockHash}`;
self.cacheKey = key; self.cacheKey = key;
if (self.incremental) {
// wire the incremental key to be just for this branch
const branchName = lib_core.getInput("incremental-key") || "-shared";
const incrementalKey = key + `-incremental` + branchName;
self.incrementalKey = incrementalKey;
}
self.cachePaths = [external_path_default().join(CARGO_HOME, "registry"), external_path_default().join(CARGO_HOME, "git")]; self.cachePaths = [external_path_default().join(CARGO_HOME, "registry"), external_path_default().join(CARGO_HOME, "git")];
if (self.cacheBin) { if (self.cacheBin) {
self.cachePaths = [ self.cachePaths = [
@ -86977,7 +86982,7 @@ class CacheConfig {
if (self.incremental) { if (self.incremental) {
if (cacheTargets === "true") { if (cacheTargets === "true") {
for (const target of self.workspaces.map((ws) => ws.target)) { for (const target of self.workspaces.map((ws) => ws.target)) {
self.cachePaths.push(external_path_default().join(target, "incremental")); self.incrementalPaths.push(external_path_default().join(target, "incremental"));
} }
} }
} }
@ -87176,7 +87181,10 @@ async function cleanProfileTarget(profileDir, packages, checkTimestamp, incremen
}; };
await fillModifiedTimes(incrementalDir); await fillModifiedTimes(incrementalDir);
// Write the modified times to the incremental folder // Write the modified times to the incremental folder
lib_core.debug(`writing incremental-restore.json for ${incrementalDir} with ${modifiedTimes} files`); lib_core.debug(`writing incremental-restore.json for ${incrementalDir} files`);
for (const file of modifiedTimes.keys()) {
lib_core.debug(` ${file} -> ${modifiedTimes.get(file)}`);
}
const contents = JSON.stringify({ modifiedTimes }); const contents = JSON.stringify({ modifiedTimes });
await external_fs_default().promises.writeFile(external_path_default().join(incrementalDir, "incremental-restore.json"), contents); await external_fs_default().promises.writeFile(external_path_default().join(incrementalDir, "incremental-restore.json"), contents);
} }
@ -87422,6 +87430,7 @@ async function rmRF(dirName) {
process.on("uncaughtException", (e) => { process.on("uncaughtException", (e) => {
lib_core.error(e.message); lib_core.error(e.message);
if (e.stack) { if (e.stack) {
@ -87482,6 +87491,15 @@ async function run() {
catch (e) { catch (e) {
lib_core.debug(`${e.stack}`); lib_core.debug(`${e.stack}`);
} }
// Save the incremental cache before we delete it
if (config.incremental) {
lib_core.info(`... Saving incremental cache ...`);
await cacheProvider.cache.saveCache(config.incrementalPaths.slice(), config.incrementalKey);
for (const path of config.incrementalPaths) {
lib_core.debug(` deleting ${path}`);
await (0,promises_.rm)(path);
}
}
lib_core.info(`... Saving cache ...`); lib_core.info(`... Saving cache ...`);
// Pass a copy of cachePaths to avoid mutating the original array as reported by: // Pass a copy of cachePaths to avoid mutating the original array as reported by:
// https://github.com/actions/toolkit/pull/1378 // https://github.com/actions/toolkit/pull/1378