mirror of
https://code.forgejo.org/actions/cache.git
synced 2026-08-05 02:53:33 +00:00
gcsCache: return matched cache key, not gcs path
@actions/cache restoreCache contract returns the matched key (primary or
restore) so callers can compare to primaryKey for cache-hit. Our wrapper
was returning the full gcs object path, so restoreImpl.ts always set
cache-hit=false → every job ran pnpm install --frozen-lockfile on top of
a restored node_modules, burning ~34s per job for nothing.
findFileOnGCS now returns { key, path }; outer wrapper returns the key.
This commit is contained in:
parent
01f9143258
commit
be02de94c3
5 changed files with 62 additions and 31 deletions
18
dist/restore-only/index.js
vendored
18
dist/restore-only/index.js
vendored
|
|
@ -92559,15 +92559,21 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
|
|||
const archiveFolder = yield utils.createTempDirectory();
|
||||
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
|
||||
const keys = [primaryKey, ...restoreKeys];
|
||||
const gcsPath = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
|
||||
if (!gcsPath) {
|
||||
const match = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
|
||||
if (!match) {
|
||||
core.info(`No matching cache found`);
|
||||
return undefined;
|
||||
}
|
||||
// Preserve the @actions/cache contract: return the matched cache KEY
|
||||
// (primaryKey or a restoreKey), not the GCS object path. The caller
|
||||
// (restoreImpl) compares the return value against primaryKey to set the
|
||||
// `cache-hit` output — returning the gcs path makes `cache-hit` always
|
||||
// false, re-triggering downstream install/build steps that gate on it.
|
||||
const { key: matchedKey, path: gcsPath } = match;
|
||||
// If lookup only, just return the key
|
||||
if (options === null || options === void 0 ? void 0 : options.lookupOnly) {
|
||||
core.info(`Cache found in GCS with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
core.info(`Cache found in GCS with key: ${matchedKey}`);
|
||||
return matchedKey;
|
||||
}
|
||||
try {
|
||||
core.info(`Downloading from GCS: ${bucket}/${gcsPath}`);
|
||||
|
|
@ -92580,7 +92586,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
|
|||
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
|
||||
yield (0, tar_1.extractTar)(archivePath, compressionMethod);
|
||||
core.info("Cache restored successfully");
|
||||
return gcsPath;
|
||||
return matchedKey;
|
||||
}
|
||||
catch (error) {
|
||||
core.warning(`Failed to restore: ${error.message}`);
|
||||
|
|
@ -92649,7 +92655,7 @@ function findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
|
|||
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
|
||||
if (yield checkFileExists(storage, bucket, gcsPath)) {
|
||||
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
return { key, path: gcsPath };
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
|
|
|||
18
dist/restore/index.js
vendored
18
dist/restore/index.js
vendored
|
|
@ -92559,15 +92559,21 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
|
|||
const archiveFolder = yield utils.createTempDirectory();
|
||||
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
|
||||
const keys = [primaryKey, ...restoreKeys];
|
||||
const gcsPath = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
|
||||
if (!gcsPath) {
|
||||
const match = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
|
||||
if (!match) {
|
||||
core.info(`No matching cache found`);
|
||||
return undefined;
|
||||
}
|
||||
// Preserve the @actions/cache contract: return the matched cache KEY
|
||||
// (primaryKey or a restoreKey), not the GCS object path. The caller
|
||||
// (restoreImpl) compares the return value against primaryKey to set the
|
||||
// `cache-hit` output — returning the gcs path makes `cache-hit` always
|
||||
// false, re-triggering downstream install/build steps that gate on it.
|
||||
const { key: matchedKey, path: gcsPath } = match;
|
||||
// If lookup only, just return the key
|
||||
if (options === null || options === void 0 ? void 0 : options.lookupOnly) {
|
||||
core.info(`Cache found in GCS with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
core.info(`Cache found in GCS with key: ${matchedKey}`);
|
||||
return matchedKey;
|
||||
}
|
||||
try {
|
||||
core.info(`Downloading from GCS: ${bucket}/${gcsPath}`);
|
||||
|
|
@ -92580,7 +92586,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
|
|||
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
|
||||
yield (0, tar_1.extractTar)(archivePath, compressionMethod);
|
||||
core.info("Cache restored successfully");
|
||||
return gcsPath;
|
||||
return matchedKey;
|
||||
}
|
||||
catch (error) {
|
||||
core.warning(`Failed to restore: ${error.message}`);
|
||||
|
|
@ -92649,7 +92655,7 @@ function findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
|
|||
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
|
||||
if (yield checkFileExists(storage, bucket, gcsPath)) {
|
||||
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
return { key, path: gcsPath };
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
|
|
|||
18
dist/save-only/index.js
vendored
18
dist/save-only/index.js
vendored
|
|
@ -92572,15 +92572,21 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
|
|||
const archiveFolder = yield utils.createTempDirectory();
|
||||
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
|
||||
const keys = [primaryKey, ...restoreKeys];
|
||||
const gcsPath = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
|
||||
if (!gcsPath) {
|
||||
const match = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
|
||||
if (!match) {
|
||||
core.info(`No matching cache found`);
|
||||
return undefined;
|
||||
}
|
||||
// Preserve the @actions/cache contract: return the matched cache KEY
|
||||
// (primaryKey or a restoreKey), not the GCS object path. The caller
|
||||
// (restoreImpl) compares the return value against primaryKey to set the
|
||||
// `cache-hit` output — returning the gcs path makes `cache-hit` always
|
||||
// false, re-triggering downstream install/build steps that gate on it.
|
||||
const { key: matchedKey, path: gcsPath } = match;
|
||||
// If lookup only, just return the key
|
||||
if (options === null || options === void 0 ? void 0 : options.lookupOnly) {
|
||||
core.info(`Cache found in GCS with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
core.info(`Cache found in GCS with key: ${matchedKey}`);
|
||||
return matchedKey;
|
||||
}
|
||||
try {
|
||||
core.info(`Downloading from GCS: ${bucket}/${gcsPath}`);
|
||||
|
|
@ -92593,7 +92599,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
|
|||
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
|
||||
yield (0, tar_1.extractTar)(archivePath, compressionMethod);
|
||||
core.info("Cache restored successfully");
|
||||
return gcsPath;
|
||||
return matchedKey;
|
||||
}
|
||||
catch (error) {
|
||||
core.warning(`Failed to restore: ${error.message}`);
|
||||
|
|
@ -92662,7 +92668,7 @@ function findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
|
|||
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
|
||||
if (yield checkFileExists(storage, bucket, gcsPath)) {
|
||||
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
return { key, path: gcsPath };
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
|
|
|||
18
dist/save/index.js
vendored
18
dist/save/index.js
vendored
|
|
@ -92572,15 +92572,21 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
|
|||
const archiveFolder = yield utils.createTempDirectory();
|
||||
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
|
||||
const keys = [primaryKey, ...restoreKeys];
|
||||
const gcsPath = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
|
||||
if (!gcsPath) {
|
||||
const match = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
|
||||
if (!match) {
|
||||
core.info(`No matching cache found`);
|
||||
return undefined;
|
||||
}
|
||||
// Preserve the @actions/cache contract: return the matched cache KEY
|
||||
// (primaryKey or a restoreKey), not the GCS object path. The caller
|
||||
// (restoreImpl) compares the return value against primaryKey to set the
|
||||
// `cache-hit` output — returning the gcs path makes `cache-hit` always
|
||||
// false, re-triggering downstream install/build steps that gate on it.
|
||||
const { key: matchedKey, path: gcsPath } = match;
|
||||
// If lookup only, just return the key
|
||||
if (options === null || options === void 0 ? void 0 : options.lookupOnly) {
|
||||
core.info(`Cache found in GCS with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
core.info(`Cache found in GCS with key: ${matchedKey}`);
|
||||
return matchedKey;
|
||||
}
|
||||
try {
|
||||
core.info(`Downloading from GCS: ${bucket}/${gcsPath}`);
|
||||
|
|
@ -92593,7 +92599,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
|
|||
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
|
||||
yield (0, tar_1.extractTar)(archivePath, compressionMethod);
|
||||
core.info("Cache restored successfully");
|
||||
return gcsPath;
|
||||
return matchedKey;
|
||||
}
|
||||
catch (error) {
|
||||
core.warning(`Failed to restore: ${error.message}`);
|
||||
|
|
@ -92662,7 +92668,7 @@ function findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
|
|||
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
|
||||
if (yield checkFileExists(storage, bucket, gcsPath)) {
|
||||
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
return { key, path: gcsPath };
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ async function restoreFromGCS(
|
|||
);
|
||||
|
||||
const keys = [primaryKey, ...restoreKeys];
|
||||
const gcsPath = await findFileOnGCS(
|
||||
const match = await findFileOnGCS(
|
||||
storage,
|
||||
bucket,
|
||||
pathPrefix,
|
||||
|
|
@ -136,15 +136,22 @@ async function restoreFromGCS(
|
|||
compressionMethod
|
||||
);
|
||||
|
||||
if (!gcsPath) {
|
||||
if (!match) {
|
||||
core.info(`No matching cache found`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Preserve the @actions/cache contract: return the matched cache KEY
|
||||
// (primaryKey or a restoreKey), not the GCS object path. The caller
|
||||
// (restoreImpl) compares the return value against primaryKey to set the
|
||||
// `cache-hit` output — returning the gcs path makes `cache-hit` always
|
||||
// false, re-triggering downstream install/build steps that gate on it.
|
||||
const { key: matchedKey, path: gcsPath } = match;
|
||||
|
||||
// If lookup only, just return the key
|
||||
if (options?.lookupOnly) {
|
||||
core.info(`Cache found in GCS with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
core.info(`Cache found in GCS with key: ${matchedKey}`);
|
||||
return matchedKey;
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -166,7 +173,7 @@ async function restoreFromGCS(
|
|||
await extractTar(archivePath, compressionMethod);
|
||||
core.info("Cache restored successfully");
|
||||
|
||||
return gcsPath;
|
||||
return matchedKey;
|
||||
} catch (error) {
|
||||
core.warning(`Failed to restore: ${(error as Error).message}`);
|
||||
} finally {
|
||||
|
|
@ -254,12 +261,12 @@ async function findFileOnGCS(
|
|||
pathPrefix: string,
|
||||
keys: string[],
|
||||
compressionMethod: CompressionMethod
|
||||
): Promise<string | undefined> {
|
||||
): Promise<{ key: string; path: string } | undefined> {
|
||||
for (const key of keys) {
|
||||
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
|
||||
if (await checkFileExists(storage, bucket, gcsPath)) {
|
||||
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
|
||||
return gcsPath;
|
||||
return { key, path: gcsPath };
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue