From c29e204c9f00578a2e53a791a7bbb53a9c2e6540 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Thu, 24 Mar 2022 14:59:36 +0530 Subject: [PATCH] review comments and updated test cases --- __tests__/actionUtils.test.ts | 40 ++++++ __tests__/restore.test.ts | 14 +-- __tests__/save.test.ts | 14 +-- dist/restore/index.js | 222 +++++++++++---------------------- dist/save/index.js | 223 +++++++++++----------------------- src/restore.ts | 12 +- src/save.ts | 13 +- src/utils/actionUtils.ts | 19 +++ 8 files changed, 209 insertions(+), 348 deletions(-) diff --git a/__tests__/actionUtils.test.ts b/__tests__/actionUtils.test.ts index c220e71..08891a0 100644 --- a/__tests__/actionUtils.test.ts +++ b/__tests__/actionUtils.test.ts @@ -1,10 +1,12 @@ import * as core from "@actions/core"; +import * as cache from "@actions/cache"; import { Events, Outputs, RefKey, State } from "../src/constants"; import * as actionUtils from "../src/utils/actionUtils"; import * as testUtils from "../src/utils/testUtils"; jest.mock("@actions/core"); +jest.mock("@actions/cache"); beforeAll(() => { jest.spyOn(core, "getInput").mockImplementation((name, options) => { @@ -232,3 +234,41 @@ test("getInputAsInt throws if required and value missing", () => { actionUtils.getInputAsInt("undefined", { required: true }) ).toThrowError(); }); + +test("isCacheFeatureAvailable for ac enabled", () => { + jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true); + + expect(actionUtils.isCacheFeatureAvailable()).toBe(true); +}); + +test("isCacheFeatureAvailable for ac disabled on GHES", () => { + jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false); + + const message = "Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not."; + const infoMock = jest.spyOn(core, "info"); + + try { + process.env["GITHUB_SERVER_URL"] = "http://example.com"; + expect(actionUtils.isCacheFeatureAvailable()).toBe(false); + expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`); + } finally { + delete process.env["GITHUB_SERVER_URL"]; + } + +}); + +test("isCacheFeatureAvailable for ac disabled on dotcom", () => { + jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false); + + const message = "An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."; + const infoMock = jest.spyOn(core, "info"); + + try { + process.env["GITHUB_SERVER_URL"] = "http://github.com"; + expect(actionUtils.isCacheFeatureAvailable()).toBe(false); + expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`); + } finally { + delete process.env["GITHUB_SERVER_URL"]; + } + +}); \ No newline at end of file diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 71604b8..88d9a22 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -34,7 +34,7 @@ beforeEach(() => { process.env[RefKey] = "refs/heads/feature-branch"; jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); - jest.spyOn(cache, "isAvailable").mockImplementation(() => true); + jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(() => true); }); afterEach(() => { @@ -58,9 +58,8 @@ test("restore with invalid event outputs warning", async () => { test("restore without AC available should no-op", async () => { jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); - jest.spyOn(cache, "isAvailable").mockImplementation(() => false); + jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(() => false); - const logWarningMock = jest.spyOn(actionUtils, "logWarning"); const restoreCacheMock = jest.spyOn(cache, "restoreCache"); const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); @@ -69,16 +68,12 @@ test("restore without AC available should no-op", async () => { expect(restoreCacheMock).toHaveBeenCalledTimes(0); expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); - expect(logWarningMock).toHaveBeenCalledWith( - "Something is going wrong with ArtifactCache service which supports cache actions. Please check https://www.githubstatus.com/ for any ongoing issue in actions." - ); }); test("restore on GHES without AC available should no-op", async () => { jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); - jest.spyOn(cache, "isAvailable").mockImplementation(() => false); + jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(() => false); - const logWarningMock = jest.spyOn(actionUtils, "logWarning"); const restoreCacheMock = jest.spyOn(cache, "restoreCache"); const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); @@ -87,9 +82,6 @@ test("restore on GHES without AC available should no-op", async () => { expect(restoreCacheMock).toHaveBeenCalledTimes(0); expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); - expect(logWarningMock).toHaveBeenCalledWith( - "Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not." - ); }); test("restore on GHES with AC available ", async () => { diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts index bd0fdcb..aff9d50 100644 --- a/__tests__/save.test.ts +++ b/__tests__/save.test.ts @@ -54,7 +54,7 @@ beforeEach(() => { process.env[RefKey] = "refs/heads/feature-branch"; jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); - jest.spyOn(cache, "isAvailable").mockImplementation(() => true); + jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(() => true); }); afterEach(() => { @@ -103,32 +103,24 @@ test("save with no primary key in state outputs warning", async () => { }); test("save without AC available should no=op", async () => { - jest.spyOn(cache, "isAvailable").mockImplementation(() => false); + jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(() => false); - const logWarningMock = jest.spyOn(actionUtils, "logWarning"); const saveCacheMock = jest.spyOn(cache, "saveCache"); await run(); expect(saveCacheMock).toHaveBeenCalledTimes(0); - expect(logWarningMock).toHaveBeenCalledWith( - "Something is going wrong with ArtifactCache service which supports cache actions. Please check https://www.githubstatus.com/ for any ongoing issue in actions." - ); }); test("save on ghes without AC available should no=op", async () => { jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); - jest.spyOn(cache, "isAvailable").mockImplementation(() => false); + jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(() => false); - const logWarningMock = jest.spyOn(actionUtils, "logWarning"); const saveCacheMock = jest.spyOn(cache, "saveCache"); await run(); expect(saveCacheMock).toHaveBeenCalledTimes(0); - expect(logWarningMock).toHaveBeenCalledWith( - "Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not." - ); }); test("save on GHES with AC available", async () => { diff --git a/dist/restore/index.js b/dist/restore/index.js index b5be4d8..7aadcd0 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -1031,25 +1031,6 @@ class ExecState extends events.EventEmitter { "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -1066,8 +1047,14 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.assertDefined = exports.isGnuTarInstalled = exports.getCacheFileName = exports.getCompressionMethod = exports.unlinkFile = exports.resolvePaths = exports.getArchiveFileSizeInBytes = exports.createTempDirectory = void 0; const core = __importStar(__webpack_require__(470)); const exec = __importStar(__webpack_require__(986)); const glob = __importStar(__webpack_require__(281)); @@ -1212,6 +1199,13 @@ function assertDefined(name, value) { return value; } exports.assertDefined = assertDefined; +function isFeatureAvailable() { + if (process.env['ACTIONS_CACHE_URL']) { + return true; + } + return false; +} +exports.isFeatureAvailable = isFeatureAvailable; //# sourceMappingURL=cacheUtils.js.map /***/ }), @@ -3204,25 +3198,6 @@ exports.baggageEntryMetadataFromString = baggageEntryMetadataFromString; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -3232,8 +3207,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.saveCache = exports.reserveCache = exports.downloadCache = exports.getCacheEntry = exports.getCacheVersion = void 0; const core = __importStar(__webpack_require__(470)); const http_client_1 = __webpack_require__(539); const auth_1 = __webpack_require__(226); @@ -5338,25 +5319,6 @@ exports.default = _default; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -5366,8 +5328,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.downloadCacheStorageSDK = exports.downloadCacheHttpClient = exports.DownloadProgress = void 0; const core = __importStar(__webpack_require__(470)); const http_client_1 = __webpack_require__(539); const storage_blob_1 = __webpack_require__(373); @@ -37102,25 +37070,6 @@ function escapeProperty(s) { "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -37130,8 +37079,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.listTar = exports.createTar = exports.extractTar = void 0; const exec_1 = __webpack_require__(986); const io = __importStar(__webpack_require__(1)); const fs_1 = __webpack_require__(747); @@ -37508,9 +37463,10 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; +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 core = __importStar(__webpack_require__(470)); const constants_1 = __webpack_require__(196); +const cache = __importStar(__webpack_require__(692)); function isGhes() { const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; @@ -37573,6 +37529,19 @@ function getInputAsInt(name, options) { return value; } exports.getInputAsInt = getInputAsInt; +function isCacheFeatureAvailable() { + if (!cache.isFeatureAvailable()) { + if (isGhes()) { + logWarning("Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not."); + } + else { + logWarning("An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."); + } + return false; + } + return true; +} +exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /***/ }), @@ -40651,27 +40620,14 @@ exports.unregisterGlobal = unregisterGlobal; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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); + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getDownloadOptions = exports.getUploadOptions = void 0; const core = __importStar(__webpack_require__(470)); /** * Returns a copy of the upload options with defaults filled in. @@ -46449,25 +46405,6 @@ exports.default = _default; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -46477,8 +46414,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.saveCache = exports.restoreCache = exports.isAvailable = exports.ReserveCacheError = exports.ValidationError = void 0; const core = __importStar(__webpack_require__(470)); const path = __importStar(__webpack_require__(622)); const utils = __importStar(__webpack_require__(15)); @@ -46515,17 +46458,14 @@ function checkKey(key) { } } /** - * isAvailable to check the presence of Artifact cache service + * isFeatureAvailable to check the presence of Artifact cache service * * @returns boolean return true if Artifact cache service is available, otherwise false */ -function isAvailable() { - if (process.env['ACTIONS_CACHE_URL']) { - return true; - } - return false; +function isFeatureAvailable() { + return utils.isFeatureAvailable(); } -exports.isAvailable = isAvailable; +exports.isFeatureAvailable = isFeatureAvailable; /** * Restores cache from keys * @@ -48187,13 +48127,7 @@ const utils = __importStar(__webpack_require__(443)); function run() { return __awaiter(this, void 0, void 0, function* () { try { - if (!cache.isAvailable()) { - if (utils.isGhes()) { - utils.logWarning("Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not."); - } - else { - utils.logWarning("Something is going wrong with ArtifactCache service which supports cache actions. Please check https://www.githubstatus.com/ for any ongoing issue in actions."); - } + if (!utils.isCacheFeatureAvailable()) { utils.setCacheHitOutput(false); return; } @@ -51757,25 +51691,6 @@ module.exports = uuid; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -51785,8 +51700,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.retryHttpClientResponse = exports.retryTypedResponse = exports.retry = exports.isRetryableStatusCode = exports.isServerErrorStatusCode = exports.isSuccessStatusCode = void 0; const core = __importStar(__webpack_require__(470)); const http_client_1 = __webpack_require__(539); const constants_1 = __webpack_require__(931); @@ -52608,7 +52529,6 @@ exports.setLogLevel = setLogLevel; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.SocketTimeout = exports.DefaultRetryDelay = exports.DefaultRetryAttempts = exports.CompressionMethod = exports.CacheFilename = void 0; var CacheFilename; (function (CacheFilename) { CacheFilename["Gzip"] = "cache.tgz"; diff --git a/dist/save/index.js b/dist/save/index.js index 5d20346..d4ffb44 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -1031,25 +1031,6 @@ class ExecState extends events.EventEmitter { "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -1066,8 +1047,14 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.assertDefined = exports.isGnuTarInstalled = exports.getCacheFileName = exports.getCompressionMethod = exports.unlinkFile = exports.resolvePaths = exports.getArchiveFileSizeInBytes = exports.createTempDirectory = void 0; const core = __importStar(__webpack_require__(470)); const exec = __importStar(__webpack_require__(986)); const glob = __importStar(__webpack_require__(281)); @@ -1212,6 +1199,13 @@ function assertDefined(name, value) { return value; } exports.assertDefined = assertDefined; +function isFeatureAvailable() { + if (process.env['ACTIONS_CACHE_URL']) { + return true; + } + return false; +} +exports.isFeatureAvailable = isFeatureAvailable; //# sourceMappingURL=cacheUtils.js.map /***/ }), @@ -3204,25 +3198,6 @@ exports.baggageEntryMetadataFromString = baggageEntryMetadataFromString; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -3232,8 +3207,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.saveCache = exports.reserveCache = exports.downloadCache = exports.getCacheEntry = exports.getCacheVersion = void 0; const core = __importStar(__webpack_require__(470)); const http_client_1 = __webpack_require__(539); const auth_1 = __webpack_require__(226); @@ -5338,25 +5319,6 @@ exports.default = _default; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -5366,8 +5328,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.downloadCacheStorageSDK = exports.downloadCacheHttpClient = exports.DownloadProgress = void 0; const core = __importStar(__webpack_require__(470)); const http_client_1 = __webpack_require__(539); const storage_blob_1 = __webpack_require__(373); @@ -37102,25 +37070,6 @@ function escapeProperty(s) { "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -37130,8 +37079,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.listTar = exports.createTar = exports.extractTar = void 0; const exec_1 = __webpack_require__(986); const io = __importStar(__webpack_require__(1)); const fs_1 = __webpack_require__(747); @@ -37508,9 +37463,10 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; +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 core = __importStar(__webpack_require__(470)); const constants_1 = __webpack_require__(196); +const cache = __importStar(__webpack_require__(692)); function isGhes() { const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; @@ -37573,6 +37529,19 @@ function getInputAsInt(name, options) { return value; } exports.getInputAsInt = getInputAsInt; +function isCacheFeatureAvailable() { + if (!cache.isFeatureAvailable()) { + if (isGhes()) { + logWarning("Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not."); + } + else { + logWarning("An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."); + } + return false; + } + return true; +} +exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /***/ }), @@ -40651,27 +40620,14 @@ exports.unregisterGlobal = unregisterGlobal; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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); + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getDownloadOptions = exports.getUploadOptions = void 0; const core = __importStar(__webpack_require__(470)); /** * Returns a copy of the upload options with defaults filled in. @@ -46450,14 +46406,7 @@ process.on("uncaughtException", e => utils.logWarning(e.message)); function run() { return __awaiter(this, void 0, void 0, function* () { try { - if (!cache.isAvailable()) { - if (utils.isGhes()) { - utils.logWarning("Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not."); - } - else { - utils.logWarning("Something is going wrong with ArtifactCache service which supports cache actions. Please check https://www.githubstatus.com/ for any ongoing issue in actions."); - } - utils.setCacheHitOutput(false); + if (!utils.isCacheFeatureAvailable()) { return; } if (!utils.isValidEvent()) { @@ -46549,25 +46498,6 @@ exports.default = run; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -46577,8 +46507,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.saveCache = exports.restoreCache = exports.isAvailable = exports.ReserveCacheError = exports.ValidationError = void 0; const core = __importStar(__webpack_require__(470)); const path = __importStar(__webpack_require__(622)); const utils = __importStar(__webpack_require__(15)); @@ -46615,17 +46551,14 @@ function checkKey(key) { } } /** - * isAvailable to check the presence of Artifact cache service + * isFeatureAvailable to check the presence of Artifact cache service * * @returns boolean return true if Artifact cache service is available, otherwise false */ -function isAvailable() { - if (process.env['ACTIONS_CACHE_URL']) { - return true; - } - return false; +function isFeatureAvailable() { + return utils.isFeatureAvailable(); } -exports.isAvailable = isAvailable; +exports.isFeatureAvailable = isFeatureAvailable; /** * Restores cache from keys * @@ -51761,25 +51694,6 @@ module.exports = uuid; "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (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) { @@ -51789,8 +51703,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -exports.retryHttpClientResponse = exports.retryTypedResponse = exports.retry = exports.isRetryableStatusCode = exports.isServerErrorStatusCode = exports.isSuccessStatusCode = void 0; const core = __importStar(__webpack_require__(470)); const http_client_1 = __webpack_require__(539); const constants_1 = __webpack_require__(931); @@ -52612,7 +52532,6 @@ exports.setLogLevel = setLogLevel; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.SocketTimeout = exports.DefaultRetryDelay = exports.DefaultRetryAttempts = exports.CompressionMethod = exports.CacheFilename = void 0; var CacheFilename; (function (CacheFilename) { CacheFilename["Gzip"] = "cache.tgz"; diff --git a/src/restore.ts b/src/restore.ts index 7a51e0b..df3dcac 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -6,17 +6,7 @@ import * as utils from "./utils/actionUtils"; async function run(): Promise { try { - if (!cache.isAvailable()) { - if (utils.isGhes()){ - utils.logWarning( - "Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not." - ); - } - else{ - utils.logWarning( - "Something is going wrong with ArtifactCache service which supports cache actions. Please check https://www.githubstatus.com/ for any ongoing issue in actions." - ); - } + if (!utils.isCacheFeatureAvailable()) { utils.setCacheHitOutput(false); return; } diff --git a/src/save.ts b/src/save.ts index 30ea834..40a1079 100644 --- a/src/save.ts +++ b/src/save.ts @@ -11,18 +11,7 @@ process.on("uncaughtException", e => utils.logWarning(e.message)); async function run(): Promise { try { - if (!cache.isAvailable()) { - if (utils.isGhes()){ - utils.logWarning( - "Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not." - ); - } - else{ - utils.logWarning( - "Something is going wrong with ArtifactCache service which supports cache actions. Please check https://www.githubstatus.com/ for any ongoing issue in actions." - ); - } - utils.setCacheHitOutput(false); + if (!utils.isCacheFeatureAvailable()) { return; } diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index a4d712d..b4af351 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -1,6 +1,7 @@ import * as core from "@actions/core"; import { Outputs, RefKey, State } from "../constants"; +import * as cache from "@actions/cache"; export function isGhes(): boolean { const ghUrl = new URL( @@ -74,3 +75,21 @@ export function getInputAsInt( } return value; } + +export function isCacheFeatureAvailable(): boolean { + if (!cache.isFeatureAvailable()) { + if (isGhes()){ + logWarning( + "Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not." + ); + } + else{ + logWarning( + "An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions." + ); + } + return false; + } + + return true; +} \ No newline at end of file