Skip to content

Commit

Permalink
[ci]: Check if there was a cache hit before checking for cache direct…
Browse files Browse the repository at this point in the history
…ory (#9)

* [ci]: check if cache exists after checking for hit
  • Loading branch information
r-LaForge authored Oct 3, 2022
1 parent e3f7fe0 commit 79c1a7e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59208,14 +59208,14 @@ const cacheBinary = () => __awaiter(void 0, void 0, void 0, function* () {
const state = core.getState(constants_1.State.CacheMatchedKey);
const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
const path = core.getState(constants_1.State.BinaryPath);
if (!fs_1.default.existsSync(path)) {
throw new Error(`Cache folder path doesn't exist on disk: ${path}`);
}
core.debug(`checking if cache hit occurred. primaryKey: ${primaryKey}, state: ${state}`);
if (primaryKey === state) {
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
return;
}
if (!fs_1.default.existsSync(path)) {
throw new Error(`Cache folder path doesn't exist on disk: ${path}`);
}
try {
yield cache.saveCache([path], primaryKey);
core.info(`Cache saved with the key: ${primaryKey}`);
Expand Down
2 changes: 1 addition & 1 deletion dist/cache-save/index.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/cache-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ export const cacheBinary = async () => {
const state = core.getState(State.CacheMatchedKey);
const primaryKey = core.getState(State.CachePrimaryKey);
const path = core.getState(State.BinaryPath);
if (!fs.existsSync(path)) {
throw new Error(`Cache folder path doesn't exist on disk: ${path}`);
}

core.debug(
`checking if cache hit occurred. primaryKey: ${primaryKey}, state: ${state}`
Expand All @@ -48,6 +45,10 @@ export const cacheBinary = async () => {
return;
}

if (!fs.existsSync(path)) {
throw new Error(`Cache folder path doesn't exist on disk: ${path}`);
}

try {
await cache.saveCache([path], primaryKey);
core.info(`Cache saved with the key: ${primaryKey}`);
Expand Down

0 comments on commit 79c1a7e

Please sign in to comment.