From 8bcf0245bb0a6eeba8df924a67367bb1dc52d714 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 17 Jan 2022 16:59:51 +0530 Subject: [PATCH] Removing GHES condition to enabled cache for GHES --- __tests__/actionUtils.test.ts | 18 ------------------ __tests__/restore.test.ts | 19 ------------------- __tests__/save.test.ts | 16 ---------------- dist/restore/index.js | 12 +----------- dist/save/index.js | 11 +---------- src/restore.ts | 8 -------- src/save.ts | 7 ------- src/utils/actionUtils.ts | 7 ------- 8 files changed, 2 insertions(+), 96 deletions(-) diff --git a/__tests__/actionUtils.test.ts b/__tests__/actionUtils.test.ts index 419881e..0dc5fa0 100644 --- a/__tests__/actionUtils.test.ts +++ b/__tests__/actionUtils.test.ts @@ -17,24 +17,6 @@ afterEach(() => { delete process.env[RefKey]; }); -test("isGhes returns true if server url is not github.com", () => { - try { - process.env["GITHUB_SERVER_URL"] = "http://example.com"; - expect(actionUtils.isGhes()).toBe(true); - } finally { - process.env["GITHUB_SERVER_URL"] = undefined; - } -}); - -test("isGhes returns true when server url is github.com", () => { - try { - process.env["GITHUB_SERVER_URL"] = "http://github.com"; - expect(actionUtils.isGhes()).toBe(false); - } finally { - process.env["GITHUB_SERVER_URL"] = undefined; - } -}); - test("isExactKeyMatch with undefined cache key returns false", () => { const key = "linux-rust"; const cacheKey = undefined; diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 4761782..8495021 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -32,8 +32,6 @@ beforeAll(() => { beforeEach(() => { process.env[Events.Key] = Events.Push; process.env[RefKey] = "refs/heads/feature-branch"; - - jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); }); afterEach(() => { @@ -55,23 +53,6 @@ test("restore with invalid event outputs warning", async () => { expect(failedMock).toHaveBeenCalledTimes(0); }); -test("restore on GHES should no-op", async () => { - jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); - - const logWarningMock = jest.spyOn(actionUtils, "logWarning"); - const restoreCacheMock = jest.spyOn(cache, "restoreCache"); - const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); - - await run(); - - expect(restoreCacheMock).toHaveBeenCalledTimes(0); - expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); - expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); - expect(logWarningMock).toHaveBeenCalledWith( - "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" - ); -}); - test("restore with no path should fail", async () => { const failedMock = jest.spyOn(core, "setFailed"); const restoreCacheMock = jest.spyOn(cache, "restoreCache"); diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts index 30178a2..d8ec1aa 100644 --- a/__tests__/save.test.ts +++ b/__tests__/save.test.ts @@ -52,8 +52,6 @@ beforeAll(() => { beforeEach(() => { process.env[Events.Key] = Events.Push; process.env[RefKey] = "refs/heads/feature-branch"; - - jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); }); afterEach(() => { @@ -101,20 +99,6 @@ test("save with no primary key in state outputs warning", async () => { expect(failedMock).toHaveBeenCalledTimes(0); }); -test("save on GHES should no-op", async () => { - jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); - - const logWarningMock = jest.spyOn(actionUtils, "logWarning"); - const saveCacheMock = jest.spyOn(cache, "saveCache"); - - await run(); - - expect(saveCacheMock).toHaveBeenCalledTimes(0); - expect(logWarningMock).toHaveBeenCalledWith( - "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" - ); -}); - test("save with exact match returns early", async () => { const infoMock = jest.spyOn(core, "info"); const failedMock = jest.spyOn(core, "setFailed"); diff --git a/dist/restore/index.js b/dist/restore/index.js index 671451c..a544189 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -36328,14 +36328,9 @@ 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.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; const core = __importStar(__webpack_require__(470)); 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"; -} -exports.isGhes = isGhes; function isExactKeyMatch(key, cacheKey) { return !!(cacheKey && cacheKey.localeCompare(key, undefined, { @@ -46719,11 +46714,6 @@ const utils = __importStar(__webpack_require__(443)); function run() { return __awaiter(this, void 0, void 0, function* () { try { - if (utils.isGhes()) { - utils.logWarning("Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"); - utils.setCacheHitOutput(false); - return; - } // Validate inputs, this can cause task failure if (!utils.isValidEvent()) { utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); diff --git a/dist/save/index.js b/dist/save/index.js index b0d491d..7ff701e 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -36328,14 +36328,9 @@ 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.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; const core = __importStar(__webpack_require__(470)); 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"; -} -exports.isGhes = isGhes; function isExactKeyMatch(key, cacheKey) { return !!(cacheKey && cacheKey.localeCompare(key, undefined, { @@ -44905,10 +44900,6 @@ process.on("uncaughtException", e => utils.logWarning(e.message)); function run() { return __awaiter(this, void 0, void 0, function* () { try { - if (utils.isGhes()) { - utils.logWarning("Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"); - return; - } if (!utils.isValidEvent()) { utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); return; diff --git a/src/restore.ts b/src/restore.ts index d411459..b1f8cca 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -6,14 +6,6 @@ import * as utils from "./utils/actionUtils"; async function run(): Promise { try { - if (utils.isGhes()) { - utils.logWarning( - "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" - ); - utils.setCacheHitOutput(false); - return; - } - // Validate inputs, this can cause task failure if (!utils.isValidEvent()) { utils.logWarning( diff --git a/src/save.ts b/src/save.ts index fc0eb73..2124012 100644 --- a/src/save.ts +++ b/src/save.ts @@ -11,13 +11,6 @@ process.on("uncaughtException", e => utils.logWarning(e.message)); async function run(): Promise { try { - if (utils.isGhes()) { - utils.logWarning( - "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" - ); - return; - } - if (!utils.isValidEvent()) { utils.logWarning( `Event Validation Error: The event type ${ diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index a4d712d..ee25a01 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -2,13 +2,6 @@ import * as core from "@actions/core"; import { Outputs, RefKey, State } from "../constants"; -export function isGhes(): boolean { - const ghUrl = new URL( - process.env["GITHUB_SERVER_URL"] || "https://github.com" - ); - return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; -} - export function isExactKeyMatch(key: string, cacheKey?: string): boolean { return !!( cacheKey &&