Skip to content

Commit

Permalink
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss
Browse files Browse the repository at this point in the history
Fix `fail-on-cache-miss` not working
  • Loading branch information
bethanyj28 committed Mar 19, 2024
2 parents ab5e6d0 + 8a55f83 commit 0c45773
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

### 4.0.2

- Fixed restore `fail-on-cache-miss` not working.

### 4.0.1

- Updated `isGhes` check
Expand Down
16 changes: 16 additions & 0 deletions __tests__/restoreImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
15 changes: 5 additions & 10 deletions dist/restore-only/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 6 additions & 9 deletions src/restoreImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
import * as utils from "./utils/actionUtils";

export async function restoreImpl(
stateProvider: IStateProvider
stateProvider: IStateProvider,
earlyExit?: boolean | undefined
): Promise<string | undefined> {
try {
if (!utils.isCacheFeatureAvailable()) {
Expand Down Expand Up @@ -83,21 +84,17 @@ export async function restoreImpl(
return cacheKey;
} catch (error: unknown) {
core.setFailed((error as Error).message);
if (earlyExit) {
process.exit(1);
}
}
}

async function run(
stateProvider: IStateProvider,
earlyExit: boolean | undefined
): Promise<void> {
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
Expand Down

0 comments on commit 0c45773

Please sign in to comment.