Skip to content

Commit eb5b03a

Browse files
committed
ci: avoid unnecessary builds
Whenever a branch is pushed to a repository which has GitHub Actions enabled, a bunch of new workflow runs are started. We sometimes see contributors push multiple branch updates in rapid succession, which in conjunction with the impressive time swallowed by even just a single CI build frequently leads to many queued-up runs. This is particularly problematic in the case of Pull Requests where a single contributor can easily (inadvertently) prevent timely builds for other contributors when using a shared repository. To help with this situation, let's use the `concurrency` feature of GitHub workflows, essentially canceling GitHub workflow runs that are obsoleted by more recent runs: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency For workflows that *do* want the behavior in the pre-image of this patch, they can use the ci-config feature to disable the new behavior by adding an executable script on the ci-config branch called 'skip-concurrent' which terminates with a non-zero exit code. Original-patch-by: Johannes Schindelin <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 3b08839 commit eb5b03a

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

.github/workflows/check-whitespace.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ on:
99
pull_request:
1010
types: [opened, synchronize]
1111

12+
# Avoid unnecessary builds. Unlike the main CI jobs, these are not
13+
# ci-configurable (but could be).
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
1218
jobs:
1319
check-whitespace:
1420
runs-on: ubuntu-latest

.github/workflows/l10n.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: git-l10n
22

33
on: [push, pull_request_target]
44

5+
# Avoid unnecessary builds. Unlike the main CI jobs, these are not
6+
# ci-configurable (but could be).
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
511
jobs:
612
git-po-helper:
713
if: >-

.github/workflows/main.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
outputs:
1313
enabled: ${{ steps.check-ref.outputs.enabled }}${{ steps.skip-if-redundant.outputs.enabled }}
14+
skip_concurrent: ${{ steps.check-ref.outputs.skip_concurrent }}
1415
steps:
1516
- name: try to clone ci-config branch
1617
run: |
@@ -34,7 +35,15 @@ jobs:
3435
then
3536
enabled=no
3637
fi
38+
39+
skip_concurrent=yes
40+
if test -x config-repo/ci/config/skip-concurrent &&
41+
! config-repo/ci/config/skip-concurrent '${{ github.ref }}'
42+
then
43+
skip_concurrent=no
44+
fi
3745
echo "::set-output name=enabled::$enabled"
46+
echo "::set-output name=skip_concurrent::$skip_concurrent"
3847
- name: skip if the commit or tree was already tested
3948
id: skip-if-redundant
4049
uses: actions/github-script@v3
@@ -82,6 +91,9 @@ jobs:
8291
needs: ci-config
8392
if: needs.ci-config.outputs.enabled == 'yes'
8493
runs-on: windows-latest
94+
concurrency:
95+
group: windows-build-${{ github.ref }}
96+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
8597
steps:
8698
- uses: actions/checkout@v2
8799
- uses: git-for-windows/setup-git-for-windows-sdk@v1
@@ -101,11 +113,14 @@ jobs:
101113
windows-test:
102114
name: win test
103115
runs-on: windows-latest
104-
needs: [windows-build]
116+
needs: [ci-config, windows-build]
105117
strategy:
106118
fail-fast: false
107119
matrix:
108120
nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
121+
concurrency:
122+
group: windows-test-${{ matrix.nr }}-${{ github.ref }}
123+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
109124
steps:
110125
- name: download tracked files and build artifacts
111126
uses: actions/download-artifact@v2
@@ -137,6 +152,9 @@ jobs:
137152
NO_PERL: 1
138153
GIT_CONFIG_PARAMETERS: "'user.name=CI' 'user.email=ci@git'"
139154
runs-on: windows-latest
155+
concurrency:
156+
group: vs-build-${{ github.ref }}
157+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
140158
steps:
141159
- uses: actions/checkout@v2
142160
- uses: git-for-windows/setup-git-for-windows-sdk@v1
@@ -184,11 +202,14 @@ jobs:
184202
vs-test:
185203
name: win+VS test
186204
runs-on: windows-latest
187-
needs: vs-build
205+
needs: [ci-config, vs-build]
188206
strategy:
189207
fail-fast: false
190208
matrix:
191209
nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
210+
concurrency:
211+
group: vs-test-${{ matrix.nr }}-${{ github.ref }}
212+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
192213
steps:
193214
- uses: git-for-windows/setup-git-for-windows-sdk@v1
194215
- name: download tracked files and build artifacts
@@ -218,6 +239,9 @@ jobs:
218239
name: ${{matrix.vector.jobname}} (${{matrix.vector.pool}})
219240
needs: ci-config
220241
if: needs.ci-config.outputs.enabled == 'yes'
242+
concurrency:
243+
group: ${{ matrix.vector.jobname }}-${{ matrix.vector.pool }}-${{ github.ref }}
244+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
221245
strategy:
222246
fail-fast: false
223247
matrix:
@@ -281,6 +305,9 @@ jobs:
281305
name: ${{matrix.vector.jobname}} (${{matrix.vector.image}})
282306
needs: ci-config
283307
if: needs.ci-config.outputs.enabled == 'yes'
308+
concurrency:
309+
group: dockerized-${{ matrix.vector.jobname }}-${{ matrix.vector.image }}-${{ github.ref }}
310+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
284311
strategy:
285312
fail-fast: false
286313
matrix:
@@ -316,6 +343,9 @@ jobs:
316343
env:
317344
jobname: StaticAnalysis
318345
runs-on: ubuntu-22.04
346+
concurrency:
347+
group: static-analysis-${{ github.ref }}
348+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
319349
steps:
320350
- uses: actions/checkout@v2
321351
- run: ci/install-dependencies.sh
@@ -327,6 +357,9 @@ jobs:
327357
env:
328358
jobname: sparse
329359
runs-on: ubuntu-20.04
360+
concurrency:
361+
group: sparse-${{ github.ref }}
362+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
330363
steps:
331364
- name: Download a current `sparse` package
332365
# Ubuntu's `sparse` version is too old for us
@@ -345,6 +378,9 @@ jobs:
345378
name: documentation
346379
needs: ci-config
347380
if: needs.ci-config.outputs.enabled == 'yes'
381+
concurrency:
382+
group: documentation-${{ github.ref }}
383+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
348384
env:
349385
jobname: Documentation
350386
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)