From 51830196b8e887d49c62b321da36d65cb464a4a3 Mon Sep 17 00:00:00 2001 From: Christian Hoffmann Date: Thu, 7 Apr 2022 23:04:52 +0200 Subject: [PATCH] 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. --- .github/pull_request_template.md | 3 ++ .github/workflows/autobuild.yml | 90 ++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6b1f6f2e7d..904d204605 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -32,3 +32,6 @@ CHANGELOG: - [ ] I waited some time after this Pull Request was opened and all GitHub checks completed without errors. - [ ] I've filled all the content above + + + diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index fbc7b64302..89ca57f2e9 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -18,6 +18,10 @@ on: workflow_dispatch: + inputs: + build_all_targets: + type: boolean + description: 'Build all targets (instead of just the main platforms)' push: tags: - "r*" @@ -62,6 +66,7 @@ jobs: publish_to_release: ${{ steps.get-build-vars.outputs.PUBLISH_TO_RELEASE }} upload_url: ${{ steps.create-release.outputs.upload_url }} build_version: ${{ steps.get-build-vars.outputs.BUILD_VERSION }} + build_all_targets: ${{ steps.decide-build-targets.outputs.build_all_targets }} env: release_changelog_path: ./.github_release_changelog.md @@ -100,6 +105,76 @@ jobs: prerelease: ${{ steps.get-build-vars.outputs.IS_PRERELEASE }} draft: false + - name: Decide which targets to build for + id: decide-build-targets + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + INPUT_BUILD_ALL_TARGETS: ${{ github.event.inputs.build_all_targets }} + PR_NUMBER: ${{ github.event.number }} + PR_BASE: ${{ github.event.pull_request.base.sha }} + PR_HEAD: ${{ github.event.pull_request.head.sha }} + run: | + set -eu + build_all_targets() { + echo "::set-output name=build_all_targets::${1}" + echo "Building for all targets? Result: ${1}" + exit 0 + } + + handle_push() { + if [[ "${GITHUB_REF}" == "refs/tags/"* ]]; then + echo 'Triggered by a tag push, building all targets' + build_all_targets 'true' + fi + if [[ "${GITHUB_REF}" == "refs/heads/autobuild"* ]]; then + echo 'Triggered by a push to an autobuild* branch, building all targets' + build_all_targets 'true' + fi + } + + handle_workflow_dispatch() { + if [[ "${INPUT_BUILD_ALL_TARGETS}" == 'true' ]]; then + echo 'Triggered by manual run with "Build all targets" checkbox set' + build_all_targets 'true' + fi + } + + handle_pull_request() { + pr_body_contains_magic_string() { + pr_body=$(gh pr view "${PR_NUMBER}" --json body --jq .body) + grep -vP '