Skip to content

Commit

Permalink
Fix save logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fcsonline committed Dec 1, 2022
1 parent 4b0571b commit 4ae7258
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
6 changes: 3 additions & 3 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103396,20 +103396,20 @@ function restoreCache() {
const localKey = path.join(local, key, cacheFileName);
core.info(`Looking for exact match: ${localKey}`);
if (fs.existsSync(localKey)) {
core.info('Local cache HIT!');
core.info('Local cache HIT!');
yield fs.copy(localKey, archivePath);
core.info('Local cache copied!');
core.info('Extracting cache file...');
yield tar_1.extractTar(archivePath, compressionMethod);
utils_1.saveMatchedKey(localKey);
utils_1.saveMatchedKey(key);
utils_1.setCacheHitOutput(true);
utils_1.setCacheHitLocal(true);
core.info("Cache restored from local successfully");
return;
}
else {
utils_1.setCacheHitLocal(false);
core.info('Local cache MISS!');
core.info('Local cache MISS!');
}
}
const mc = utils_1.newMinio();
Expand Down
16 changes: 10 additions & 6 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98659,7 +98659,9 @@ function saveCache() {
const useFallback = utils_1.getInputAsBoolean("use-fallback");
const paths = utils_1.getInputAsArray("path");
const local = core.getInput("local");
if (((local && utils_1.isLocalHit()) || !local) && utils_1.isExactKeyMatch()) {
const shouldNotStoreInLocal = !local || (local && utils_1.isLocalHit());
const shouldNotStoreInRemote = utils_1.isExactKeyMatch();
if (shouldNotStoreInLocal && shouldNotStoreInRemote) {
core.info("Cache was exact key match, not saving");
return;
}
Expand All @@ -98682,11 +98684,13 @@ function saveCache() {
if (core.isDebug()) {
yield tar_1.listTar(archivePath, compressionMethod);
}
const object = path.join(key, cacheFileName);
core.info(`Uploading tar to s3. Bucket: ${bucket}, Object: ${object}`);
yield mc.fPutObject(bucket, object, archivePath, {});
core.info("Cache saved to s3 successfully");
if (local) {
if (!shouldNotStoreInRemote) {
const object = path.join(key, cacheFileName);
core.info(`Uploading tar to s3. Bucket: ${bucket}, Object: ${object}`);
yield mc.fPutObject(bucket, object, archivePath, {});
core.info("Cache saved to s3 successfully");
}
if (!shouldNotStoreInLocal) {
core.info("Local cache is enabled");
const localKey = path.join(local, key, cacheFileName);
core.info(`Storing local cache to: ${localKey}`);
Expand Down
6 changes: 3 additions & 3 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ async function restoreCache() {
core.info(`Looking for exact match: ${localKey}`);

if (fs.existsSync(localKey)) {
core.info('Local cache HIT!')
core.info('Local cache HIT!')
await fs.copy(localKey, archivePath)
core.info('Local cache copied!')

core.info('Extracting cache file...')
await extractTar(archivePath, compressionMethod);

saveMatchedKey(localKey);
saveMatchedKey(key);
setCacheHitOutput(true);
setCacheHitLocal(true);

core.info("Cache restored from local successfully");
return
} else {
setCacheHitLocal(false);
core.info('Local cache MISS!')
core.info('Local cache MISS!')
}
}

Expand Down
19 changes: 13 additions & 6 deletions src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ async function saveCache() {
const useFallback = getInputAsBoolean("use-fallback");
const paths = getInputAsArray("path");
const local = core.getInput("local");
const shouldNotStoreInLocal = !local || (local && isLocalHit())
const shouldNotStoreInRemote = isExactKeyMatch()

if (((local && isLocalHit()) || !local) && isExactKeyMatch()) {

if (shouldNotStoreInLocal && shouldNotStoreInRemote) {
core.info("Cache was exact key match, not saving");

return;
}

Expand All @@ -50,17 +54,20 @@ async function saveCache() {
core.debug(`Archive Path: ${archivePath}`);

await createTar(archiveFolder, cachePaths, compressionMethod);

if (core.isDebug()) {
await listTar(archivePath, compressionMethod);
}

const object = path.join(key, cacheFileName);
if (!shouldNotStoreInRemote) {
const object = path.join(key, cacheFileName);

core.info(`Uploading tar to s3. Bucket: ${bucket}, Object: ${object}`);
await mc.fPutObject(bucket, object, archivePath, {});
core.info("Cache saved to s3 successfully");
core.info(`Uploading tar to s3. Bucket: ${bucket}, Object: ${object}`);
await mc.fPutObject(bucket, object, archivePath, {});
core.info("Cache saved to s3 successfully");
}

if (local) {
if (!shouldNotStoreInLocal) {
core.info("Local cache is enabled");

const localKey = path.join(local, key, cacheFileName);
Expand Down

0 comments on commit 4ae7258

Please sign in to comment.