From cce93fb2c7a56e99183e4d1542ea5cb8fca478ee Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 6 Dec 2022 08:23:10 +0000 Subject: [PATCH 1/6] Generated dist --- dist/restore/index.js | 206 +++++++++++++++++++++++------------------- src/outputSetter.ts | 2 +- src/restoreOnly.ts | 4 +- 3 files changed, 117 insertions(+), 95 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index 26ddd0f..70fc9be 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -3701,30 +3701,7 @@ exports.DiagAPI = DiagAPI; /* 121 */, /* 122 */, /* 123 */, -/* 124 */ -/***/ (function(__unusedmodule, exports) { - -"use strict"; - -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=tracer_provider.js.map - -/***/ }), +/* 124 */, /* 125 */, /* 126 */, /* 127 */, @@ -4981,7 +4958,41 @@ exports.checkBypass = checkBypass; /* 193 */, /* 194 */, /* 195 */, -/* 196 */, +/* 196 */ +/***/ (function(__unusedmodule, exports) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; +var Inputs; +(function (Inputs) { + Inputs["Key"] = "key"; + Inputs["Path"] = "path"; + Inputs["RestoreKeys"] = "restore-keys"; + Inputs["UploadChunkSize"] = "upload-chunk-size"; +})(Inputs = exports.Inputs || (exports.Inputs = {})); +var Outputs; +(function (Outputs) { + Outputs["CacheHit"] = "cache-hit"; + Outputs["Key"] = "key"; + Outputs["Path"] = "path"; +})(Outputs = exports.Outputs || (exports.Outputs = {})); +var State; +(function (State) { + State["CachePrimaryKey"] = "CACHE_KEY"; + State["CacheMatchedKey"] = "CACHE_RESULT"; +})(State = exports.State || (exports.State = {})); +var Events; +(function (Events) { + Events["Key"] = "GITHUB_EVENT_NAME"; + Events["Push"] = "push"; + Events["PullRequest"] = "pull_request"; +})(Events = exports.Events || (exports.Events = {})); +exports.RefKey = "GITHUB_REF"; + + +/***/ }), /* 197 */ /***/ (function(__unusedmodule, exports, __webpack_require__) { @@ -38349,7 +38360,7 @@ __exportStar(__webpack_require__(220), exports); __exportStar(__webpack_require__(932), exports); __exportStar(__webpack_require__(975), exports); __exportStar(__webpack_require__(207), exports); -__exportStar(__webpack_require__(124), exports); +__exportStar(__webpack_require__(694), exports); __exportStar(__webpack_require__(695), exports); var spancontext_utils_1 = __webpack_require__(629); Object.defineProperty(exports, "isSpanContextValid", { enumerable: true, get: function () { return spancontext_utils_1.isSpanContextValid; } }); @@ -38421,7 +38432,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.isCacheFeatureAvailable = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; const cache = __importStar(__webpack_require__(692)); const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(694); +const constants_1 = __webpack_require__(196); function isGhes() { const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; @@ -47520,34 +47531,23 @@ exports.saveCache = saveCache; "use strict"; +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; -var Inputs; -(function (Inputs) { - Inputs["Key"] = "key"; - Inputs["Path"] = "path"; - Inputs["RestoreKeys"] = "restore-keys"; - Inputs["UploadChunkSize"] = "upload-chunk-size"; -})(Inputs = exports.Inputs || (exports.Inputs = {})); -var Outputs; -(function (Outputs) { - Outputs["CacheHit"] = "cache-hit"; - Outputs["Key"] = "key"; - Outputs["Path"] = "path"; -})(Outputs = exports.Outputs || (exports.Outputs = {})); -var State; -(function (State) { - State["CachePrimaryKey"] = "CACHE_KEY"; - State["CacheMatchedKey"] = "CACHE_RESULT"; -})(State = exports.State || (exports.State = {})); -var Events; -(function (Events) { - Events["Key"] = "GITHUB_EVENT_NAME"; - Events["Push"] = "push"; - Events["PullRequest"] = "pull_request"; -})(Events = exports.Events || (exports.Events = {})); -exports.RefKey = "GITHUB_REF"; - +//# sourceMappingURL=tracer_provider.js.map /***/ }), /* 695 */ @@ -48958,29 +48958,6 @@ module.exports = function(dst, src) { "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -48994,20 +48971,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(694); +const outputSetter_1 = __webpack_require__(958); const restoreImpl_1 = __importDefault(__webpack_require__(835)); -const utils = __importStar(__webpack_require__(443)); function restore() { return __awaiter(this, void 0, void 0, function* () { - const cacheKey = yield (0, restoreImpl_1.default)(); - if (cacheKey) { - // Store the matched cache key in states - utils.setCacheState(cacheKey); - const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey); - utils.setCacheHitOutput(isExactKeyMatch); - core.info(`Cache restored from key: ${cacheKey}`); - } + yield (0, restoreImpl_1.default)(new outputSetter_1.StateOutputSetter()); }); } exports.default = restore; @@ -50657,9 +50625,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const cache = __importStar(__webpack_require__(692)); const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(694); +const constants_1 = __webpack_require__(196); const utils = __importStar(__webpack_require__(443)); -function run() { +function run(outputter) { return __awaiter(this, void 0, void 0, function* () { try { if (!utils.isCacheFeatureAvailable()) { @@ -50672,7 +50640,7 @@ function run() { return; } const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true }); - core.saveState(constants_1.State.CachePrimaryKey, primaryKey); + outputter.setState(constants_1.State.CachePrimaryKey, primaryKey); const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys); const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { required: true @@ -50685,6 +50653,13 @@ function run() { ].join(", ")}`); return; } + // Store the matched cache key in states + //utils.setCacheState(cacheKey); + outputter.setState(constants_1.State.CacheMatchedKey, cacheKey); + const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey); + //utils.setCacheHitOutput(isExactKeyMatch); + outputter.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString()); + core.info(`Cache restored from key: ${cacheKey}`); return cacheKey; } catch (error) { @@ -55007,7 +54982,54 @@ exports._globalThis = typeof globalThis === 'object' ? globalThis : global; /***/ }), /* 957 */, -/* 958 */, +/* 958 */ +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.NonStateOutputSetter = exports.StateOutputSetter = void 0; +const core = __importStar(__webpack_require__(470)); +class StateOutputSetter { + constructor() { + this.setOutput = core.setOutput; + this.setState = core.saveState; + } +} +exports.StateOutputSetter = StateOutputSetter; +class NonStateOutputSetter { + constructor() { + this.setOutput = core.setOutput; + this.setState = core.setOutput; + } +} +exports.NonStateOutputSetter = NonStateOutputSetter; + + +/***/ }), /* 959 */, /* 960 */ /***/ (function(__unusedmodule, exports, __webpack_require__) { diff --git a/src/outputSetter.ts b/src/outputSetter.ts index 29d11fb..4b0618e 100644 --- a/src/outputSetter.ts +++ b/src/outputSetter.ts @@ -10,7 +10,7 @@ export class StateOutputSetter implements IOutputSetter { setState = core.saveState; } -export class NonStateOuputSetter implements IOutputSetter { +export class NonStateOutputSetter implements IOutputSetter { setOutput = core.setOutput; setState = core.setOutput; } diff --git a/src/restoreOnly.ts b/src/restoreOnly.ts index 282fe93..ee73a01 100644 --- a/src/restoreOnly.ts +++ b/src/restoreOnly.ts @@ -1,8 +1,8 @@ -import { NonStateOuputSetter } from "./outputSetter"; +import { NonStateOutputSetter } from "./outputSetter"; import run from "./restoreImpl"; async function restoreOnly(): Promise { - await run(new NonStateOuputSetter()); + await run(new NonStateOutputSetter()); } export default restoreOnly; From 85ae5bbcea16456f2d79f718d9b2a2c19a2caa1a Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 6 Dec 2022 09:36:37 +0000 Subject: [PATCH 2/6] Fixed breaking test case --- __tests__/restore.test.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index e9a505b..6d78052 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -102,7 +102,7 @@ test("restore on GHES with AC available ", async () => { const infoMock = jest.spyOn(core, "info"); const failedMock = jest.spyOn(core, "setFailed"); const stateMock = jest.spyOn(core, "saveState"); - const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); + const setCacheHitOutputMock = jest.spyOn(core, "setOutput"); const restoreCacheMock = jest .spyOn(cache, "restoreCache") .mockImplementationOnce(() => { @@ -116,7 +116,7 @@ test("restore on GHES with AC available ", async () => { expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); - expect(setCacheHitOutputMock).toHaveBeenCalledWith(true); + expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`); expect(failedMock).toHaveBeenCalledTimes(0); @@ -270,7 +270,7 @@ test("restore with cache found for key", async () => { const infoMock = jest.spyOn(core, "info"); const failedMock = jest.spyOn(core, "setFailed"); const stateMock = jest.spyOn(core, "saveState"); - const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); + const setCacheHitOutputMock = jest.spyOn(core, "setOutput"); const restoreCacheMock = jest .spyOn(cache, "restoreCache") .mockImplementationOnce(() => { @@ -284,7 +284,7 @@ test("restore with cache found for key", async () => { expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); - expect(setCacheHitOutputMock).toHaveBeenCalledWith(true); + expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`); expect(failedMock).toHaveBeenCalledTimes(0); @@ -303,7 +303,7 @@ test("restore with cache found for restore key", async () => { const infoMock = jest.spyOn(core, "info"); const failedMock = jest.spyOn(core, "setFailed"); const stateMock = jest.spyOn(core, "saveState"); - const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); + const setCacheHitOutputMock = jest.spyOn(core, "setOutput"); const restoreCacheMock = jest .spyOn(cache, "restoreCache") .mockImplementationOnce(() => { @@ -317,8 +317,7 @@ test("restore with cache found for restore key", async () => { expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); - expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); - + expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false"); expect(infoMock).toHaveBeenCalledWith( `Cache restored from key: ${restoreKey}` ); From e02e5113eddc911dd5a75f1554ed0f0d11278a02 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 6 Dec 2022 10:03:48 +0000 Subject: [PATCH 3/6] Removed return type in promise --- src/restoreImpl.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 868e812..679dcd2 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -5,7 +5,7 @@ import { Events, Inputs, Outputs, State } from "./constants"; import { IOutputSetter } from "./outputSetter"; import * as utils from "./utils/actionUtils"; -async function run(outputter: IOutputSetter): Promise { +async function run(outputter: IOutputSetter): Promise { try { if (!utils.isCacheFeatureAvailable()) { utils.setCacheHitOutput(false); @@ -59,7 +59,7 @@ async function run(outputter: IOutputSetter): Promise { outputter.setOutput(Outputs.CacheHit, isExactKeyMatch.toString()); core.info(`Cache restored from key: ${cacheKey}`); - return cacheKey; + return; } catch (error: unknown) { core.setFailed((error as Error).message); } From a76826ef46eda2ed649a006956884f6690917102 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 6 Dec 2022 10:07:30 +0000 Subject: [PATCH 4/6] Removed commented lines --- src/restoreImpl.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 679dcd2..3bbc840 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -48,14 +48,12 @@ async function run(outputter: IOutputSetter): Promise { } // Store the matched cache key in states - //utils.setCacheState(cacheKey); outputter.setState(State.CacheMatchedKey, cacheKey); const isExactKeyMatch = utils.isExactKeyMatch( core.getInput(Inputs.Key, { required: true }), cacheKey ); - //utils.setCacheHitOutput(isExactKeyMatch); outputter.setOutput(Outputs.CacheHit, isExactKeyMatch.toString()); core.info(`Cache restored from key: ${cacheKey}`); From d6e98d930262c2585221e283afd2b850ec5ddef1 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 6 Dec 2022 10:08:26 +0000 Subject: [PATCH 5/6] Calling methods from same file --- src/restore.ts | 2 ++ src/restoreOnly.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/restore.ts b/src/restore.ts index 6b9e221..7f11e2f 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -5,4 +5,6 @@ async function restore(): Promise { await run(new StateOutputSetter()); } +restore(); + export default restore; diff --git a/src/restoreOnly.ts b/src/restoreOnly.ts index ee73a01..a5bf399 100644 --- a/src/restoreOnly.ts +++ b/src/restoreOnly.ts @@ -5,4 +5,6 @@ async function restoreOnly(): Promise { await run(new NonStateOutputSetter()); } +restoreOnly(); + export default restoreOnly; From 86712a07334f26262744a7efc00801fbaf6a9027 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 6 Dec 2022 10:10:52 +0000 Subject: [PATCH 6/6] dist --- dist/restore/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index 70fc9be..92394dd 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -48978,6 +48978,7 @@ function restore() { yield (0, restoreImpl_1.default)(new outputSetter_1.StateOutputSetter()); }); } +restore(); exports.default = restore; @@ -50654,13 +50655,11 @@ function run(outputter) { return; } // Store the matched cache key in states - //utils.setCacheState(cacheKey); outputter.setState(constants_1.State.CacheMatchedKey, cacheKey); const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey); - //utils.setCacheHitOutput(isExactKeyMatch); outputter.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString()); core.info(`Cache restored from key: ${cacheKey}`); - return cacheKey; + return; } catch (error) { core.setFailed(error.message);