diff --git a/README.md b/README.md index 417047c..be42df3 100644 --- a/README.md +++ b/README.md @@ -135,9 +135,9 @@ 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`, `release`. +Possible values are `pull_request`, `push`, `workflow_dispatch`, `schedule`, `release`, `merge_group`. -**Default:** `'["workflow_dispatch", "schedule"]'` +**Default:** `'["workflow_dispatch", "schedule", "merge_group"]'` ### `concurrent_skipping` @@ -235,6 +235,7 @@ To minimize changes to existing jobs, it is often easier to skip entire jobs. > > - You may need to use [`fromJSON`](https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson) to access properties of object outputs. For example, for `skipped_by.id`, you can use the expression: `${{ fromJSON(steps.skip_check.outputs.skipped_by).id }}`. > - For GitHub repositories where [default permissions](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#setting-the-permissions-of-the-github_token-for-your-repository) for `GITHUB_TOKEN` has been set to "permissive (read-only)", the following lines must be included in the workflow (see [permissions syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions)): +> > ```yaml > # Minimum permissions required by skip-duplicate-actions > permissions: @@ -408,14 +409,15 @@ stateDiagram-v2 ### How to Use Skip Check With Required Matrix Jobs? -Discussed in https://github.com/fkirc/skip-duplicate-actions/issues/44. +Discussed in . If you have matrix jobs that are registered as required status checks and the matrix runs conditionally based on the skip check, you might run into the problem that the pull request remains in a unmergable state forever because the jobs are not executed at all and thus not reported as skipped (`Expected - Waiting for status to be reported`). There are several approaches to circumvent this problem: -- Define the condition (`if`) in each step in the matrix job instead of a single condition on the job level: https://github.com/fkirc/skip-duplicate-actions/issues/44 +- Define the condition (`if`) in each step in the matrix job instead of a single condition on the job level: - If you want the check to be considered successful only if all jobs in the matrix were successful, you can add a subsequent job whose only task is to report the final status of the matrix. Then you can register this final job as a required status check: + ```yaml result: name: Result @@ -429,6 +431,7 @@ There are several approaches to circumvent this problem: if: needs.example-matrix-job.result != 'success' run: exit 1 ``` + - Define an opposite workflow, as offically suggested by GitHub: [Handling skipped but required checks](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks) ## Maintainers diff --git a/action.yml b/action.yml index 8b5342b..2adc895 100644 --- a/action.yml +++ b/action.yml @@ -31,7 +31,7 @@ inputs: do_not_skip: description: 'A JSON-array with triggers that should never be skipped' required: false - default: '["workflow_dispatch", "schedule"]' + default: '["workflow_dispatch", "schedule", "merge_group"]' concurrent_skipping: description: 'One of never, same_content, same_content_newer, outdated_runs, always' required: true @@ -48,5 +48,5 @@ outputs: paths_result: description: 'Returns information for each configured filter in paths_filter' runs: - using: 'node16' + using: 'node20' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index f8a26f3..b972596 100644 --- a/dist/index.js +++ b/dist/index.js @@ -55,7 +55,8 @@ const workflowRunTriggerOptions = [ 'push', 'workflow_dispatch', 'schedule', - 'release' + 'release', + 'merge_group' ]; const concurrentSkippingOptions = [ 'always', @@ -334,7 +335,18 @@ function main() { const repo = github.context.repo; const octokit = new Octokit((0, utils_1.getOctokitOptions)(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 })); + let apiCurrentRun = null; + try { + const res = yield octokit.rest.actions.getWorkflowRun(Object.assign(Object.assign({}, repo), { run_id: github.context.runId })); + apiCurrentRun = res.data; + } + catch (error) { + core.warning(error); + yield exitSuccess({ + shouldSkip: false, + reason: 'no_transferable_run' + }); + } const currentTreeHash = (_a = apiCurrentRun.head_commit) === null || _a === void 0 ? void 0 : _a.tree_id; if (!currentTreeHash) { exitFail(` diff --git a/src/main.ts b/src/main.ts index 835df57..1d4509b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,8 @@ const workflowRunTriggerOptions = [ 'push', 'workflow_dispatch', 'schedule', - 'release' + 'release', + 'merge_group' ] as const type WorkflowRunTrigger = typeof workflowRunTriggerOptions[number] @@ -465,10 +466,20 @@ async function main(): Promise { const octokit = new Octokit(getOctokitOptions(token)) // Get and parse the current workflow run. - const {data: apiCurrentRun} = await octokit.rest.actions.getWorkflowRun({ - ...repo, - run_id: github.context.runId - }) + let apiCurrentRun: ApiWorkflowRun = null as unknown as ApiWorkflowRun + try { + const res = await octokit.rest.actions.getWorkflowRun({ + ...repo, + run_id: github.context.runId + }) + apiCurrentRun = res.data + } catch (error) { + core.warning(error as string | Error) + await exitSuccess({ + shouldSkip: false, + reason: 'no_transferable_run' + }) + } const currentTreeHash = apiCurrentRun.head_commit?.tree_id if (!currentTreeHash) { exitFail(`