From 64ae8e04f8b9c05a742f1a04cc4161032a12bcb9 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 23 Dec 2022 19:33:50 +0100 Subject: [PATCH] Small improvements --- __tests__/restore.test.ts | 4 ++-- dist/restore-only/index.js | 5 ++--- dist/restore/index.js | 5 ++--- src/restoreImpl.ts | 7 ++----- src/utils/testUtils.ts | 4 ++-- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index b185322..11a4c32 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -214,7 +214,7 @@ test("Fail restore when fail on cache miss is enabled and primary key not found" path: path, key, restoreKeys: [restoreKey], - failOnCacheMiss: true + failOnCacheMiss: "true" }); const failedMock = jest.spyOn(core, "setFailed"); @@ -248,7 +248,7 @@ test("Fail restore when fail on cache miss is enabled and primary key doesn't ma path: path, key, restoreKeys: [restoreKey], - failOnCacheMiss: true + failOnCacheMiss: "true" }); const failedMock = jest.spyOn(core, "setFailed"); diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 34c4dd6..3a2a36d 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -50498,7 +50498,7 @@ function restoreImpl(stateProvider) { const enableCrossOsArchive = utils.getInputAsBool(constants_1.Inputs.EnableCrossOsArchive); const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, {}, enableCrossOsArchive); if (!cacheKey) { - if (core.getBooleanInput(constants_1.Inputs.FailOnCacheMiss) == true) { + if (core.getBooleanInput(constants_1.Inputs.FailOnCacheMiss)) { throw new Error(`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`); } core.info(`Cache not found for input keys: ${[ @@ -50511,8 +50511,7 @@ function restoreImpl(stateProvider) { stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey); const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey); core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString()); - if (!isExactKeyMatch && - core.getBooleanInput(constants_1.Inputs.FailOnCacheMiss) == true) { + if (!isExactKeyMatch && core.getBooleanInput(constants_1.Inputs.FailOnCacheMiss)) { throw new Error(`Restored cache key doesn't match the given input key. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`); } core.info(`Cache restored from key: ${cacheKey}`); diff --git a/dist/restore/index.js b/dist/restore/index.js index df8456b..91d45ae 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -50498,7 +50498,7 @@ function restoreImpl(stateProvider) { const enableCrossOsArchive = utils.getInputAsBool(constants_1.Inputs.EnableCrossOsArchive); const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, {}, enableCrossOsArchive); if (!cacheKey) { - if (core.getBooleanInput(constants_1.Inputs.FailOnCacheMiss) == true) { + if (core.getBooleanInput(constants_1.Inputs.FailOnCacheMiss)) { throw new Error(`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`); } core.info(`Cache not found for input keys: ${[ @@ -50511,8 +50511,7 @@ function restoreImpl(stateProvider) { stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey); const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey); core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString()); - if (!isExactKeyMatch && - core.getBooleanInput(constants_1.Inputs.FailOnCacheMiss) == true) { + if (!isExactKeyMatch && core.getBooleanInput(constants_1.Inputs.FailOnCacheMiss)) { throw new Error(`Restored cache key doesn't match the given input key. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`); } core.info(`Cache restored from key: ${cacheKey}`); diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index db27f4f..79d69f5 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -44,7 +44,7 @@ async function restoreImpl( ); if (!cacheKey) { - if (core.getBooleanInput(Inputs.FailOnCacheMiss) == true) { + if (core.getBooleanInput(Inputs.FailOnCacheMiss)) { throw new Error( `Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}` ); @@ -68,10 +68,7 @@ async function restoreImpl( ); core.setOutput(Outputs.CacheHit, isExactKeyMatch.toString()); - if ( - !isExactKeyMatch && - core.getBooleanInput(Inputs.FailOnCacheMiss) == true - ) { + if (!isExactKeyMatch && core.getBooleanInput(Inputs.FailOnCacheMiss)) { throw new Error( `Restored cache key doesn't match the given input key. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}` ); diff --git a/src/utils/testUtils.ts b/src/utils/testUtils.ts index 2bc7d16..7044cdb 100644 --- a/src/utils/testUtils.ts +++ b/src/utils/testUtils.ts @@ -14,7 +14,7 @@ interface CacheInput { key: string; restoreKeys?: string[]; enableCrossOsArchive?: boolean; - failOnCacheMiss?: boolean; + failOnCacheMiss?: string; } export function setInputs(input: CacheInput): void { @@ -29,7 +29,7 @@ export function setInputs(input: CacheInput): void { input.enableCrossOsArchive.toString() ); input.failOnCacheMiss && - setInput(Inputs.FailOnCacheMiss, String(input.failOnCacheMiss)); + setInput(Inputs.FailOnCacheMiss, input.failOnCacheMiss); } export function clearInputs(): void {