diff --git a/RELEASES.md b/RELEASES.md index 4674c447..e70823ec 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/__tests__/restoreImpl.test.ts b/__tests__/restoreImpl.test.ts index 639b944f..ed42c432 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); +}); diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 71fd6412..6077e826 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -94935,7 +94935,7 @@ const stateProvider_1 = __nccwpck_require__(1527); const utils = __importStar(__nccwpck_require__(4427)); const restore = __importStar(__nccwpck_require__(8486)); const install = __importStar(__nccwpck_require__(8501)); -function restoreImpl(stateProvider) { +function restoreImpl(stateProvider, earlyExit) { var _a, _b, _c, _d, _e, _f, _g; return __awaiter(this, void 0, void 0, function* () { try { @@ -95041,21 +95041,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 175b3bd9..f2c0cac6 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -94935,7 +94935,7 @@ const stateProvider_1 = __nccwpck_require__(1527); const utils = __importStar(__nccwpck_require__(4427)); const restore = __importStar(__nccwpck_require__(8486)); const install = __importStar(__nccwpck_require__(8501)); -function restoreImpl(stateProvider) { +function restoreImpl(stateProvider, earlyExit) { var _a, _b, _c, _d, _e, _f, _g; return __awaiter(this, void 0, void 0, function* () { try { @@ -95041,21 +95041,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/package-lock.json b/package-lock.json index 6c6d2cc2..d6b4af60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cache", - "version": "4.0.1", + "version": "4.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cache", - "version": "4.0.1", + "version": "4.0.2", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 3bd28196..4fc3b2f4 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", diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 0e66cc29..c88c60ab 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -12,7 +12,8 @@ import * as restore from "./utils/restore"; import * as install from "./utils/install"; export async function restoreImpl( - stateProvider: IStateProvider + stateProvider: IStateProvider, + earlyExit?: boolean | undefined ): Promise { try { core.setOutput(Outputs.Hit, false); @@ -154,6 +155,9 @@ export async function restoreImpl( return restoredKey; } catch (error: unknown) { core.setFailed((error as Error).message); + if (earlyExit) { + process.exit(1); + } } } @@ -161,14 +165,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