Skip to content

Commit 5183019

Browse files
committed
Autobuild: Limit build targets by default
This modifies the build logic to stop building all platforms on PRs by default. To re-enable building for all platforms, the PR has to contain a special hint which has been documented in the PR template. Manually triggered workflows can also decide this explicitly now. Tags/releases and autobuild branches are unchanged. This is supposed to reduce CI usage times in order to keep build queues for us shorter and in order to avoid wasting energy.
1 parent cafdbaf commit 5183019

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

.github/pull_request_template.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ CHANGELOG: <!-- Insert a short, end-user understandable sentence in past tense r
3232
- [ ] My code follows the [style guide](https://github.com/jamulussoftware/jamulus/blob/master/CONTRIBUTING.md#source-code-consistency) <!-- You can also check if your code passes clang-format -->
3333
- [ ] I waited some time after this Pull Request was opened and all GitHub checks completed without errors. <!-- GitHub doesn't run these checks for new contributors automatically. -->
3434
- [ ] I've filled all the content above
35+
36+
<!-- Uncomment the following line if your PR changes platform- or build-specific code: -->
37+
<!-- AUTOBUILD: Please build all targets -->

.github/workflows/autobuild.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
on:
2020
workflow_dispatch:
21+
inputs:
22+
build_all_targets:
23+
type: boolean
24+
description: 'Build all targets (instead of just the main platforms)'
2125
push:
2226
tags:
2327
- "r*"
@@ -62,6 +66,7 @@ jobs:
6266
publish_to_release: ${{ steps.get-build-vars.outputs.PUBLISH_TO_RELEASE }}
6367
upload_url: ${{ steps.create-release.outputs.upload_url }}
6468
build_version: ${{ steps.get-build-vars.outputs.BUILD_VERSION }}
69+
build_all_targets: ${{ steps.decide-build-targets.outputs.build_all_targets }}
6570
env:
6671
release_changelog_path: ./.github_release_changelog.md
6772

@@ -100,6 +105,76 @@ jobs:
100105
prerelease: ${{ steps.get-build-vars.outputs.IS_PRERELEASE }}
101106
draft: false
102107

108+
- name: Decide which targets to build for
109+
id: decide-build-targets
110+
env:
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
INPUT_BUILD_ALL_TARGETS: ${{ github.event.inputs.build_all_targets }}
113+
PR_NUMBER: ${{ github.event.number }}
114+
PR_BASE: ${{ github.event.pull_request.base.sha }}
115+
PR_HEAD: ${{ github.event.pull_request.head.sha }}
116+
run: |
117+
set -eu
118+
build_all_targets() {
119+
echo "::set-output name=build_all_targets::${1}"
120+
echo "Building for all targets? Result: ${1}"
121+
exit 0
122+
}
123+
124+
handle_push() {
125+
if [[ "${GITHUB_REF}" == "refs/tags/"* ]]; then
126+
echo 'Triggered by a tag push, building all targets'
127+
build_all_targets 'true'
128+
fi
129+
if [[ "${GITHUB_REF}" == "refs/heads/autobuild"* ]]; then
130+
echo 'Triggered by a push to an autobuild* branch, building all targets'
131+
build_all_targets 'true'
132+
fi
133+
}
134+
135+
handle_workflow_dispatch() {
136+
if [[ "${INPUT_BUILD_ALL_TARGETS}" == 'true' ]]; then
137+
echo 'Triggered by manual run with "Build all targets" checkbox set'
138+
build_all_targets 'true'
139+
fi
140+
}
141+
142+
handle_pull_request() {
143+
pr_body_contains_magic_string() {
144+
pr_body=$(gh pr view "${PR_NUMBER}" --json body --jq .body)
145+
grep -vP '<!--' <<< "$pr_body" | grep -qiF -- 'AUTOBUILD: Please build all targets'
146+
}
147+
if pr_body_contains_magic_string; then
148+
echo 'Triggered by a PR with magic AUTOBUILD: string, building all targets'
149+
build_all_targets 'true'
150+
fi
151+
152+
pr_contains_build_changes() {
153+
git fetch origin "${PR_BASE}" "${PR_HEAD}"
154+
git diff --name-only "${PR_BASE}..${PR_HEAD}" |
155+
grep -qP 'autobuild|windows|linux|mac|ios|android|\.pro'
156+
}
157+
if pr_contains_build_changes; then
158+
echo 'Triggered by a PR with build- or platform-specific changes, building all targets'
159+
build_all_targets 'true'
160+
fi
161+
}
162+
163+
case "${GITHUB_EVENT_NAME}" in
164+
push)
165+
handle_push
166+
;;
167+
workflow_dispatch)
168+
handle_workflow_dispatch
169+
;;
170+
pull_request)
171+
handle_pull_request
172+
;;
173+
esac
174+
175+
echo 'default case, not building all targets'
176+
build_all_targets 'false'
177+
103178
104179
release_assets:
105180
name: Build for ${{ matrix.config.config_name }}
@@ -115,6 +190,7 @@ jobs:
115190
building_on_os: ubuntu-20.04
116191
base_command: ./.github/autobuild/android.sh
117192
run_codeql: true
193+
is_main_build_target: true
118194
# Jamulus.pro needs to count git history length for android versioning:
119195
checkout_fetch_depth: '0'
120196

@@ -124,6 +200,7 @@ jobs:
124200
building_container: ubuntu:18.04
125201
base_command: ./.github/autobuild/linux_deb.sh
126202
run_codeql: true
203+
is_main_build_target: true
127204

128205
- config_name: Linux .deb armhf (artifacts)
129206
target_os: linux
@@ -140,6 +217,7 @@ jobs:
140217
run_codeql: false
141218
# Latest Xcode which runs on macos-11:
142219
xcode_version: 13.4.1
220+
is_main_build_target: true
143221

144222
- config_name: MacOS arm64 (artifacts)
145223
target_os: macos
@@ -162,6 +240,7 @@ jobs:
162240
# Xcode 12.1.1 is the most-recent 12.1.x release:
163241
# https://xcodereleases.com/
164242
xcode_version: 12.1.1
243+
is_main_build_target: true
165244

166245
- config_name: iOS (artifacts)
167246
target_os: ios
@@ -178,13 +257,24 @@ jobs:
178257
building_on_os: windows-2022
179258
base_command: powershell .\.github\autobuild\windows.ps1 -Stage
180259
run_codeql: true
260+
is_main_build_target: true
181261

182262
- config_name: Windows JACK (artifact)
183263
target_os: windows
184264
building_on_os: windows-2022
185265
base_command: powershell .\.github\autobuild\windows.ps1 -BuildOption jackonwindows -Stage
186266
run_codeql: false
187267

268+
# This injects the build_all_targets information into each matrix output:
269+
build_all_targets:
270+
- ${{ needs.create_release.outputs.build_all_targets }}
271+
272+
# Exclude all non-main build targets if we are not building for all targets:
273+
exclude:
274+
- build_all_targets: 'false' # This is based on a script output and is therefore a string
275+
config:
276+
is_main_build_target: null
277+
188278
runs-on: ${{ matrix.config.building_on_os }}
189279
container: ${{ matrix.config.building_container }}
190280
steps:

0 commit comments

Comments
 (0)