Skip to content

Commit

Permalink
feat: add ignore_branch flag to cancel workflows in all branches
Browse files Browse the repository at this point in the history
Fixes styfle#86
  • Loading branch information
mpontus committed May 24, 2023
1 parent 034d0e9 commit f333d21
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -54,6 +54,25 @@ Visit [Releases](https://github.com/styfle/cancel-workflow-action/releases) to f
>
> 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.
### Advanced: Canceling Workflows for Other Branches

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.

```yml
name: Cancel
on: [push]
jobs:
test:
name: 'Cancel Previous Runs'
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: styfle/cancel-workflow-action
with:
ignore_branch: true
```


### Advanced: Canceling Other Workflows

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.
Expand Down
3 changes: 2 additions & 1 deletion dist/index.js
Expand Up @@ -9705,6 +9705,7 @@ async function main() {
const token = core.getInput('access_token');
const workflow_id = core.getInput('workflow_id', { required: false });
const ignore_sha = core.getBooleanInput('ignore_sha', { required: false });
const ignore_branch = core.getBooleanInput('ignore_branch', { required: false });
const all_but_latest = core.getBooleanInput('all_but_latest', { required: false });
console.log(`Found token: ${token ? 'yes' : 'no'}`);
const workflow_ids = [];
Expand Down Expand Up @@ -9738,7 +9739,7 @@ async function main() {
owner,
repo,
workflow_id,
branch,
branch: ignore_branch ? undefined : branch,
});
console.log(`Found ${total_count} runs total.`);
let cancelBefore = new Date(current_run.created_at);
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Expand Up @@ -33,6 +33,7 @@ async function main() {
const token = core.getInput('access_token');
const workflow_id = core.getInput('workflow_id', { required: false });
const ignore_sha = core.getBooleanInput('ignore_sha', { required: false });
const ignore_branch = core.getBooleanInput('ignore_branch', { required: false });
const all_but_latest = core.getBooleanInput('all_but_latest', { required: false });
console.log(`Found token: ${token ? 'yes' : 'no'}`);
const workflow_ids: string[] = [];
Expand Down Expand Up @@ -75,7 +76,7 @@ async function main() {
repo,
// @ts-ignore
workflow_id,
branch,
branch: ignore_branch ? undefined : branch,
});
console.log(`Found ${total_count} runs total.`);
let cancelBefore = new Date(current_run.created_at);
Expand Down

0 comments on commit f333d21

Please sign in to comment.