From e29dad3e36390db18fc19fb666cb1302f4929002 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:58:25 +0100 Subject: [PATCH 1/3] Fix fail-on-cache-miss not working --- dist/restore-only/index.js | 15 +++++---------- dist/restore/index.js | 15 +++++---------- src/restoreImpl.ts | 15 ++++++--------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index e8148ee..9a59ac0 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -59392,7 +59392,7 @@ const core = __importStar(__nccwpck_require__(2186)); const constants_1 = __nccwpck_require__(9042); const stateProvider_1 = __nccwpck_require__(1527); const utils = __importStar(__nccwpck_require__(6850)); -function restoreImpl(stateProvider) { +function restoreImpl(stateProvider, earlyExit) { return __awaiter(this, void 0, void 0, function* () { try { if (!utils.isCacheFeatureAvailable()) { @@ -59438,21 +59438,16 @@ function restoreImpl(stateProvider) { } catch (error) { core.setFailed(error.message); + if (earlyExit) { + process.exit(1); + } } }); } exports.restoreImpl = restoreImpl; function run(stateProvider, earlyExit) { return __awaiter(this, void 0, void 0, function* () { - try { - yield restoreImpl(stateProvider); - } - catch (err) { - console.error(err); - if (earlyExit) { - process.exit(1); - } - } + yield restoreImpl(stateProvider, earlyExit); // node will stay alive if any promises are not resolved, // which is a possibility if HTTP requests are dangling // due to retries or timeouts. We know that if we got here diff --git a/dist/restore/index.js b/dist/restore/index.js index 9995844..03a12b5 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -59392,7 +59392,7 @@ const core = __importStar(__nccwpck_require__(2186)); const constants_1 = __nccwpck_require__(9042); const stateProvider_1 = __nccwpck_require__(1527); const utils = __importStar(__nccwpck_require__(6850)); -function restoreImpl(stateProvider) { +function restoreImpl(stateProvider, earlyExit) { return __awaiter(this, void 0, void 0, function* () { try { if (!utils.isCacheFeatureAvailable()) { @@ -59438,21 +59438,16 @@ function restoreImpl(stateProvider) { } catch (error) { core.setFailed(error.message); + if (earlyExit) { + process.exit(1); + } } }); } exports.restoreImpl = restoreImpl; function run(stateProvider, earlyExit) { return __awaiter(this, void 0, void 0, function* () { - try { - yield restoreImpl(stateProvider); - } - catch (err) { - console.error(err); - if (earlyExit) { - process.exit(1); - } - } + yield restoreImpl(stateProvider, earlyExit); // node will stay alive if any promises are not resolved, // which is a possibility if HTTP requests are dangling // due to retries or timeouts. We know that if we got here diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 0aff57a..74a366d 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -10,7 +10,8 @@ import { import * as utils from "./utils/actionUtils"; export async function restoreImpl( - stateProvider: IStateProvider + stateProvider: IStateProvider, + earlyExit?: boolean | undefined ): Promise { try { if (!utils.isCacheFeatureAvailable()) { @@ -83,6 +84,9 @@ export async function restoreImpl( return cacheKey; } catch (error: unknown) { core.setFailed((error as Error).message); + if (earlyExit) { + process.exit(1); + } } } @@ -90,14 +94,7 @@ async function run( stateProvider: IStateProvider, earlyExit: boolean | undefined ): Promise { - try { - await restoreImpl(stateProvider); - } catch (err) { - console.error(err); - if (earlyExit) { - process.exit(1); - } - } + await restoreImpl(stateProvider, earlyExit); // node will stay alive if any promises are not resolved, // which is a possibility if HTTP requests are dangling From 3884cace147bdf9307fcc52a277f421af7b30798 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 15 Feb 2024 22:17:45 +0100 Subject: [PATCH 2/3] Bump version --- RELEASES.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 4674c44..e70823e 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,9 @@ # Releases +### 4.0.2 + +- Fixed restore `fail-on-cache-miss` not working. + ### 4.0.1 - Updated `isGhes` check diff --git a/package-lock.json b/package-lock.json index 0780399..a232507 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cache", - "version": "4.0.1", + "version": "4.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cache", - "version": "4.0.1", + "version": "4.0.2", "license": "MIT", "dependencies": { "@actions/cache": "^3.2.3", diff --git a/package.json b/package.json index fc29a4d..7468af5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cache", - "version": "4.0.1", + "version": "4.0.2", "private": true, "description": "Cache dependencies and build outputs", "main": "dist/restore/index.js", From 8a55f839aa4b4578e47bdc8a52828637cbb9a454 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 19 Mar 2024 09:28:12 +0100 Subject: [PATCH 3/3] Add test case for process exit Co-authored-by: Bethany --- __tests__/restoreImpl.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/__tests__/restoreImpl.test.ts b/__tests__/restoreImpl.test.ts index 8bab894..16f5f72 100644 --- a/__tests__/restoreImpl.test.ts +++ b/__tests__/restoreImpl.test.ts @@ -449,3 +449,19 @@ test("restore with lookup-only set", async () => { ); expect(failedMock).toHaveBeenCalledTimes(0); }); + +test("restore failure with earlyExit should call process exit", async () => { + testUtils.setInput(Inputs.Path, "node_modules"); + const failedMock = jest.spyOn(core, "setFailed"); + const restoreCacheMock = jest.spyOn(cache, "restoreCache"); + const processExitMock = jest.spyOn(process, "exit").mockImplementation(); + + // call restoreImpl with `earlyExit` set to true + await restoreImpl(new StateProvider(), true); + + expect(restoreCacheMock).toHaveBeenCalledTimes(0); + expect(failedMock).toHaveBeenCalledWith( + "Input required and not supplied: key" + ); + expect(processExitMock).toHaveBeenCalledWith(1); +});