From fe6d3a1d187e4e234abdd5325fd9265362bbe383 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 29 Nov 2026 10:23:04 +0100 Subject: [PATCH] ci: build the binaries once per commit, and not for docs or scenario tests A pull request from a branch of this repository no longer builds the binaries: the push run of that branch builds the same commit and publishes its download, and the merge with the base is compiled by the Build and Coverage workflows. A pull request from a fork has no push run here and builds both variants as before. A push that changes only *.md, docs/, LICENSE or tests/scenarios/ builds nothing either (new branches are compared with staging, then master); pushes to staging and master and manual runs always build, and so does anything the check can't decide. The decision is a job (`changes`) the build jobs need, so a skipped build counts as passed. With the pull request builds gone, the AVX2-only matrix of a same-repository pull request is no longer needed and both jobs list their two variants again. Coverage skips tests/scenarios/ as well. --- .github/workflows/build_bin.yml | 102 ++++++++++++++++++++++++++++---- .github/workflows/coverage.yml | 9 +-- 2 files changed, 97 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml index dc612e0fd..c2bfe2e64 100644 --- a/.github/workflows/build_bin.yml +++ b/.github/workflows/build_bin.yml @@ -23,6 +23,80 @@ env: jobs: + # ============================================================ + # Whether the binaries are built at all + # ============================================================ + + # Every push to a branch of this repository runs this workflow, and a pull request from such a branch would run it + # once more for the same commit. The push run builds and publishes the download of the branch, so the pull request + # run of a branch of this repository builds nothing (the merge with the base is compiled by the Build and Coverage + # workflows); a pull request from a fork has no push run here and builds as before. A push that changes only + # documentation or the data of the scenario tests (which the binaries don't contain) builds nothing either: the + # download of the branch stays at its last build, of the same binaries. Pushes to staging and master and manual runs + # always build. The checks are job-level conditions, not `paths-ignore` or `branches-ignore` on the trigger: a skipped + # job counts as passed, a workflow that doesn't start would leave a required check pending for ever (none is + # required today). Anything this job can't decide builds. + changes: + name: Whether to build + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + pull-requests: read + outputs: + build: ${{ steps.decide.outputs.build }} + steps: + - name: Decide from the event and the changed files + id: decide + env: + GH_TOKEN: ${{ github.token }} + EVENT_NAME: ${{ github.event_name }} + REPO: ${{ github.repository }} + REF: ${{ github.ref }} + SHA: ${{ github.sha }} + BEFORE: ${{ github.event.before }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} + run: | + build() { echo "$1"; echo "build=true" >> "$GITHUB_OUTPUT"; exit 0; } + case "$EVENT_NAME" in + pull_request) + if [ "$PR_HEAD_REPO" = "$REPO" ]; then + echo "A branch of this repository: its push run builds this commit." + echo "build=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + files="$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" --jq '.[] | .filename, (.previous_filename // empty)')" \ + || build "The files of the pull request are not available, building." ;; + push) + case "$REF" in + refs/heads/staging|refs/heads/master) build "A push to staging or master, building." ;; + esac + # a new branch (before = zeros) against staging, then master; a later push against the commit before it + if [ -n "$BEFORE" ] && [ "$BEFORE" != 0000000000000000000000000000000000000000 ]; then + bases="$BEFORE" + else + bases="staging master" + fi + files="" + for base in $bases; do + # the compare lists at most 300 files: more than that, or no list, builds + if out="$(gh api "repos/$REPO/compare/$base...$SHA" --jq 'if (.files | length) < 300 then (.files[] | .filename, (.previous_filename // empty)) else error("too many files") end')"; then + files="$out" + break + fi + done ;; + *) build "A manual run, building." ;; + esac + [ -n "$files" ] || build "The list of changed files is not available or empty, building." + # what the binaries don't contain: *.md, docs/, LICENSE and the scenario tests (cases and their runner) + # (not *.txt: CMakeLists.txt is code; tests/unit is built into the binaries' test run) + if printf '%s\n' "$files" | grep -Evq '(\.md$|^docs/|^LICENSE|^tests/scenarios/)'; then + build "Code changed, building." + fi + echo "Only documentation or scenario test data changed, the binaries are not built." + echo "build=false" >> "$GITHUB_OUTPUT" + # ============================================================ # Windows / MSVC # ============================================================ @@ -37,6 +111,8 @@ jobs: windows: name: Windows x64 / MSVC / ${{ matrix.variant.name }} + needs: changes + if: needs.changes.outputs.build == 'true' runs-on: windows-2022 concurrency: group: ${{ github.workflow }}-windows-${{ matrix.variant.suffix }}-${{ github.event_name }}-${{ github.ref == 'refs/heads/master' && github.sha || github.ref }} @@ -45,11 +121,13 @@ jobs: strategy: fail-fast: false matrix: - # a pull request from a branch of this repository builds the AVX2 variant only; the variant without AVX2 - # (the same sources, one compiler switch) is built by the push of that branch, by the pushes to staging - # and master and by a manual run. a pull request from a fork has no push run here, so it builds both. - # so the "No AVX2" jobs of a pull request of this repository never run: don't make them a required check - variant: ${{ fromJSON(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }} + variant: + - name: "AVX2" + suffix: "avx2" + cmake_flags: "-DENABLE_AVX2=ON" + - name: "No AVX2" + suffix: "noavx2" + cmake_flags: "-DENABLE_AVX2=OFF" steps: - name: Checkout repository @@ -204,6 +282,8 @@ jobs: linux: name: Linux x64 / GCC / ${{ matrix.variant.name }} + needs: changes + if: needs.changes.outputs.build == 'true' runs-on: ubuntu-24.04 # the key of a compiler cache saved here, one output per variant (a matrix job's outputs are shared by its legs): # the job linux-ccache-cleanup deletes the older ones, so this job needs no write access @@ -218,11 +298,13 @@ jobs: strategy: fail-fast: false matrix: - # a pull request from a branch of this repository builds the AVX2 variant only; the variant without AVX2 - # (the same sources, one compiler switch) is built by the push of that branch, by the pushes to staging - # and master and by a manual run. a pull request from a fork has no push run here, so it builds both. - # so the "No AVX2" jobs of a pull request of this repository never run: don't make them a required check - variant: ${{ fromJSON(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }} + variant: + - name: "AVX2" + suffix: "avx2" + cmake_flags: "-DENABLE_AVX2=ON" + - name: "No AVX2" + suffix: "noavx2" + cmake_flags: "-DENABLE_AVX2=OFF" steps: - name: Checkout repository diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index dbd79eee8..92fa748cd 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -28,7 +28,8 @@ concurrency: cancel-in-progress: true jobs: - # A pull request that changes only documentation doesn't need the coverage build. The check is a job-level + # A pull request that changes only documentation or the scenario tests (cases and their runner, which aren't built) + # doesn't need the coverage build. The check is a job-level # condition, not `paths-ignore` on the trigger: a workflow that doesn't start leaves a required check "pending" # for ever, while a skipped job (its name is fixed) counts as passed. A push, and anything this step can't # decide, runs the build. @@ -58,11 +59,11 @@ jobs: echo "code=true" >> "$GITHUB_OUTPUT" exit 0 fi - # what is not documentation: *.md, docs/ and LICENSE (not *.txt: CMakeLists.txt is code) - if printf '%s\n' "$files" | grep -Evq '(\.md$|^docs/|^LICENSE)'; then + # what is not built: *.md, docs/, LICENSE and tests/scenarios/ (not *.txt: CMakeLists.txt is code) + if printf '%s\n' "$files" | grep -Evq '(\.md$|^docs/|^LICENSE|^tests/scenarios/)'; then echo "code=true" >> "$GITHUB_OUTPUT" else - echo "Only documentation changed, the coverage build is skipped." + echo "Only documentation or scenario tests changed, the coverage build is skipped." echo "code=false" >> "$GITHUB_OUTPUT" fi