Skip to content
Merged
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
30 changes: 21 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 = (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);
Expand All @@ -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);
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
59 changes: 41 additions & 18 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -41,33 +51,46 @@ async function restoreCache() {
const cacheFileName = utils.getCacheFileName(compressionMethod);
const archivePath = path.join(
await utils.createTempDirectory(),
cacheFileName
cacheFileName,
);

const { item: obj, matchingKey } = await findObject(
mc,
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eblfo I think if lookupOnly is set, it'll never download the cache. Hope this is ok with you

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);
Expand All @@ -79,7 +102,7 @@ async function restoreCache() {
const fallbackMatchingKey = await cache.restoreCache(
paths,
key,
restoreKeys
restoreKeys,
);
if (fallbackMatchingKey) {
setCacheHitOutput(fallbackMatchingKey === key);
Expand Down
Loading