Skip to content

Commit

Permalink
Fix cache-hit output when cache missed (actions#1404)
Browse files Browse the repository at this point in the history
* fix: cache-hit output

* fix: Output chache hit timing

* fix: Output chache hit timing

---------

Co-authored-by: Josh Gross <joshmgross@github.com>
  • Loading branch information
fchimpan and joshmgross authored Jul 31, 2024
1 parent e47d9f9 commit 40c3b67
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion __tests__/restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(0);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);

expect(failedMock).toHaveBeenCalledWith(
`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${key}`
Expand Down
3 changes: 2 additions & 1 deletion __tests__/restoreOnly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ test("restore with no cache found", async () => {
);

expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
expect(outputMock).toHaveBeenCalledTimes(1);
expect(outputMock).toHaveBeenCalledWith("cache-hit", "false");
expect(outputMock).toHaveBeenCalledTimes(2);
expect(failedMock).toHaveBeenCalledTimes(0);

expect(infoMock).toHaveBeenCalledWith(
Expand Down
1 change: 1 addition & 0 deletions dist/restore-only/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59415,6 +59415,7 @@ function restoreImpl(stateProvider, earlyExit) {
const lookupOnly = utils.getInputAsBool(constants_1.Inputs.LookupOnly);
const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { lookupOnly: lookupOnly }, enableCrossOsArchive);
if (!cacheKey) {
core.setOutput(constants_1.Outputs.CacheHit, false.toString());
if (failOnCacheMiss) {
throw new Error(`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`);
}
Expand Down
1 change: 1 addition & 0 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59415,6 +59415,7 @@ function restoreImpl(stateProvider, earlyExit) {
const lookupOnly = utils.getInputAsBool(constants_1.Inputs.LookupOnly);
const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { lookupOnly: lookupOnly }, enableCrossOsArchive);
if (!cacheKey) {
core.setOutput(constants_1.Outputs.CacheHit, false.toString());
if (failOnCacheMiss) {
throw new Error(`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/restoreImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function restoreImpl(
);

if (!cacheKey) {
core.setOutput(Outputs.CacheHit, false.toString());
if (failOnCacheMiss) {
throw new Error(
`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`
Expand All @@ -62,7 +63,6 @@ export async function restoreImpl(
...restoreKeys
].join(", ")}`
);

return;
}

Expand Down

0 comments on commit 40c3b67

Please sign in to comment.