Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -109657,16 +109658,23 @@ 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) && (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)(true);
(0, utils_1.setCacheSizeOutput)(obj.size);
}
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);
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
4 changes: 4 additions & 0 deletions restore/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 22 additions & 12 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,21 +54,30 @@ 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) && (matchingKey === key) && (obj.size > 0)) {
core.info(
`Cache Hit. NOT Downloading cache from s3, lookup-only is set. bucket: ${bucket}, object: ${obj.name}`
);

if (core.isDebug()) {
await listTar(archivePath, compressionMethod);
}
setCacheHitOutput(true);
setCacheSizeOutput(obj.size);
} else {
core.info(
`Downloading cache from s3 to ${archivePath}. bucket: ${bucket}, object: ${obj.name}`
);
await mc.fGetObject(bucket, obj.name, archivePath);

core.info(`Cache Size: ${formatSize(obj.size)} (${obj.size} bytes)`);
if (core.isDebug()) {
await listTar(archivePath, compressionMethod);
}

await extractTar(archivePath, compressionMethod);
setCacheHitOutput(matchingKey === key);
setCacheSizeOutput(obj.size)
core.info("Cache restored from s3 successfully");
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");
}
} catch (e) {
core.info("Restore s3 cache failed: " + e.message);
setCacheHitOutput(false);
Expand Down
Loading