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 <Johannes.Schindelin@gmx.de> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Taylor Blau committed Nov 8, 2022 at 13:25 UTC eb5b03a9c0a0c8b4d82ece6069821de41b06722b
3 files changed +50 -2
.github/workflows/check-whitespace.yml
+6
@@ -9,6 +9,12 @@ on:
9 pull_request:
10 types: [opened, synchronize]
11
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 +
18 jobs:
19 check-whitespace:
20 runs-on: ubuntu-latest
.github/workflows/l10n.yml
+6
@@ -2,6 +2,12 @@ name: git-l10n
2
3 on: [push, pull_request_target]
4
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 +
11 jobs:
12 git-po-helper:
13 if: >-
.github/workflows/main.yml
+38 -2
@@ -11,6 +11,7 @@ jobs:
11 runs-on: ubuntu-latest
12 outputs:
13 enabled: ${{ steps.check-ref.outputs.enabled }}${{ steps.skip-if-redundant.outputs.enabled }}
14 + skip_concurrent: ${{ steps.check-ref.outputs.skip_concurrent }}
15 steps:
16 - name: try to clone ci-config branch
17 run: |
@@ -34,7 +35,15 @@ jobs:
35 then
36 enabled=no
37 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
45 echo "::set-output name=enabled::$enabled"
46 + echo "::set-output name=skip_concurrent::$skip_concurrent"
47 - name: skip if the commit or tree was already tested
48 id: skip-if-redundant
49 uses: actions/github-script@v3
@@ -82,6 +91,9 @@ jobs:
91 needs: ci-config
92 if: needs.ci-config.outputs.enabled == 'yes'
93 runs-on: windows-latest
94 + concurrency:
95 + group: windows-build-${{ github.ref }}
96 + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
97 steps:
98 - uses: actions/checkout@v2
99 - uses: git-for-windows/setup-git-for-windows-sdk@v1
@@ -101,11 +113,14 @@ jobs:
113 windows-test:
114 name: win test
115 runs-on: windows-latest
104 - needs: [windows-build]
116 + needs: [ci-config, windows-build]
117 strategy:
118 fail-fast: false
119 matrix:
120 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' }}
124 steps:
125 - name: download tracked files and build artifacts
126 uses: actions/download-artifact@v2
@@ -137,6 +152,9 @@ jobs:
152 NO_PERL: 1
153 GIT_CONFIG_PARAMETERS: "'user.name=CI' 'user.email=ci@git'"
154 runs-on: windows-latest
155 + concurrency:
156 + group: vs-build-${{ github.ref }}
157 + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
158 steps:
159 - uses: actions/checkout@v2
160 - uses: git-for-windows/setup-git-for-windows-sdk@v1
@@ -184,11 +202,14 @@ jobs:
202 vs-test:
203 name: win+VS test
204 runs-on: windows-latest
187 - needs: vs-build
205 + needs: [ci-config, vs-build]
206 strategy:
207 fail-fast: false
208 matrix:
209 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' }}
213 steps:
214 - uses: git-for-windows/setup-git-for-windows-sdk@v1
215 - name: download tracked files and build artifacts
@@ -218,6 +239,9 @@ jobs:
239 name: ${{matrix.vector.jobname}} (${{matrix.vector.pool}})
240 needs: ci-config
241 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' }}
245 strategy:
246 fail-fast: false
247 matrix:
@@ -281,6 +305,9 @@ jobs:
305 name: ${{matrix.vector.jobname}} (${{matrix.vector.image}})
306 needs: ci-config
307 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' }}
311 strategy:
312 fail-fast: false
313 matrix:
@@ -316,6 +343,9 @@ jobs:
343 env:
344 jobname: StaticAnalysis
345 runs-on: ubuntu-22.04
346 + concurrency:
347 + group: static-analysis-${{ github.ref }}
348 + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
349 steps:
350 - uses: actions/checkout@v2
351 - run: ci/install-dependencies.sh
@@ -327,6 +357,9 @@ jobs:
357 env:
358 jobname: sparse
359 runs-on: ubuntu-20.04
360 + concurrency:
361 + group: sparse-${{ github.ref }}
362 + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
363 steps:
364 - name: Download a current `sparse` package
365 # Ubuntu's `sparse` version is too old for us
@@ -345,6 +378,9 @@ jobs:
378 name: documentation
379 needs: ci-config
380 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' }}
384 env:
385 jobname: Documentation
386 runs-on: ubuntu-latest