18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 09:15:01 +01:00
Files
maszyna/.github/workflows/build.yml
jerrrrycho 963791e3f3 ci: cancel the builds of a commit superseded by a newer push
A push to a pull request or to a branch started new runs of the Build and Build binaries workflows while the runs for the older commit went on to the end, holding the runners for results nobody needs.

The Build workflow now has a concurrency group per pull request, and the build jobs of Build binaries one per branch or pull request, with cancel-in-progress: the run for the older commit is cancelled when a newer one starts. Pushes to master get a group of their own (the commit), so the runs on master are neither cancelled nor held back by one another. In Build binaries the groups are on the build jobs, not on the workflow, so a publish job already running is left to finish.

sonar.yml needs no change: it already posts an error status (analysis skipped) on the commit of a cancelled Build run, and the newer commit gets its own pending status and analysis.
2026-11-11 10:16:23 +01:00

124 lines
4.8 KiB
YAML

# .github/workflows/build.yml
# UNTRUSTED CONTEXT. This workflow runs fork-authored code.
# It must never reference `secrets.*` (other than the default GITHUB_TOKEN,
# which is read-only here). Do not add SONAR_TOKEN to this file.
name: Build
on:
push:
branches:
- master
pull_request:
types: [ opened, reopened, synchronize ]
permissions: {}
# A newer push to a pull request makes the run for its older commit pointless, so that run is
# cancelled (sonar.yml then marks the analysis of the older commit as skipped). A push to master
# gets a group of its own, its commit, so the runs on master are neither cancelled nor held back
# by one another.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.sha }}
cancel-in-progress: true
jobs:
build:
name: Build under Build Wrapper
runs-on: ubuntu-24.04
permissions:
contents: read
env:
BUILD_WRAPPER_OUT_DIR: bw-output
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
with:
fetch-depth: 0
submodules: recursive
- name: Set up Python 3.14
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: '3.14'
- name: Install build dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y \
build-essential \
libgl1-mesa-dev libglew-dev libglfw3-dev \
libpng-dev libopenal-dev libluajit-5.1-dev \
libserialport-dev libsndfile1-dev \
xorg-dev libxkbcommon-dev libwayland-dev wayland-protocols
- name: Build current OpenAL Soft
run: |
git clone --depth 1 --branch 1.24.2 https://github.com/kcat/openal-soft.git /tmp/openal-soft
cmake -S /tmp/openal-soft -B /tmp/openal-soft/build \
-DCMAKE_BUILD_TYPE=Release -DALSOFT_EXAMPLES=OFF -DALSOFT_UTILS=OFF
cmake --build /tmp/openal-soft/build -j"$(nproc)"
sudo cmake --install /tmp/openal-soft/build
sudo ldconfig
# A little bit of magic for unbreaking GCC. Not an issue for Clang and MSVC.
# Fix for specific hard-errors for a combo of: varargs and always_inline
- name: Patch GLM for GCC
run: |
sed -i 's/GLM_FUNC_QUALIFIER std::string format(const char\* message, \.\.\.)/inline std::string format(const char* message, ...)/' \
ref/glm/glm/gtx/string_cast.inl
grep -n "std::string format(const char\* message" ref/glm/glm/gtx/string_cast.inl
- name: Install SonarQube Cloud Build Wrapper
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 # v6.0.0
- name: Configure (CMake)
run: |
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DWITH_BETTER_RENDERER=OFF \
-DWITH_ZMQ=OFF -DWITH_OPENVR=OFF -DUSE_LTO=OFF \
-DCMAKE_CXX_FLAGS="-Wno-attributes -fno-inline-functions-called-once" \
-DPython3_EXECUTABLE="$(which python3)"
- name: Build under Build Wrapper
run: |
build-wrapper-linux-x86-64 \
--out-dir "${BUILD_WRAPPER_OUT_DIR}" \
cmake --build build --config Release -j"$(nproc)"
# Metadata the trusted workflow needs to identify the PR.
# Treated as UNVERIFIED input there and re-checked against the API.
- name: Record event metadata
env:
EVENT_NAME: ${{ github.event_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
COMMIT_SHA: ${{ github.sha }}
run: |
mkdir -p .sonar-meta
printf '%s\n' "$EVENT_NAME" > .sonar-meta/event
printf '%s\n' "$PR_NUMBER" > .sonar-meta/pr_number
printf '%s\n' "$PR_HEAD_SHA" > .sonar-meta/head_sha
printf '%s\n' "$COMMIT_SHA" > .sonar-meta/sha
# The C/C++ analyzer needs the sources AND the build-wrapper output.
# compile_commands.json holds absolute paths, so the trusted workflow must
# unpack this at the same $GITHUB_WORKSPACE path — same repo, so it matches.
- name: Pack analysis input
run: |
tar -czf /tmp/workspace.tar.gz \
--exclude='./build/CMakeFiles' \
--exclude='*.o' \
--exclude='*.a' \
--exclude='*.so' \
--exclude='*.so.*' \
-C "$GITHUB_WORKSPACE" .
- name: Upload analysis input
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: sonar-input
path: /tmp/workspace.tar.gz
retention-days: 1
if-no-files-found: error