diff --git a/action.yml b/action.yml index b60e5860..f3c505bd 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,10 @@ inputs: workflow_id: description: 'Optional - A single Workflow ID or a comma separated list of IDs' required: false + ignore_sha: + description: 'Optional - Allow canceling other workflows with the same SHA. Useful for the `pull_request.closed` event.' + required: false + default: false access_token: description: 'Your GitHub Access Token, defaults to: {{ github.token }}' default: '${{ github.token }}' diff --git a/dist/index.js b/dist/index.js index 14693238..bb8a82ba 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5859,6 +5859,7 @@ async function main() { console.log({ eventName, sha, headSha, branch, owner, repo, GITHUB_RUN_ID }); const token = core.getInput('access_token', { required: true }); const workflow_id = core.getInput('workflow_id', { required: false }); + const ignore_sha = core.getInput('ignore_sha', { required: false }) === 'true'; console.log(`Found token: ${token ? 'yes' : 'no'}`); const workflow_ids = []; const octokit = github.getOctokit(token); @@ -5885,7 +5886,9 @@ async function main() { branch, }); console.log(`Found ${data.total_count} runs total.`); - const runningWorkflows = data.workflow_runs.filter(run => run.head_branch === branch && run.head_sha !== headSha && run.status !== 'completed' && + const runningWorkflows = data.workflow_runs.filter(run => run.head_branch === branch && + (ignore_sha || run.head_sha !== headSha) && + run.status !== 'completed' && new Date(run.created_at) < new Date(current_run.created_at)); console.log(`Found ${runningWorkflows.length} runs in progress.`); for (const { id, head_sha, status } of runningWorkflows) { diff --git a/src/index.ts b/src/index.ts index e7d9b8ee..b3f5740e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,7 @@ async function main() { console.log({ eventName, sha, headSha, branch, owner, repo, GITHUB_RUN_ID }); const token = core.getInput('access_token', { required: true }); const workflow_id = core.getInput('workflow_id', { required: false }); + const ignore_sha = core.getInput('ignore_sha', { required: false }) === 'true'; console.log(`Found token: ${token ? 'yes' : 'no'}`); const workflow_ids: string[] = []; const octokit = github.getOctokit(token); @@ -55,9 +56,11 @@ async function main() { branch, }); console.log(`Found ${data.total_count} runs total.`); - const runningWorkflows = data.workflow_runs.filter( - run => run.head_branch === branch && run.head_sha !== headSha && run.status !== 'completed' && - new Date(run.created_at) < new Date(current_run.created_at) + const runningWorkflows = data.workflow_runs.filter(run => + run.head_branch === branch && + (ignore_sha || run.head_sha !== headSha) && + run.status !== 'completed' && + new Date(run.created_at) < new Date(current_run.created_at) ); console.log(`Found ${runningWorkflows.length} runs in progress.`); for (const {id, head_sha, status} of runningWorkflows) {