From b8076051474d234b9bf70d23464609b88d271060 Mon Sep 17 00:00:00 2001 From: Pascal Jufer Date: Thu, 22 Sep 2022 17:00:27 +0200 Subject: [PATCH] Allow `release` for `do_not_skip` input (#273) * Allow 'release' as option for 'do_not_skip' input * Small optimizations * Use meaningful variable ('file' vs. 'f') * Remove unnecessary default values for boolean inputs * Directly return commit response (remove 'res' variable) --- README.md | 2 +- dist/index.js | 18 ++++++++++-------- src/main.ts | 25 +++++++++++++++---------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index fe31f33..3c71c6a 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ If true, skip if an already finished duplicate run can be found. A JSON-array with triggers that should never be skipped. -Possible values are `pull_request`, `push`, `workflow_dispatch`, `schedule`. +Possible values are `pull_request`, `push`, `workflow_dispatch`, `schedule`, `release`. **Default:** `'["workflow_dispatch", "schedule"]'` diff --git a/dist/index.js b/dist/index.js index 6869d29..08cc47a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -50,7 +50,8 @@ const workflowRunTriggerOptions = [ 'pull_request', 'push', 'workflow_dispatch', - 'schedule' + 'schedule', + 'release' ]; const concurrentSkippingOptions = [ 'always', @@ -221,7 +222,9 @@ class SkipDuplicateActions { } iterSha = ((_a = commit.parents) === null || _a === void 0 ? void 0 : _a.length) ? (_b = commit.parents[0]) === null || _b === void 0 ? void 0 : _b.sha : null; const changedFiles = commit.files - ? commit.files.map(f => f.filename).filter(f => typeof f === 'string') + ? commit.files + .map(file => file.filename) + .filter(file => typeof file === 'string') : []; allChangedFiles.push(changedFiles); const successfulRun = (distanceToHEAD >= 1 && @@ -294,8 +297,7 @@ class SkipDuplicateActions { return null; } try { - const res = yield this.context.octokit.rest.repos.getCommit(Object.assign(Object.assign({}, this.context.repo), { ref: sha })); - return res.data; + return (yield this.context.octokit.rest.repos.getCommit(Object.assign(Object.assign({}, this.context.repo), { ref: sha }))).data; } catch (error) { if (error instanceof Error || typeof error === 'string') { @@ -308,7 +310,7 @@ class SkipDuplicateActions { } } function main() { - var _a, _b, _c; + var _a; return __awaiter(this, void 0, void 0, function* () { // Get and validate inputs. const token = core.getInput('github_token', { required: true }); @@ -318,14 +320,14 @@ function main() { pathsFilter: getPathsFilterInput('paths_filter'), doNotSkip: getDoNotSkipInput('do_not_skip'), concurrentSkipping: getConcurrentSkippingInput('concurrent_skipping'), - cancelOthers: (_a = core.getBooleanInput('cancel_others')) !== null && _a !== void 0 ? _a : false, - skipAfterSuccessfulDuplicates: (_b = core.getBooleanInput('skip_after_successful_duplicate')) !== null && _b !== void 0 ? _b : true + cancelOthers: core.getBooleanInput('cancel_others'), + skipAfterSuccessfulDuplicates: core.getBooleanInput('skip_after_successful_duplicate') }; const repo = github.context.repo; const octokit = github.getOctokit(token); // Get and parse the current workflow run. const { data: apiCurrentRun } = yield octokit.rest.actions.getWorkflowRun(Object.assign(Object.assign({}, repo), { run_id: github.context.runId })); - const currentTreeHash = (_c = apiCurrentRun.head_commit) === null || _c === void 0 ? void 0 : _c.tree_id; + const currentTreeHash = (_a = apiCurrentRun.head_commit) === null || _a === void 0 ? void 0 : _a.tree_id; if (!currentTreeHash) { exitFail(` Could not find the tree hash of run ${apiCurrentRun.id} (Workflow ID: ${apiCurrentRun.workflow_id}, diff --git a/src/main.ts b/src/main.ts index edbf912..e6602c5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,7 +16,8 @@ const workflowRunTriggerOptions = [ 'pull_request', 'push', 'workflow_dispatch', - 'schedule' + 'schedule', + 'release' ] as const type WorkflowRunTrigger = typeof workflowRunTriggerOptions[number] @@ -305,7 +306,9 @@ class SkipDuplicateActions { } iterSha = commit.parents?.length ? commit.parents[0]?.sha : null const changedFiles = commit.files - ? commit.files.map(f => f.filename).filter(f => typeof f === 'string') + ? commit.files + .map(file => file.filename) + .filter(file => typeof file === 'string') : [] allChangedFiles.push(changedFiles) @@ -417,11 +420,12 @@ class SkipDuplicateActions { return null } try { - const res = await this.context.octokit.rest.repos.getCommit({ - ...this.context.repo, - ref: sha - }) - return res.data + return ( + await this.context.octokit.rest.repos.getCommit({ + ...this.context.repo, + ref: sha + }) + ).data } catch (error) { if (error instanceof Error || typeof error === 'string') { core.warning(error) @@ -441,9 +445,10 @@ async function main(): Promise { pathsFilter: getPathsFilterInput('paths_filter'), doNotSkip: getDoNotSkipInput('do_not_skip'), concurrentSkipping: getConcurrentSkippingInput('concurrent_skipping'), - cancelOthers: core.getBooleanInput('cancel_others') ?? false, - skipAfterSuccessfulDuplicates: - core.getBooleanInput('skip_after_successful_duplicate') ?? true + cancelOthers: core.getBooleanInput('cancel_others'), + skipAfterSuccessfulDuplicates: core.getBooleanInput( + 'skip_after_successful_duplicate' + ) } const repo = github.context.repo