From 87173c46d25af27add650e03065b014ff6187729 Mon Sep 17 00:00:00 2001 From: enrico b Date: Tue, 20 May 2025 09:50:50 +0300 Subject: [PATCH 1/4] SW-26574 - lookup-only --- action.yml | 4 ++++ dist/restore/index.js | 25 ++++++++++++++++--------- restore/action.yml | 4 ++++ src/restore.ts | 32 ++++++++++++++++++++------------ 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/action.yml b/action.yml index 4720c2f..42f9a6f 100644 --- a/action.yml +++ b/action.yml @@ -40,6 +40,10 @@ inputs: description: "Use github actions/cache as fallback" required: false default: "true" + lookup-only: + description: "Check if a restore is successfull but dont download/extract cache." + required: false + default: "false" # zip-option: # description: zip options # required: false diff --git a/dist/restore/index.js b/dist/restore/index.js index f029e26..e108505 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -109643,6 +109643,7 @@ function restoreCache() { const useFallback = (0, utils_1.getInputAsBoolean)("use-fallback"); const paths = (0, utils_1.getInputAsArray)("path"); const restoreKeys = (0, utils_1.getInputAsArray)("restore-keys"); + const lookupOnly = core.getInput("lookup-only", { required: false }); try { // Inputs are re-evaluted before the post action, so we want to store the original values core.saveState(state_1.State.PrimaryKey, key); @@ -109657,16 +109658,22 @@ function restoreCache() { const { item: obj, matchingKey } = yield (0, utils_1.findObject)(mc, bucket, key, restoreKeys, compressionMethod); core.debug("found cache object"); (0, utils_1.saveMatchedKey)(matchingKey); - core.info(`Downloading cache from s3 to ${archivePath}. bucket: ${bucket}, object: ${obj.name}`); - yield mc.fGetObject(bucket, obj.name, archivePath); - if (core.isDebug()) { - yield (0, tar_1.listTar)(archivePath, compressionMethod); + if ("true" === lookupOnly) { + core.info(`NOT Downloading cache from s3, lookup-only is set. bucket: ${bucket}, object: ${obj.name}`); + (0, utils_1.setCacheHitOutput)(matchingKey === key); + } + else { + core.info(`Downloading cache from s3 to ${archivePath}. bucket: ${bucket}, object: ${obj.name}`); + yield mc.fGetObject(bucket, obj.name, archivePath); + if (core.isDebug()) { + yield (0, tar_1.listTar)(archivePath, compressionMethod); + } + core.info(`Cache Size: ${(0, utils_1.formatSize)(obj.size)} (${obj.size} bytes)`); + yield (0, tar_1.extractTar)(archivePath, compressionMethod); + (0, utils_1.setCacheHitOutput)(matchingKey === key); + (0, utils_1.setCacheSizeOutput)(obj.size); + core.info("Cache restored from s3 successfully"); } - core.info(`Cache Size: ${(0, utils_1.formatSize)(obj.size)} (${obj.size} bytes)`); - yield (0, tar_1.extractTar)(archivePath, compressionMethod); - (0, utils_1.setCacheHitOutput)(matchingKey === key); - (0, utils_1.setCacheSizeOutput)(obj.size); - core.info("Cache restored from s3 successfully"); } catch (e) { core.info("Restore s3 cache failed: " + e.message); diff --git a/restore/action.yml b/restore/action.yml index 44b9ade..703bcfe 100644 --- a/restore/action.yml +++ b/restore/action.yml @@ -40,6 +40,10 @@ inputs: description: "Use github actions/cache as fallback" required: false default: "true" + lookup-only: + description: "Check if a restore is successfull but dont download/extract cache." + required: false + default: "false" # zip-option: # description: zip options # required: false diff --git a/src/restore.ts b/src/restore.ts index eac7e45..766e9ed 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -26,6 +26,7 @@ async function restoreCache() { const useFallback = getInputAsBoolean("use-fallback"); const paths = getInputAsArray("path"); const restoreKeys = getInputAsArray("restore-keys"); + const lookupOnly = core.getInput("lookup-only", { required: false }); try { // Inputs are re-evaluted before the post action, so we want to store the original values @@ -53,21 +54,28 @@ async function restoreCache() { ); core.debug("found cache object"); saveMatchedKey(matchingKey); - core.info( - `Downloading cache from s3 to ${archivePath}. bucket: ${bucket}, object: ${obj.name}` - ); - await mc.fGetObject(bucket, obj.name, archivePath); + if ("true" === lookupOnly) { + core.info( + `NOT Downloading cache from s3, lookup-only is set. bucket: ${bucket}, object: ${obj.name}` + ); + setCacheHitOutput(matchingKey === key); + } else { + core.info( + `Downloading cache from s3 to ${archivePath}. bucket: ${bucket}, object: ${obj.name}` + ); + await mc.fGetObject(bucket, obj.name, archivePath); - if (core.isDebug()) { - await listTar(archivePath, compressionMethod); - } + if (core.isDebug()) { + await listTar(archivePath, compressionMethod); + } - core.info(`Cache Size: ${formatSize(obj.size)} (${obj.size} bytes)`); + core.info(`Cache Size: ${formatSize(obj.size)} (${obj.size} bytes)`); - await extractTar(archivePath, compressionMethod); - setCacheHitOutput(matchingKey === key); - setCacheSizeOutput(obj.size) - core.info("Cache restored from s3 successfully"); + await extractTar(archivePath, compressionMethod); + setCacheHitOutput(matchingKey === key); + setCacheSizeOutput(obj.size) + core.info("Cache restored from s3 successfully"); + } } catch (e) { core.info("Restore s3 cache failed: " + e.message); setCacheHitOutput(false); From e686789af2e59f474859f027ef3859c2d007ac22 Mon Sep 17 00:00:00 2001 From: enrico b Date: Tue, 20 May 2025 09:54:28 +0300 Subject: [PATCH 2/4] SW-26574 - jest --- jest.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 6d7cb6a..df487eb 100644 --- a/jest.config.js +++ b/jest.config.js @@ -14,7 +14,7 @@ const processStdoutWrite = process.stdout.write.bind(process.stdout); process.stdout.write = (str, encoding, cb) => { // Core library will directly call process.stdout.write for commands // We don't want :: commands to be executed by the runner during tests - if (!str.match(/^::/)) { + if (typeof str === 'string' && !str.match(/^::/)) { return processStdoutWrite(str, encoding, cb); } }; From 20831c84c3cb4db52fa6eb40ac5d80131536756a Mon Sep 17 00:00:00 2001 From: enrico b Date: Tue, 20 May 2025 10:09:51 +0300 Subject: [PATCH 3/4] SW-26574 - lookup - msg --- dist/restore/index.js | 2 +- src/restore.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index e108505..f168684 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -109659,7 +109659,7 @@ function restoreCache() { core.debug("found cache object"); (0, utils_1.saveMatchedKey)(matchingKey); if ("true" === lookupOnly) { - core.info(`NOT Downloading cache from s3, lookup-only is set. bucket: ${bucket}, object: ${obj.name}`); + core.info(`Cache Hit. NOT Downloading cache from s3, lookup-only is set. bucket: ${bucket}, object: ${obj.name}`); (0, utils_1.setCacheHitOutput)(matchingKey === key); } else { diff --git a/src/restore.ts b/src/restore.ts index 766e9ed..2311fba 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -56,7 +56,7 @@ async function restoreCache() { saveMatchedKey(matchingKey); if ("true" === lookupOnly) { core.info( - `NOT Downloading cache from s3, lookup-only is set. bucket: ${bucket}, object: ${obj.name}` + `Cache Hit. NOT Downloading cache from s3, lookup-only is set. bucket: ${bucket}, object: ${obj.name}` ); setCacheHitOutput(matchingKey === key); } else { From 0c4a9a92e2d4eb8b6bf4adfabb5538c06f2ec20c Mon Sep 17 00:00:00 2001 From: enrico b Date: Tue, 20 May 2025 10:43:30 +0300 Subject: [PATCH 4/4] SW-26773 - more checks --- dist/restore/index.js | 5 +++-- src/restore.ts | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index f168684..24a8b75 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -109658,9 +109658,10 @@ function restoreCache() { const { item: obj, matchingKey } = yield (0, utils_1.findObject)(mc, bucket, key, restoreKeys, compressionMethod); core.debug("found cache object"); (0, utils_1.saveMatchedKey)(matchingKey); - if ("true" === lookupOnly) { + if (("true" === lookupOnly) && (matchingKey === key) && (obj.size > 0)) { core.info(`Cache Hit. NOT Downloading cache from s3, lookup-only is set. bucket: ${bucket}, object: ${obj.name}`); - (0, utils_1.setCacheHitOutput)(matchingKey === key); + (0, utils_1.setCacheHitOutput)(true); + (0, utils_1.setCacheSizeOutput)(obj.size); } else { core.info(`Downloading cache from s3 to ${archivePath}. bucket: ${bucket}, object: ${obj.name}`); diff --git a/src/restore.ts b/src/restore.ts index 2311fba..b8aac33 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -54,11 +54,13 @@ async function restoreCache() { ); core.debug("found cache object"); saveMatchedKey(matchingKey); - if ("true" === lookupOnly) { + if (("true" === lookupOnly) && (matchingKey === key) && (obj.size > 0)) { core.info( `Cache Hit. NOT Downloading cache from s3, lookup-only is set. bucket: ${bucket}, object: ${obj.name}` ); - setCacheHitOutput(matchingKey === key); + + setCacheHitOutput(true); + setCacheSizeOutput(obj.size); } else { core.info( `Downloading cache from s3 to ${archivePath}. bucket: ${bucket}, object: ${obj.name}`