Skip to content

Commit b36f29a

Browse files
jrfnlgrogy
authored andcommitted
GH Actions: auto-cancel previous builds for same branch
Previously, in Travis, when the same branch was pushed again and the "Auto cancellation" option on the "Settings" page had been turned on (as it was for most repos), any still running builds for the same branch would be stopped in favour of starting the build for the newly pushed version of the branch. To enable this behaviour in GH Actions, a `concurrency` configuration needs to be added to each workflow for which this should applied to. More than anything, this is a way to be kind to GitHub by not wasting resources which they so kindly provide to us for free. Refs: * https://github.blog/changelog/2021-04-19-github-actions-limit-workflow-run-or-job-concurrency/ * https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#concurrency
1 parent c991e1e commit b36f29a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

.github/workflows/cs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ on:
66
# Allow manually triggering the workflow.
77
workflow_dispatch:
88

9+
# Cancels all previous workflow runs for the same branch that have not yet completed.
10+
concurrency:
11+
# The concurrency group contains the workflow name and the branch name.
12+
group: ${{ github.workflow }}-${{ github.head_ref }}
13+
cancel-in-progress: true
14+
915
jobs:
1016
checkcs:
1117
name: 'Check code style'

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ on:
66
# Allow manually triggering the workflow.
77
workflow_dispatch:
88

9+
# Cancels all previous workflow runs for the same branch that have not yet completed.
10+
concurrency:
11+
# The concurrency group contains the workflow name and the branch name.
12+
group: ${{ github.workflow }}-${{ github.head_ref }}
13+
cancel-in-progress: true
14+
915
jobs:
1016
test:
1117
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)