Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ on:
pull_request:
branches:
- main
concurrency:
# 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 }}
PACKAGE_VERSION: ${{ github.sha }}
Expand All @@ -18,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
Expand Down Expand Up @@ -88,6 +122,7 @@ jobs:
# verbose: true # optional (default = false)
##### sanitizer #####
sanitizer:
needs: tag-priority
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -127,6 +162,7 @@ jobs:
run: make config=asan test
##### lint #####
lint:
needs: tag-priority
runs-on: ubuntu-latest
container: debian:trixie
name: lint
Expand All @@ -153,6 +189,7 @@ jobs:
run: make config=lint test
##### deb linux #####
deb:
needs: tag-priority
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -221,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
Expand Down Expand Up @@ -270,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:
Expand All @@ -296,6 +335,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
##### msys2 #####
msys2:
needs: tag-priority
runs-on: windows-latest
defaults:
run:
Expand Down Expand Up @@ -350,6 +390,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
##### vcpkg-linux #####
vcpkg-linux:
needs: tag-priority
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -407,6 +448,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
##### vcpkg-windows #####
vcpkg-windows:
needs: tag-priority
runs-on: windows-latest
defaults:
run:
Expand Down Expand Up @@ -454,6 +496,7 @@ jobs:
if-no-files-found: warn
##### vcpkg-macos #####
vcpkg-macos:
needs: tag-priority
runs-on: macos-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -515,6 +558,7 @@ jobs:
if-no-files-found: warn
##### vcpkg-ios #####
vcpkg-ios:
needs: tag-priority
runs-on: macos-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -682,6 +726,7 @@ jobs:
# if: startsWith(github.ref, 'refs/tags/')
##### conan - emscripten #####
conan-emscripten:
needs: tag-priority
strategy:
fail-fast: false
matrix:
Expand Down