diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 37c95cb..c2e6021 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -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; diff --git a/dist/restore/index.js b/dist/restore/index.js index ed3cf87..0d6b9f5 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -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; diff --git a/dist/save-only/index.js b/dist/save-only/index.js index 4af28e4..df35931 100644 --- a/dist/save-only/index.js +++ b/dist/save-only/index.js @@ -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; diff --git a/dist/save/index.js b/dist/save/index.js index 75583a2..f75a284 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -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; diff --git a/src/utils/gcsCache.ts b/src/utils/gcsCache.ts index 041335b..e631fdd 100644 --- a/src/utils/gcsCache.ts +++ b/src/utils/gcsCache.ts @@ -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 { +): 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;