Skip to content

Commit dd4a287

Browse files
committed
Merge branch 'jk/ci-only-on-selected-branches'
Instead of always building all branches at GitHub via Actions, users can specify which branches to build. * jk/ci-only-on-selected-branches: ci: allow per-branch config for GitHub Actions
2 parents 94afbbb + e76eec3 commit dd4a287

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

.github/workflows/main.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,39 @@ env:
66
DEVELOPER: 1
77

88
jobs:
9+
ci-config:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
enabled: ${{ steps.check-ref.outputs.enabled }}
13+
steps:
14+
- name: try to clone ci-config branch
15+
continue-on-error: true
16+
run: |
17+
git -c protocol.version=2 clone \
18+
--no-tags \
19+
--single-branch \
20+
-b ci-config \
21+
--depth 1 \
22+
--no-checkout \
23+
--filter=blob:none \
24+
https://github.com/${{ github.repository }} \
25+
config-repo &&
26+
cd config-repo &&
27+
git checkout HEAD -- ci/config
28+
- id: check-ref
29+
name: check whether CI is enabled for ref
30+
run: |
31+
enabled=yes
32+
if test -x config-repo/ci/config/allow-ref &&
33+
! config-repo/ci/config/allow-ref '${{ github.ref }}'
34+
then
35+
enabled=no
36+
fi
37+
echo "::set-output name=enabled::$enabled"
38+
939
windows-build:
40+
needs: ci-config
41+
if: needs.ci-config.outputs.enabled == 'yes'
1042
runs-on: windows-latest
1143
steps:
1244
- uses: actions/checkout@v1
@@ -70,6 +102,8 @@ jobs:
70102
name: failed-tests-windows
71103
path: ${{env.FAILED_TEST_ARTIFACTS}}
72104
vs-build:
105+
needs: ci-config
106+
if: needs.ci-config.outputs.enabled == 'yes'
73107
env:
74108
MSYSTEM: MINGW64
75109
NO_PERL: 1
@@ -154,6 +188,8 @@ jobs:
154188
${{matrix.nr}} 10 t[0-9]*.sh)
155189
"@
156190
regular:
191+
needs: ci-config
192+
if: needs.ci-config.outputs.enabled == 'yes'
157193
strategy:
158194
matrix:
159195
vector:
@@ -189,6 +225,8 @@ jobs:
189225
name: failed-tests-${{matrix.vector.jobname}}
190226
path: ${{env.FAILED_TEST_ARTIFACTS}}
191227
dockerized:
228+
needs: ci-config
229+
if: needs.ci-config.outputs.enabled == 'yes'
192230
strategy:
193231
matrix:
194232
vector:
@@ -213,6 +251,8 @@ jobs:
213251
name: failed-tests-${{matrix.vector.jobname}}
214252
path: ${{env.FAILED_TEST_ARTIFACTS}}
215253
static-analysis:
254+
needs: ci-config
255+
if: needs.ci-config.outputs.enabled == 'yes'
216256
env:
217257
jobname: StaticAnalysis
218258
runs-on: ubuntu-latest
@@ -221,6 +261,8 @@ jobs:
221261
- run: ci/install-dependencies.sh
222262
- run: ci/run-static-analysis.sh
223263
documentation:
264+
needs: ci-config
265+
if: needs.ci-config.outputs.enabled == 'yes'
224266
env:
225267
jobname: Documentation
226268
runs-on: ubuntu-latest

ci/config/allow-refs.sample

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
#
3+
# Sample script for enabling/disabling GitHub Actions CI runs on
4+
# particular refs. By default, CI is run for all branches pushed to
5+
# GitHub. You can override this by dropping the ".sample" from the script,
6+
# editing it, committing, and pushing the result to the "ci-config" branch of
7+
# your repository:
8+
#
9+
# git checkout -b ci-config
10+
# cp allow-refs.sample allow-refs
11+
# $EDITOR allow-refs
12+
# git commit -am "implement my ci preferences"
13+
# git push
14+
#
15+
# This script will then be run when any refs are pushed to that repository. It
16+
# gets the fully qualified refname as the first argument, and should exit with
17+
# success only for refs for which you want to run CI.
18+
19+
case "$1" in
20+
# allow one-off tests by pushing to "for-ci" or "for-ci/mybranch"
21+
refs/heads/for-ci*) true ;;
22+
# always build your integration branch
23+
refs/heads/my-integration-branch) true ;;
24+
# don't build any other branches or tags
25+
*) false ;;
26+
esac

0 commit comments

Comments
 (0)