diff --git a/README.md b/README.md index bf405efc..40c7ef3c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/action.yml b/action.yml index 54af1d4d..1e812b67 100644 --- a/action.yml +++ b/action.yml @@ -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.' + 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 853fcd71..4c2673fc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 = []; @@ -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); diff --git a/src/index.ts b/src/index.ts index 93d04dbc..7a1e0d33 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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[] = []; @@ -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);