Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ignore_branch flag to cancel workflows in all branches #207

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
```
Copy link
Owner

@styfle styfle May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move this new section below ### Advanced: SHA since I think it wont be a common use case.

Also lets call it ### Advanced: Ignore Branch



### 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
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -12,6 +12,10 @@ inputs:
description: 'Optional - Allow canceling other workflows with the same SHA. Useful for the `pull_request.closed` event.'
required: false
default: 'false'
ignore_branch:
description: 'Optional - Allow canceling workflows in all branches.'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: 'Optional - Allow canceling workflows in all branches.'
description: 'Optional - Allow canceling workflows, regardless of branch.'

required: false
default: 'false'
access_token:
description: 'Your GitHub Access Token, defaults to: {{ github.token }}'
default: ${{ github.token }}
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