From 40c3b67b2955d93d83b27ed164edd0756bc24049 Mon Sep 17 00:00:00 2001 From: r4mimu <52129983+fchimpan@users.noreply.github.com> Date: Thu, 1 Aug 2024 01:56:48 +0900 Subject: [PATCH] Fix cache-hit output when cache missed (#1404) * fix: cache-hit output * fix: Output chache hit timing * fix: Output chache hit timing --------- Co-authored-by: Josh Gross --- __tests__/restore.test.ts | 2 +- __tests__/restoreOnly.test.ts | 3 ++- dist/restore-only/index.js | 1 + dist/restore/index.js | 1 + src/restoreImpl.ts | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 250f7ef..9b066eb 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -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}` diff --git a/__tests__/restoreOnly.test.ts b/__tests__/restoreOnly.test.ts index 81e5bca..840307d 100644 --- a/__tests__/restoreOnly.test.ts +++ b/__tests__/restoreOnly.test.ts @@ -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( diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 9a59ac0..d2f3631 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -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}`); } diff --git a/dist/restore/index.js b/dist/restore/index.js index 03a12b5..842eaa6 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -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}`); } diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 74a366d..bb302ac 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -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}` @@ -62,7 +63,6 @@ export async function restoreImpl( ...restoreKeys ].join(", ")}` ); - return; }