Releases: n1hility/cancel-previous-runs
v3.0
cancel-previous-runs
This action cancels previous runs for one or more branches/prs associated with a workflow, effectively limiting the resource consumption of the workflow to one per branch.
Usage
The easiest and most complete approach to utilize this action, is to create a separate schedule event triggered workflow, which is directed at the workflow you wish to clear duplicate runs. At each cron interval all branches and all PRs executing for either push or pull_request events will be processed and limited to one run per branch/pr.
Additionally this action can be placed as an early step in your workflow (e.g. after checkout), so that it can abort the other previously running jobs immediately, in case most resources are tied up. Unfortunately this approach is a no-op when a pull request uses a fork for a source branch. This is because the GITHUB_TOKEN provided to runs with a fork source branch specifies reed-only permissions for security reasons. write permissions are required to be able to cancel a job. Therefore, it's a good idea to only rely on this approach as a fallback in-addition to the previously described scheduling model.
Inputs
token - The github token passed from ${{ secrets.GITHUB_TOKEN }}
. Since workflow files are visible in the repository, DO NOT HARDCODE A TOKEN ONLY USE A REFERENCE.
workflow - The filename of the workflow to limit runs on (only applies to schedule events)
Schedule Example
name: Cleanup Duplicate Branches and PRs
on:
schedule:
- cron: '*/15 * * * *'
cancel-runs:
# Prevent forks from running this to be nice
if: github.repository == 'foo-org/my-repo'
runs-on: ubuntu-latest
steps:
- uses: n1hility/cancel-previous-runs@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
workflow: my-heavy-workflow.yml
Alternate/Fallback Example
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: n1hility/cancel-previous-runs@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
License
The scripts and documentation in this project are released under the MIT License
2.0
cancel-previous-runs
[BETA] This action cancels previous runs for one or more branches/prs associated with a workflow, effectively limiting the resource consumption of the workflow to one per branch.
Usage
The easiest and most complete approach to utilize this action, is to create a separate schedule event triggered workflow, which is directed at the workflow you wish to clear duplicate runs. At each cron interrval all branches and all PRs executing for either push or pull_request events will be processed and limited to one run per branch/pr.
Additionally this action can be placed as an early step in your workflow (e.g. after checkout), so that it can abort the other previously running jobs immediately, in case most resources are tied up. Unfortunately this approach is a no-op when a pull request uses a fork for a source branch. This is because the GITHUB_TOKEN provided to runs with a fork source branch specifies reed-only permissions for security reasons. write permissions are required to be able to cancel a job. Therefore, it's a good idea to only rely on this approach as a fallback in-addition to the previously described scheduling model.
Inputs
token - The github token passed from ${{ secrets.GITHUB_TOKEN }}
. Since workflow files are visible in the repository, DO NOT HARDCODE A TOKEN ONLY USE A REFERENCE.
workflow - The filename of the workflow to limit runs on (only applies to schedule events)
Schedule Example
name: Cleanup Duplicate Branches and PRs
on:
schedule:
- cron: '*/15 * * * *'
cancel-runs:
# Prevent forks from running this to be nice
if: github.repository == 'foo-org/my-repo'
runs-on: ubuntu-latest
steps:
- uses: n1hility/cancel-previous-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
workflow: my-heavy-workflow.yml
Alternate/Fallback Example
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: n1hility/cancel-previous-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
License
The scripts and documentation in this project are released under the MIT License
Cancel Previous Workflow Runs
cancel-previous-runs
[BETA] This action cancels all previous runs on the same branch, effectively limiting the resource consumption of the workflow using this action to one run per branch.
Usage
This action should be placed as an early step in your workflow (e.g. after chekout), so that it can abort the other running jobs before consuming additional capacity. Additionally, it requires that the running Github Action token (located in the secrets context) be passed as an input parameter so that it can list and cancel workflow runs associated with the workflow's repository.
Inputs
token - The github token passed from ${{ secrets.GITHUB_TOKEN }}
. Since workflow files are visible in the repository, DO NOT HARDODE A TOKEN ONLY USE A REFERENCE.
Example
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: n1hility/cancel-previous-runs@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
License
The scripts and documentation in this project are released under the MIT License