From 0bd8bdb1c9ba005fdf2ac5088ba9d057947ec2b1 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Wed, 25 Nov 2026 16:54:12 +0200 Subject: [PATCH 1/2] ci: cancel previous jobs from the same branch; prefer tag builds on the same commit group concurrency by the pushed commit sha for push events (branches and tags), so a tag build pushed after a branch build on the same commit cancels the in-progress branch build and remains. for pull requests group by ref (refs/pull/N/merge). --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37e9eee..e249578 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,12 @@ on: pull_request: branches: - main +concurrency: + # for push events (branches and tags) group by the pushed commit sha, so that a + # tag build pushed after a branch build on the same commit cancels the branch + # build and remains. for pull requests group by ref (refs/pull/N/merge). + group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }} + cancel-in-progress: true env: PACKAGE_NAME: ${{ github.event.repository.name }} PACKAGE_VERSION: ${{ github.sha }} From 2e6ba2619db4457df5cf9c4ab282d243cd146ecc Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Wed, 25 Nov 2026 17:06:44 +0200 Subject: [PATCH 2/2] ci: enforce tag build priority regardless of run order the concurrency group cancels the older run, so it cannot give the tag build priority when the branch run starts after the tag run. revert the group to a plain per-ref one (branch and tag runs no longer share a group) and add a tag-priority job that all other jobs depend on: in a tag build it cancels in-progress branch builds on the same commit, in a branch build it cancels the run when a tag build on the same commit is in progress. --- .github/workflows/ci.yml | 47 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e249578..11e1b82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,10 +8,11 @@ on: branches: - main concurrency: - # for push events (branches and tags) group by the pushed commit sha, so that a - # tag build pushed after a branch build on the same commit cancels the branch - # build and remains. for pull requests group by ref (refs/pull/N/merge). - group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }} + # group by ref: a new push to a branch or pull request cancels the in-progress run of the + # same branch or pull request. branch and tag builds do not share a group, so the tag build + # priority is enforced by the tag-priority job instead (a concurrency group cancels the + # older run, which would not give the tag build priority when the branch run starts later) + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true env: PACKAGE_NAME: ${{ github.event.repository.name }} @@ -24,6 +25,33 @@ env: MYCI_CONAN_USER: cppfw MYCI_CONAN_PASSWORD: ${{ secrets.MYCI_CONAN_PASSWORD }} jobs: + tag-priority: + # enforce that the tag build always wins over the branch build on the same commit, + # regardless of the order in which the runs start: + # - in a tag build: cancel the in-progress branch build on the same commit + # - in a branch build: cancel this run when a tag build on the same commit is in progress + # all the other jobs depend on this job, so the cancellation happens before the builds start + if: github.ref_type == 'tag' || (github.event_name == 'push' && github.ref_type == 'branch') + runs-on: ubuntu-latest + steps: + - name: enforce tag build priority + env: + GH_TOKEN: ${{ github.token }} + run: | + if [ "${GITHUB_REF_TYPE}" = tag ]; then + for id in $(gh api "repos/${GITHUB_REPOSITORY}/actions/runs?status=in_progress&per_page=100" --paginate \ + -q ".workflow_runs[] | select(.head_sha == \"${GITHUB_SHA}\" and .event == \"push\" and .name == \"ci\" and .head_branch != null and .head_branch != \"\") | .id"); do + echo "cancelling in-progress branch build (run $id) on the same commit" + gh api -X POST "repos/${GITHUB_REPOSITORY}/actions/runs/$id/cancelations" + done + else + for id in $(gh api "repos/${GITHUB_REPOSITORY}/actions/runs?status=in_progress&per_page=100" --paginate \ + -q ".workflow_runs[] | select(.head_sha == \"${GITHUB_SHA}\" and .event == \"push\" and .name == \"ci\" and (.head_branch == null or .head_branch == \"\")) | .id"); do + echo "a tag build (run $id) on the same commit is in progress; cancelling this branch build" + gh api -X POST "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/cancelations" + exit 0 + done + fi ##### coverage ##### # coverage: # runs-on: ubuntu-latest @@ -94,6 +122,7 @@ jobs: # verbose: true # optional (default = false) ##### sanitizer ##### sanitizer: + needs: tag-priority strategy: fail-fast: false matrix: @@ -133,6 +162,7 @@ jobs: run: make config=asan test ##### lint ##### lint: + needs: tag-priority runs-on: ubuntu-latest container: debian:trixie name: lint @@ -159,6 +189,7 @@ jobs: run: make config=lint test ##### deb linux ##### deb: + needs: tag-priority strategy: fail-fast: false matrix: @@ -227,6 +258,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') ##### macosx ##### macosx: + needs: tag-priority runs-on: macos-latest steps: - name: workaround python2 and python3 issue when upgrading python @@ -276,6 +308,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') ##### android ##### android: + needs: tag-priority runs-on: ubuntu-latest container: mingc/android-build-box:latest steps: @@ -302,6 +335,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') ##### msys2 ##### msys2: + needs: tag-priority runs-on: windows-latest defaults: run: @@ -356,6 +390,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') ##### vcpkg-linux ##### vcpkg-linux: + needs: tag-priority strategy: fail-fast: false matrix: @@ -413,6 +448,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') ##### vcpkg-windows ##### vcpkg-windows: + needs: tag-priority runs-on: windows-latest defaults: run: @@ -460,6 +496,7 @@ jobs: if-no-files-found: warn ##### vcpkg-macos ##### vcpkg-macos: + needs: tag-priority runs-on: macos-latest strategy: fail-fast: false @@ -521,6 +558,7 @@ jobs: if-no-files-found: warn ##### vcpkg-ios ##### vcpkg-ios: + needs: tag-priority runs-on: macos-latest strategy: fail-fast: false @@ -688,6 +726,7 @@ jobs: # if: startsWith(github.ref, 'refs/tags/') ##### conan - emscripten ##### conan-emscripten: + needs: tag-priority strategy: fail-fast: false matrix: