Skip to content

Commit 0c45773

Browse files
authoredMar 19, 2024
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss
Fix `fail-on-cache-miss` not working
2 parents ab5e6d0 + 8a55f83 commit 0c45773

File tree

7 files changed

+39
-32
lines changed

7 files changed

+39
-32
lines changed
 

‎RELEASES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
### 4.0.2
4+
5+
- Fixed restore `fail-on-cache-miss` not working.
6+
37
### 4.0.1
48

59
- Updated `isGhes` check

‎__tests__/restoreImpl.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,19 @@ test("restore with lookup-only set", async () => {
449449
);
450450
expect(failedMock).toHaveBeenCalledTimes(0);
451451
});
452+
453+
test("restore failure with earlyExit should call process exit", async () => {
454+
testUtils.setInput(Inputs.Path, "node_modules");
455+
const failedMock = jest.spyOn(core, "setFailed");
456+
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
457+
const processExitMock = jest.spyOn(process, "exit").mockImplementation();
458+
459+
// call restoreImpl with `earlyExit` set to true
460+
await restoreImpl(new StateProvider(), true);
461+
462+
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
463+
expect(failedMock).toHaveBeenCalledWith(
464+
"Input required and not supplied: key"
465+
);
466+
expect(processExitMock).toHaveBeenCalledWith(1);
467+
});

‎dist/restore-only/index.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -59392,7 +59392,7 @@ const core = __importStar(__nccwpck_require__(2186));
5939259392
const constants_1 = __nccwpck_require__(9042);
5939359393
const stateProvider_1 = __nccwpck_require__(1527);
5939459394
const utils = __importStar(__nccwpck_require__(6850));
59395-
function restoreImpl(stateProvider) {
59395+
function restoreImpl(stateProvider, earlyExit) {
5939659396
return __awaiter(this, void 0, void 0, function* () {
5939759397
try {
5939859398
if (!utils.isCacheFeatureAvailable()) {
@@ -59438,21 +59438,16 @@ function restoreImpl(stateProvider) {
5943859438
}
5943959439
catch (error) {
5944059440
core.setFailed(error.message);
59441+
if (earlyExit) {
59442+
process.exit(1);
59443+
}
5944159444
}
5944259445
});
5944359446
}
5944459447
exports.restoreImpl = restoreImpl;
5944559448
function run(stateProvider, earlyExit) {
5944659449
return __awaiter(this, void 0, void 0, function* () {
59447-
try {
59448-
yield restoreImpl(stateProvider);
59449-
}
59450-
catch (err) {
59451-
console.error(err);
59452-
if (earlyExit) {
59453-
process.exit(1);
59454-
}
59455-
}
59450+
yield restoreImpl(stateProvider, earlyExit);
5945659451
// node will stay alive if any promises are not resolved,
5945759452
// which is a possibility if HTTP requests are dangling
5945859453
// due to retries or timeouts. We know that if we got here

‎dist/restore/index.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -59392,7 +59392,7 @@ const core = __importStar(__nccwpck_require__(2186));
5939259392
const constants_1 = __nccwpck_require__(9042);
5939359393
const stateProvider_1 = __nccwpck_require__(1527);
5939459394
const utils = __importStar(__nccwpck_require__(6850));
59395-
function restoreImpl(stateProvider) {
59395+
function restoreImpl(stateProvider, earlyExit) {
5939659396
return __awaiter(this, void 0, void 0, function* () {
5939759397
try {
5939859398
if (!utils.isCacheFeatureAvailable()) {
@@ -59438,21 +59438,16 @@ function restoreImpl(stateProvider) {
5943859438
}
5943959439
catch (error) {
5944059440
core.setFailed(error.message);
59441+
if (earlyExit) {
59442+
process.exit(1);
59443+
}
5944159444
}
5944259445
});
5944359446
}
5944459447
exports.restoreImpl = restoreImpl;
5944559448
function run(stateProvider, earlyExit) {
5944659449
return __awaiter(this, void 0, void 0, function* () {
59447-
try {
59448-
yield restoreImpl(stateProvider);
59449-
}
59450-
catch (err) {
59451-
console.error(err);
59452-
if (earlyExit) {
59453-
process.exit(1);
59454-
}
59455-
}
59450+
yield restoreImpl(stateProvider, earlyExit);
5945659451
// node will stay alive if any promises are not resolved,
5945759452
// which is a possibility if HTTP requests are dangling
5945859453
// due to retries or timeouts. We know that if we got here

‎package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cache",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"private": true,
55
"description": "Cache dependencies and build outputs",
66
"main": "dist/restore/index.js",

‎src/restoreImpl.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
import * as utils from "./utils/actionUtils";
1111

1212
export async function restoreImpl(
13-
stateProvider: IStateProvider
13+
stateProvider: IStateProvider,
14+
earlyExit?: boolean | undefined
1415
): Promise<string | undefined> {
1516
try {
1617
if (!utils.isCacheFeatureAvailable()) {
@@ -83,21 +84,17 @@ export async function restoreImpl(
8384
return cacheKey;
8485
} catch (error: unknown) {
8586
core.setFailed((error as Error).message);
87+
if (earlyExit) {
88+
process.exit(1);
89+
}
8690
}
8791
}
8892

8993
async function run(
9094
stateProvider: IStateProvider,
9195
earlyExit: boolean | undefined
9296
): Promise<void> {
93-
try {
94-
await restoreImpl(stateProvider);
95-
} catch (err) {
96-
console.error(err);
97-
if (earlyExit) {
98-
process.exit(1);
99-
}
100-
}
97+
await restoreImpl(stateProvider, earlyExit);
10198

10299
// node will stay alive if any promises are not resolved,
103100
// which is a possibility if HTTP requests are dangling

0 commit comments

Comments
 (0)