Skip to content

Commit 0122982

Browse files
committed
Apply workaround for earlyExit
1 parent 3185ecf commit 0122982

File tree

8 files changed

+191
-143
lines changed

8 files changed

+191
-143
lines changed

__tests__/save.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
22
import * as core from "@actions/core";
33

44
import { Events, Inputs, RefKey } from "../src/constants";
5-
import run from "../src/save";
5+
import { saveRun } from "../src/saveImpl";
66
import * as actionUtils from "../src/utils/actionUtils";
77
import * as testUtils from "../src/utils/testUtils";
88

@@ -100,7 +100,7 @@ test("save with valid inputs uploads a cache", async () => {
100100
return Promise.resolve(cacheId);
101101
});
102102

103-
await run();
103+
await saveRun();
104104

105105
expect(saveCacheMock).toHaveBeenCalledTimes(1);
106106
expect(saveCacheMock).toHaveBeenCalledWith(

__tests__/saveImpl.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
22
import * as core from "@actions/core";
33

44
import { Events, Inputs, RefKey } from "../src/constants";
5-
import run from "../src/saveImpl";
5+
import { saveImpl } from "../src/saveImpl";
66
import { StateProvider } from "../src/stateProvider";
77
import * as actionUtils from "../src/utils/actionUtils";
88
import * as testUtils from "../src/utils/testUtils";
@@ -77,7 +77,7 @@ test("save with invalid event outputs warning", async () => {
7777
const invalidEvent = "commit_comment";
7878
process.env[Events.Key] = invalidEvent;
7979
delete process.env[RefKey];
80-
await run(new StateProvider());
80+
await saveImpl(new StateProvider());
8181
expect(logWarningMock).toHaveBeenCalledWith(
8282
`Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
8383
);
@@ -100,7 +100,7 @@ test("save with no primary key in state outputs warning", async () => {
100100
});
101101
const saveCacheMock = jest.spyOn(cache, "saveCache");
102102

103-
await run(new StateProvider());
103+
await saveImpl(new StateProvider());
104104

105105
expect(saveCacheMock).toHaveBeenCalledTimes(0);
106106
expect(logWarningMock).toHaveBeenCalledWith(`Key is not specified.`);
@@ -115,7 +115,7 @@ test("save without AC available should no-op", async () => {
115115

116116
const saveCacheMock = jest.spyOn(cache, "saveCache");
117117

118-
await run(new StateProvider());
118+
await saveImpl(new StateProvider());
119119

120120
expect(saveCacheMock).toHaveBeenCalledTimes(0);
121121
});
@@ -128,7 +128,7 @@ test("save on ghes without AC available should no-op", async () => {
128128

129129
const saveCacheMock = jest.spyOn(cache, "saveCache");
130130

131-
await run(new StateProvider());
131+
await saveImpl(new StateProvider());
132132

133133
expect(saveCacheMock).toHaveBeenCalledTimes(0);
134134
});
@@ -161,7 +161,7 @@ test("save on GHES with AC available", async () => {
161161
return Promise.resolve(cacheId);
162162
});
163163

164-
await run(new StateProvider());
164+
await saveImpl(new StateProvider());
165165

166166
expect(saveCacheMock).toHaveBeenCalledTimes(1);
167167
expect(saveCacheMock).toHaveBeenCalledWith(
@@ -194,7 +194,7 @@ test("save with exact match returns early", async () => {
194194
});
195195
const saveCacheMock = jest.spyOn(cache, "saveCache");
196196

197-
await run(new StateProvider());
197+
await saveImpl(new StateProvider());
198198

199199
expect(saveCacheMock).toHaveBeenCalledTimes(0);
200200
expect(infoMock).toHaveBeenCalledWith(
@@ -221,7 +221,7 @@ test("save with missing input outputs warning", async () => {
221221
});
222222
const saveCacheMock = jest.spyOn(cache, "saveCache");
223223

224-
await run(new StateProvider());
224+
await saveImpl(new StateProvider());
225225

226226
expect(saveCacheMock).toHaveBeenCalledTimes(0);
227227
expect(logWarningMock).toHaveBeenCalledWith(
@@ -259,7 +259,7 @@ test("save with large cache outputs warning", async () => {
259259
);
260260
});
261261

262-
await run(new StateProvider());
262+
await saveImpl(new StateProvider());
263263

264264
expect(saveCacheMock).toHaveBeenCalledTimes(1);
265265
expect(saveCacheMock).toHaveBeenCalledWith(
@@ -306,7 +306,7 @@ test("save with reserve cache failure outputs warning", async () => {
306306
throw error;
307307
});
308308

309-
await run(new StateProvider());
309+
await saveImpl(new StateProvider());
310310

311311
expect(saveCacheMock).toHaveBeenCalledTimes(1);
312312
expect(saveCacheMock).toHaveBeenCalledWith(
@@ -349,7 +349,7 @@ test("save with server error outputs warning", async () => {
349349
throw new Error("HTTP Error Occurred");
350350
});
351351

352-
await run(new StateProvider());
352+
await saveImpl(new StateProvider());
353353

354354
expect(saveCacheMock).toHaveBeenCalledTimes(1);
355355
expect(saveCacheMock).toHaveBeenCalledWith(
@@ -392,7 +392,7 @@ test("save with valid inputs uploads a cache", async () => {
392392
return Promise.resolve(cacheId);
393393
});
394394

395-
await run(new StateProvider());
395+
await saveImpl(new StateProvider());
396396

397397
expect(saveCacheMock).toHaveBeenCalledTimes(1);
398398
expect(saveCacheMock).toHaveBeenCalledWith(

__tests__/saveOnly.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
22
import * as core from "@actions/core";
33

44
import { Events, Inputs, RefKey } from "../src/constants";
5-
import run from "../src/saveOnly";
5+
import { saveOnlyRun } from "../src/saveImpl";
66
import * as actionUtils from "../src/utils/actionUtils";
77
import * as testUtils from "../src/utils/testUtils";
88

@@ -90,7 +90,7 @@ test("save with valid inputs uploads a cache", async () => {
9090
return Promise.resolve(cacheId);
9191
});
9292

93-
await run();
93+
await saveOnlyRun();
9494

9595
expect(saveCacheMock).toHaveBeenCalledTimes(1);
9696
expect(saveCacheMock).toHaveBeenCalledWith(
@@ -122,7 +122,7 @@ test("save failing logs the warning message", async () => {
122122
return Promise.resolve(cacheId);
123123
});
124124

125-
await run();
125+
await saveOnlyRun();
126126

127127
expect(saveCacheMock).toHaveBeenCalledTimes(1);
128128
expect(saveCacheMock).toHaveBeenCalledWith(

dist/save-only/index.js

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -59387,9 +59387,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
5938759387
});
5938859388
};
5938959389
Object.defineProperty(exports, "__esModule", ({ value: true }));
59390+
exports.saveRun = exports.saveOnlyRun = exports.saveImpl = void 0;
5939059391
const cache = __importStar(__nccwpck_require__(7799));
5939159392
const core = __importStar(__nccwpck_require__(2186));
5939259393
const constants_1 = __nccwpck_require__(9042);
59394+
const stateProvider_1 = __nccwpck_require__(1527);
5939359395
const utils = __importStar(__nccwpck_require__(6850));
5939459396
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
5939559397
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
@@ -59436,65 +59438,54 @@ function saveImpl(stateProvider) {
5943659438
return cacheId;
5943759439
});
5943859440
}
59439-
exports["default"] = saveImpl;
59440-
59441-
59442-
/***/ }),
59443-
59444-
/***/ 3160:
59445-
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
59446-
59447-
"use strict";
59448-
59449-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
59450-
if (k2 === undefined) k2 = k;
59451-
var desc = Object.getOwnPropertyDescriptor(m, k);
59452-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
59453-
desc = { enumerable: true, get: function() { return m[k]; } };
59454-
}
59455-
Object.defineProperty(o, k2, desc);
59456-
}) : (function(o, m, k, k2) {
59457-
if (k2 === undefined) k2 = k;
59458-
o[k2] = m[k];
59459-
}));
59460-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
59461-
Object.defineProperty(o, "default", { enumerable: true, value: v });
59462-
}) : function(o, v) {
59463-
o["default"] = v;
59464-
});
59465-
var __importStar = (this && this.__importStar) || function (mod) {
59466-
if (mod && mod.__esModule) return mod;
59467-
var result = {};
59468-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
59469-
__setModuleDefault(result, mod);
59470-
return result;
59471-
};
59472-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
59473-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
59474-
return new (P || (P = Promise))(function (resolve, reject) {
59475-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
59476-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
59477-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
59478-
step((generator = generator.apply(thisArg, _arguments || [])).next());
59441+
exports.saveImpl = saveImpl;
59442+
function saveOnlyRun(earlyExit) {
59443+
return __awaiter(this, void 0, void 0, function* () {
59444+
try {
59445+
const cacheId = yield saveImpl(new stateProvider_1.NullStateProvider());
59446+
if (cacheId === -1) {
59447+
core.warning(`Cache save failed.`);
59448+
}
59449+
}
59450+
catch (err) {
59451+
console.error(err);
59452+
if (earlyExit) {
59453+
process.exit(1);
59454+
}
59455+
}
59456+
// node will stay alive if any promises are not resolved,
59457+
// which is a possibility if HTTP requests are dangling
59458+
// due to retries or timeouts. We know that if we got here
59459+
// that all promises that we care about have successfully
59460+
// resolved, so simply exit with success.
59461+
if (earlyExit) {
59462+
process.exit(0);
59463+
}
5947959464
});
59480-
};
59481-
var __importDefault = (this && this.__importDefault) || function (mod) {
59482-
return (mod && mod.__esModule) ? mod : { "default": mod };
59483-
};
59484-
Object.defineProperty(exports, "__esModule", ({ value: true }));
59485-
const core = __importStar(__nccwpck_require__(2186));
59486-
const saveImpl_1 = __importDefault(__nccwpck_require__(6589));
59487-
const stateProvider_1 = __nccwpck_require__(1527);
59488-
function run() {
59465+
}
59466+
exports.saveOnlyRun = saveOnlyRun;
59467+
function saveRun(earlyExit) {
5948959468
return __awaiter(this, void 0, void 0, function* () {
59490-
const cacheId = yield (0, saveImpl_1.default)(new stateProvider_1.NullStateProvider());
59491-
if (cacheId === -1) {
59492-
core.warning(`Cache save failed.`);
59469+
try {
59470+
yield saveImpl(new stateProvider_1.StateProvider());
59471+
}
59472+
catch (err) {
59473+
console.error(err);
59474+
if (earlyExit) {
59475+
process.exit(1);
59476+
}
59477+
}
59478+
// node will stay alive if any promises are not resolved,
59479+
// which is a possibility if HTTP requests are dangling
59480+
// due to retries or timeouts. We know that if we got here
59481+
// that all promises that we care about have successfully
59482+
// resolved, so simply exit with success.
59483+
if (earlyExit) {
59484+
process.exit(0);
5949359485
}
5949459486
});
5949559487
}
59496-
run();
59497-
exports["default"] = run;
59488+
exports.saveRun = saveRun;
5949859489

5949959490

5950059491
/***/ }),
@@ -59882,12 +59873,18 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
5988259873
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
5988359874
/******/
5988459875
/************************************************************************/
59885-
/******/
59886-
/******/ // startup
59887-
/******/ // Load entry module and return exports
59888-
/******/ // This entry module is referenced by other modules so it can't be inlined
59889-
/******/ var __webpack_exports__ = __nccwpck_require__(3160);
59890-
/******/ module.exports = __webpack_exports__;
59891-
/******/
59876+
var __webpack_exports__ = {};
59877+
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
59878+
(() => {
59879+
"use strict";
59880+
var exports = __webpack_exports__;
59881+
59882+
Object.defineProperty(exports, "__esModule", ({ value: true }));
59883+
const saveImpl_1 = __nccwpck_require__(6589);
59884+
(0, saveImpl_1.saveOnlyRun)(true);
59885+
59886+
})();
59887+
59888+
module.exports = __webpack_exports__;
5989259889
/******/ })()
5989359890
;

0 commit comments

Comments
 (0)