From 957293572578874c46cf758c89382f0ed90f1f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 17 May 2020 10:25:49 +0200 Subject: [PATCH] Fix: Remove event validation --- __tests__/actionUtils.test.ts | 22 +--------------------- __tests__/restore.test.ts | 23 +---------------------- __tests__/save.test.ts | 23 +---------------------- dist/restore/index.js | 12 ------------ dist/save/index.js | 11 ----------- src/constants.ts | 2 -- src/restore.ts | 10 ---------- src/save.ts | 9 --------- src/utils/actionUtils.ts | 7 ------- 9 files changed, 3 insertions(+), 116 deletions(-) diff --git a/__tests__/actionUtils.test.ts b/__tests__/actionUtils.test.ts index d6f9f88..7ab7806 100644 --- a/__tests__/actionUtils.test.ts +++ b/__tests__/actionUtils.test.ts @@ -4,7 +4,7 @@ import { promises as fs } from "fs"; import * as os from "os"; import * as path from "path"; -import { Events, Outputs, RefKey, State } from "../src/constants"; +import { Events, Outputs, State } from "../src/constants"; import { ArtifactCacheEntry } from "../src/contracts"; import * as actionUtils from "../src/utils/actionUtils"; @@ -19,7 +19,6 @@ function getTempDir(): string { afterEach(() => { delete process.env[Events.Key]; - delete process.env[RefKey]; }); afterAll(async () => { @@ -186,15 +185,6 @@ test("logWarning logs a message with a warning prefix", () => { expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`); }); -test("isValidEvent returns false for event that does not have a branch or tag", () => { - const event = "foo"; - process.env[Events.Key] = event; - - const isValidEvent = actionUtils.isValidEvent(); - - expect(isValidEvent).toBe(false); -}); - test("resolvePaths with no ~ in path", async () => { const filePath = ".cache"; @@ -326,16 +316,6 @@ test("resolvePaths exclusion pattern returns not found", async () => { } }); -test("isValidEvent returns true for event that has a ref", () => { - const event = Events.Push; - process.env[Events.Key] = event; - process.env[RefKey] = "ref/heads/feature"; - - const isValidEvent = actionUtils.isValidEvent(); - - expect(isValidEvent).toBe(true); -}); - test("unlinkFile unlinks file", async () => { const testDirectory = await fs.mkdtemp("unlinkFileTest"); const testFile = path.join(testDirectory, "test.txt"); diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index ff217ac..a0a95a4 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -6,8 +6,7 @@ import { CacheFilename, CompressionMethod, Events, - Inputs, - RefKey + Inputs } from "../src/constants"; import { ArtifactCacheEntry } from "../src/contracts"; import run from "../src/restore"; @@ -27,11 +26,6 @@ beforeAll(() => { } ); - jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => { - const actualUtils = jest.requireActual("../src/utils/actionUtils"); - return actualUtils.isValidEvent(); - }); - jest.spyOn(actionUtils, "getCacheFileName").mockImplementation(cm => { const actualUtils = jest.requireActual("../src/utils/actionUtils"); return actualUtils.getCacheFileName(cm); @@ -40,26 +34,11 @@ beforeAll(() => { beforeEach(() => { process.env[Events.Key] = Events.Push; - process.env[RefKey] = "refs/heads/feature-branch"; }); afterEach(() => { testUtils.clearInputs(); delete process.env[Events.Key]; - delete process.env[RefKey]; -}); - -test("restore with invalid event outputs warning", async () => { - const logWarningMock = jest.spyOn(actionUtils, "logWarning"); - const failedMock = jest.spyOn(core, "setFailed"); - const invalidEvent = "commit_comment"; - process.env[Events.Key] = invalidEvent; - delete process.env[RefKey]; - await run(); - expect(logWarningMock).toHaveBeenCalledWith( - `Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.` - ); - expect(failedMock).toHaveBeenCalledTimes(0); }); test("restore with no path should fail", async () => { diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts index 365a2fa..f2cb279 100644 --- a/__tests__/save.test.ts +++ b/__tests__/save.test.ts @@ -6,8 +6,7 @@ import { CacheFilename, CompressionMethod, Events, - Inputs, - RefKey + Inputs } from "../src/constants"; import { ArtifactCacheEntry } from "../src/contracts"; import run from "../src/save"; @@ -37,11 +36,6 @@ beforeAll(() => { } ); - jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => { - const actualUtils = jest.requireActual("../src/utils/actionUtils"); - return actualUtils.isValidEvent(); - }); - jest.spyOn(actionUtils, "resolvePaths").mockImplementation( async filePaths => { return filePaths.map(x => path.resolve(x)); @@ -60,26 +54,11 @@ beforeAll(() => { beforeEach(() => { process.env[Events.Key] = Events.Push; - process.env[RefKey] = "refs/heads/feature-branch"; }); afterEach(() => { testUtils.clearInputs(); delete process.env[Events.Key]; - delete process.env[RefKey]; -}); - -test("save with invalid event outputs warning", async () => { - const logWarningMock = jest.spyOn(actionUtils, "logWarning"); - const failedMock = jest.spyOn(core, "setFailed"); - const invalidEvent = "commit_comment"; - process.env[Events.Key] = invalidEvent; - delete process.env[RefKey]; - await run(); - expect(logWarningMock).toHaveBeenCalledWith( - `Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.` - ); - expect(failedMock).toHaveBeenCalledTimes(0); }); test("save with no primary key in state outputs warning", async () => { diff --git a/dist/restore/index.js b/dist/restore/index.js index 0ab3872..4d09ed6 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -3345,12 +3345,6 @@ function resolvePaths(patterns) { }); } exports.resolvePaths = resolvePaths; -// Cache token authorized for all events that are tied to a ref -// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context -function isValidEvent() { - return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); -} -exports.isValidEvent = isValidEvent; function unlinkFile(path) { return util.promisify(fs.unlink)(path); } @@ -4607,7 +4601,6 @@ var CompressionMethod; // over the socket during this period, the socket is destroyed and the download // is aborted. exports.SocketTimeout = 5000; -exports.RefKey = "GITHUB_REF"; /***/ }), @@ -4699,11 +4692,6 @@ function run() { var _a; return __awaiter(this, void 0, void 0, function* () { try { - // 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.`); - return; - } const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true }); core.saveState(constants_1.State.CacheKey, primaryKey); const restoreKeys = core diff --git a/dist/save/index.js b/dist/save/index.js index ec2df96..28cfebe 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -3345,12 +3345,6 @@ function resolvePaths(patterns) { }); } exports.resolvePaths = resolvePaths; -// Cache token authorized for all events that are tied to a ref -// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context -function isValidEvent() { - return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); -} -exports.isValidEvent = isValidEvent; function unlinkFile(path) { return util.promisify(fs.unlink)(path); } @@ -4597,10 +4591,6 @@ const utils = __importStar(__webpack_require__(443)); function run() { return __awaiter(this, void 0, void 0, function* () { try { - 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; - } const state = utils.getCacheState(); // Inputs are re-evaluted before the post action, so we want the original key used for restore const primaryKey = core.getState(constants_1.State.CacheKey); @@ -4694,7 +4684,6 @@ var CompressionMethod; // over the socket during this period, the socket is destroyed and the download // is aborted. exports.SocketTimeout = 5000; -exports.RefKey = "GITHUB_REF"; /***/ }), diff --git a/src/constants.ts b/src/constants.ts index 4eb5ef5..d1b1675 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -33,5 +33,3 @@ export enum CompressionMethod { // over the socket during this period, the socket is destroyed and the download // is aborted. export const SocketTimeout = 5000; - -export const RefKey = "GITHUB_REF"; diff --git a/src/restore.ts b/src/restore.ts index e2ed054..1afd16c 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -8,16 +8,6 @@ import * as utils from "./utils/actionUtils"; async function run(): Promise { try { - // Validate inputs, this can cause task failure - if (!utils.isValidEvent()) { - utils.logWarning( - `Event Validation Error: The event type ${ - process.env[Events.Key] - } is not supported because it's not tied to a branch or tag ref.` - ); - return; - } - const primaryKey = core.getInput(Inputs.Key, { required: true }); core.saveState(State.CacheKey, primaryKey); diff --git a/src/save.ts b/src/save.ts index 5776dff..4ad08af 100644 --- a/src/save.ts +++ b/src/save.ts @@ -8,15 +8,6 @@ import * as utils from "./utils/actionUtils"; async function run(): Promise { try { - if (!utils.isValidEvent()) { - utils.logWarning( - `Event Validation Error: The event type ${ - process.env[Events.Key] - } is not supported because it's not tied to a branch or tag ref.` - ); - return; - } - const state = utils.getCacheState(); // Inputs are re-evaluted before the post action, so we want the original key used for restore diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index 3b7a857..3d014fe 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -11,7 +11,6 @@ import { CacheFilename, CompressionMethod, Outputs, - RefKey, State } from "../constants"; import { ArtifactCacheEntry } from "../contracts"; @@ -108,12 +107,6 @@ export async function resolvePaths(patterns: string[]): Promise { return paths; } -// Cache token authorized for all events that are tied to a ref -// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context -export function isValidEvent(): boolean { - return RefKey in process.env && Boolean(process.env[RefKey]); -} - export function unlinkFile(path: fs.PathLike): Promise { return util.promisify(fs.unlink)(path); }