From 5a1d04e5f367ddb8dbee9138f62e2b055875ce24 Mon Sep 17 00:00:00 2001 From: rak Date: Tue, 18 Mar 2025 21:53:50 +0100 Subject: [PATCH] Fix incorrect cache-hit check --- dist/cleanup/index.js | 7 ++++--- dist/setup/index.js | 7 ++++--- src/cache.ts | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 703a626b..a689bf74 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -96625,7 +96625,7 @@ function computeCacheKey(packageManager, cacheDependencyPath) { if (!fileHash) { throw new Error(`No file in ${process.cwd()} matched to [${pattern}], make sure you have checked out the target repository`); } - return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-ABC-${process.arch}-${packageManager.id}-${fileHash}`; + return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${packageManager.id}-${fileHash}`; }); } /** @@ -96643,10 +96643,12 @@ function restore(id, cacheDependencyPath) { const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey); if (matchedKey) { core.saveState(CACHE_MATCHED_KEY, matchedKey); + core.saveState(STATE_CACHE_HIT, true); core.setOutput('cache-hit', true); core.info(`Cache restored from key: ${matchedKey}`); } else { + core.saveState(STATE_CACHE_HIT, false); core.setOutput('cache-hit', false); core.info(`${packageManager.id} cache is not found`); } @@ -96660,7 +96662,6 @@ exports.restore = restore; function save(id) { return __awaiter(this, void 0, void 0, function* () { const packageManager = findPackageManager(id); - const matchedKey = core.getState(CACHE_MATCHED_KEY); // Inputs are re-evaluated before the post action, so we want the original key used for restore const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY); const cacheHit = core.getState(STATE_CACHE_HIT); @@ -96668,7 +96669,7 @@ function save(id) { core.warning('Error retrieving key from state.'); return; } - else if (matchedKey === primaryKey || cacheHit) { + else if (cacheHit) { // no change in target directories core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); return; diff --git a/dist/setup/index.js b/dist/setup/index.js index 3ed99fbf..e2f31f16 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -131874,7 +131874,7 @@ function computeCacheKey(packageManager, cacheDependencyPath) { if (!fileHash) { throw new Error(`No file in ${process.cwd()} matched to [${pattern}], make sure you have checked out the target repository`); } - return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-ABC-${process.arch}-${packageManager.id}-${fileHash}`; + return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${packageManager.id}-${fileHash}`; }); } /** @@ -131892,10 +131892,12 @@ function restore(id, cacheDependencyPath) { const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey); if (matchedKey) { core.saveState(CACHE_MATCHED_KEY, matchedKey); + core.saveState(STATE_CACHE_HIT, true); core.setOutput('cache-hit', true); core.info(`Cache restored from key: ${matchedKey}`); } else { + core.saveState(STATE_CACHE_HIT, false); core.setOutput('cache-hit', false); core.info(`${packageManager.id} cache is not found`); } @@ -131909,7 +131911,6 @@ exports.restore = restore; function save(id) { return __awaiter(this, void 0, void 0, function* () { const packageManager = findPackageManager(id); - const matchedKey = core.getState(CACHE_MATCHED_KEY); // Inputs are re-evaluated before the post action, so we want the original key used for restore const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY); const cacheHit = core.getState(STATE_CACHE_HIT); @@ -131917,7 +131918,7 @@ function save(id) { core.warning('Error retrieving key from state.'); return; } - else if (matchedKey === primaryKey || cacheHit) { + else if (cacheHit) { // no change in target directories core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); return; diff --git a/src/cache.ts b/src/cache.ts index 65f40c4e..5fca2fb2 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -99,7 +99,7 @@ async function computeCacheKey( `No file in ${process.cwd()} matched to [${pattern}], make sure you have checked out the target repository` ); } - return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-ABC-${process.arch}-${packageManager.id}-${fileHash}`; + return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${packageManager.id}-${fileHash}`; } /** @@ -117,9 +117,11 @@ export async function restore(id: string, cacheDependencyPath: string) { const matchedKey = await cache.restoreCache(packageManager.path, primaryKey); if (matchedKey) { core.saveState(CACHE_MATCHED_KEY, matchedKey); + core.saveState(STATE_CACHE_HIT, true); core.setOutput('cache-hit', true); core.info(`Cache restored from key: ${matchedKey}`); } else { + core.saveState(STATE_CACHE_HIT, false); core.setOutput('cache-hit', false); core.info(`${packageManager.id} cache is not found`); } @@ -131,7 +133,6 @@ export async function restore(id: string, cacheDependencyPath: string) { */ export async function save(id: string) { const packageManager = findPackageManager(id); - const matchedKey = core.getState(CACHE_MATCHED_KEY); // Inputs are re-evaluated before the post action, so we want the original key used for restore const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY); @@ -140,7 +141,7 @@ export async function save(id: string) { if (!primaryKey) { core.warning('Error retrieving key from state.'); return; - } else if (matchedKey === primaryKey || cacheHit) { + } else if (cacheHit) { // no change in target directories core.info( `Cache hit occurred on the primary key ${primaryKey}, not saving cache.`