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..31227c9 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 = (0, utils_1.getInputAsBoolean)("lookup-only"); 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,27 @@ 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); - } - 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); + const cacheHit = matchingKey === key; + (0, utils_1.setCacheHitOutput)(cacheHit); (0, utils_1.setCacheSizeOutput)(obj.size); - core.info("Cache restored from s3 successfully"); + if (lookupOnly) { + if (cacheHit && obj.size > 0) { + core.info(`Cache Hit. NOT Downloading cache from s3 because lookup-only is set. bucket: ${bucket}, object: ${obj.name}`); + } + else { + core.info(`Cache Miss or cache size is 0. NOT Downloading cache from s3 because lookup-only is set. bucket: ${bucket}, object: ${obj.name}`); + } + } + 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); + core.info("Cache restored from s3 successfully"); + } } catch (e) { core.info("Restore s3 cache failed: " + e.message); 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); } }; 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..c397e8b 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -26,13 +26,23 @@ async function restoreCache() { const useFallback = getInputAsBoolean("use-fallback"); const paths = getInputAsArray("path"); const restoreKeys = getInputAsArray("restore-keys"); + const lookupOnly = getInputAsBoolean("lookup-only"); try { // Inputs are re-evaluted before the post action, so we want to store the original values core.saveState(State.PrimaryKey, key); - core.saveState(State.AccessKey, getInput("accessKey", "AWS_ACCESS_KEY_ID")); - core.saveState(State.SecretKey, getInput("secretKey", "AWS_SECRET_ACCESS_KEY")); - core.saveState(State.SessionToken, getInput("sessionToken", "AWS_SESSION_TOKEN")); + core.saveState( + State.AccessKey, + getInput("accessKey", "AWS_ACCESS_KEY_ID"), + ); + core.saveState( + State.SecretKey, + getInput("secretKey", "AWS_SECRET_ACCESS_KEY"), + ); + core.saveState( + State.SessionToken, + getInput("sessionToken", "AWS_SESSION_TOKEN"), + ); core.saveState(State.Region, getInput("region", "AWS_REGION")); const mc = newMinio(); @@ -41,7 +51,7 @@ async function restoreCache() { const cacheFileName = utils.getCacheFileName(compressionMethod); const archivePath = path.join( await utils.createTempDirectory(), - cacheFileName + cacheFileName, ); const { item: obj, matchingKey } = await findObject( @@ -49,25 +59,38 @@ async function restoreCache() { bucket, key, restoreKeys, - compressionMethod + compressionMethod, ); 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); + const cacheHit = matchingKey === key; + setCacheHitOutput(cacheHit); + setCacheSizeOutput(obj.size); + if (lookupOnly) { + if (cacheHit && obj.size > 0) { + core.info( + `Cache Hit. NOT Downloading cache from s3 because lookup-only is set. bucket: ${bucket}, object: ${obj.name}`, + ); + } else { + core.info( + `Cache Miss or cache size is 0. NOT Downloading cache from s3 because lookup-only is set. bucket: ${bucket}, object: ${obj.name}`, + ) + } + } 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); + core.info("Cache restored from s3 successfully"); + } } catch (e) { core.info("Restore s3 cache failed: " + e.message); setCacheHitOutput(false); @@ -79,7 +102,7 @@ async function restoreCache() { const fallbackMatchingKey = await cache.restoreCache( paths, key, - restoreKeys + restoreKeys, ); if (fallbackMatchingKey) { setCacheHitOutput(fallbackMatchingKey === key);