Skip to content

Commit 25a55b2

Browse files
committed
feat: add ignore_branch flag to cancel workflows in all branches
Fixes #86
1 parent 034d0e9 commit 25a55b2

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ Visit [Releases](https://github.com/styfle/cancel-workflow-action/releases) to f
5454
>
5555
> You might run into "the `uses' attribute must be a path, a Docker image, or owner/repo@ref" error if you don't specify a version.
5656

57+
### Advanced: Canceling Workflows for Other Branches
58+
59+
By default, this action cancels workflows running in the same branch as itself. The `ignore_branch` flag allows to ignore the branch name when selecting workflows to cancel.
60+
61+
```yml
62+
name: Cancel
63+
on: [push]
64+
jobs:
65+
test:
66+
name: 'Cancel Previous Runs'
67+
runs-on: ubuntu-latest
68+
timeout-minutes: 3
69+
steps:
70+
- uses: styfle/cancel-workflow-action
71+
with:
72+
ignore_branch: true
73+
```
74+
75+
5776
### Advanced: Canceling Other Workflows
5877

5978
In some cases, you may wish to avoid modifying all your workflows and instead create a new workflow that cancels your other workflows. This can be useful when you have a problem with workflows getting queued.

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
description: 'Optional - Allow canceling other workflows with the same SHA. Useful for the `pull_request.closed` event.'
1313
required: false
1414
default: 'false'
15+
ignore_branch:
16+
description: 'Optional - Allow canceling workflows in all branches.'
17+
required: false
18+
default: 'false'
1519
access_token:
1620
description: 'Your GitHub Access Token, defaults to: {{ github.token }}'
1721
default: ${{ github.token }}

dist/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9705,6 +9705,7 @@ async function main() {
97059705
const token = core.getInput('access_token');
97069706
const workflow_id = core.getInput('workflow_id', { required: false });
97079707
const ignore_sha = core.getBooleanInput('ignore_sha', { required: false });
9708+
const ignore_branch = core.getBooleanInput('ignore_branch', { required: false });
97089709
const all_but_latest = core.getBooleanInput('all_but_latest', { required: false });
97099710
console.log(`Found token: ${token ? 'yes' : 'no'}`);
97109711
const workflow_ids = [];
@@ -9738,7 +9739,7 @@ async function main() {
97389739
owner,
97399740
repo,
97409741
workflow_id,
9741-
branch,
9742+
branch: ignore_branch ? undefined : branch,
97429743
});
97439744
console.log(`Found ${total_count} runs total.`);
97449745
let cancelBefore = new Date(current_run.created_at);

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ async function main() {
3333
const token = core.getInput('access_token');
3434
const workflow_id = core.getInput('workflow_id', { required: false });
3535
const ignore_sha = core.getBooleanInput('ignore_sha', { required: false });
36+
const ignore_branch = core.getBooleanInput('ignore_branch', { required: false });
3637
const all_but_latest = core.getBooleanInput('all_but_latest', { required: false });
3738
console.log(`Found token: ${token ? 'yes' : 'no'}`);
3839
const workflow_ids: string[] = [];
@@ -75,7 +76,7 @@ async function main() {
7576
repo,
7677
// @ts-ignore
7778
workflow_id,
78-
branch,
79+
branch: ignore_branch ? undefined : branch,
7980
});
8081
console.log(`Found ${total_count} runs total.`);
8182
let cancelBefore = new Date(current_run.created_at);

0 commit comments

Comments
 (0)