From 6aa6b077bfc12fee17ddcd8bf6839d97421cee00 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 29 Nov 2026 10:48:12 +0100 Subject: [PATCH] ci: Sonar input without compiling; no AVX2 for master only; unit tests in the AVX2 build Build (the input of the SonarQube Cloud analysis): the analyzer needs the compile commands and the headers, not the objects, so the job no longer compiles under the Build Wrapper. CMake writes compile_commands.json at configure time (CMAKE_EXPORT_COMPILE_COMMANDS), together with the headers the project generates; glslang's build_info.h is made by its own small target. The database goes where sonar.yml reads it (bw-output/), so the trusted workflow is unchanged. build/CMakeFiles is packed now: it holds cmake_pch.hxx, which the commands include. Build binaries: the variant without AVX2 is built for master only (pushes to master, pull requests into master, i.e. staging into master) and by a manual run; branch downloads have the AVX2 build and point to build-master for the other one. A pull request into master from this repository builds again (both variants, the merge), as the check before a release. The variant without AVX2 builds no unit tests (-DWITH_TESTS=OFF, no lua51.dll): they run in the AVX2 build of the same commit. The matrix comes from the `changes` job. --- .github/workflows/build.yml | 29 +++++++------ .github/workflows/build_bin.yml | 75 +++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 758b4c8d5..8ce3f1569 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ concurrency: jobs: build: - name: Build under Build Wrapper + name: Compilation database for SonarQube Cloud runs-on: ubuntu-24.04 permissions: contents: read @@ -76,23 +76,27 @@ jobs: 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 - + # The analyzer needs the compile command of every file and the headers they include, not the objects: the + # compilation database CMake writes at configure time is enough, so nothing is compiled here. The headers the + # project generates (version_info.h, the editor icons) are written by the configure step too. - name: Configure (CMake) run: | cmake -S . -B build \ -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -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 + # glslang writes its build_info.h at build time; its sources are excluded from the analysis, but the target + # is cheap and makes the include available should a header of ours reach it + - name: Compilation database run: | - build-wrapper-linux-x86-64 \ - --out-dir "${BUILD_WRAPPER_OUT_DIR}" \ - cmake --build build --config Release -j"$(nproc)" + cmake --build build --target glslang-build-info || echo "no glslang-build-info target, nothing generated" + mkdir -p "${BUILD_WRAPPER_OUT_DIR}" + cp build/compile_commands.json "${BUILD_WRAPPER_OUT_DIR}/compile_commands.json" + echo "$(grep -c '"file"' "${BUILD_WRAPPER_OUT_DIR}/compile_commands.json") compile commands" # Metadata the trusted workflow needs to identify the PR. # Treated as UNVERIFIED input there and re-checked against the API. @@ -109,13 +113,14 @@ jobs: 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. + # The C/C++ analyzer needs the sources AND the compilation database (kept in bw-output/, where the + # trusted workflow reads it). compile_commands.json holds absolute paths, so the trusted workflow must + # unpack this at the same $GITHUB_WORKSPACE path — same repo, so it matches. build/CMakeFiles stays in: + # with nothing compiled it is small, and it holds cmake_pch.hxx, which every command of the targets with + # the precompiled header includes (-include). - name: Pack analysis input run: | tar -czf /tmp/workspace.tar.gz \ - --exclude='./build/CMakeFiles' \ --exclude='*.o' \ --exclude='*.a' \ --exclude='*.so' \ diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml index c2bfe2e64..ca6087363 100644 --- a/.github/workflows/build_bin.yml +++ b/.github/workflows/build_bin.yml @@ -30,12 +30,18 @@ jobs: # 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 + # workflows), except a pull request into master (staging into master): that is the check before a release, of the + # merge, with both variants. 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. + # required today; a skipped matrix job shows under its unexpanded name, `${{ matrix.variant.name }}`). Anything + # this job can't decide builds. + # + # The variant without AVX2 (CPUs older than Haswell, 2013) is the same sources with one compiler switch: it is built + # for master only (pushes to master, pull requests into master, so every staging into master) and by a manual run. + # It builds no unit tests: they run in the AVX2 build of the same commit. changes: name: Whether to build runs-on: ubuntu-24.04 @@ -45,6 +51,8 @@ jobs: pull-requests: read outputs: build: ${{ steps.decide.outputs.build }} + variants: ${{ steps.decide.outputs.variants }} + noavx2: ${{ steps.decide.outputs.noavx2 }} steps: - name: Decide from the event and the changed files id: decide @@ -57,10 +65,23 @@ jobs: BEFORE: ${{ github.event.before }} PR_NUMBER: ${{ github.event.pull_request.number }} PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} + BASE_REF: ${{ github.base_ref }} run: | + avx2='{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON","tests":true}' + noavx2='{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF -DWITH_TESTS=OFF","tests":false}' + if [ "$EVENT_NAME" = workflow_dispatch ] \ + || { [ "$EVENT_NAME" = push ] && [ "$REF" = refs/heads/master ]; } \ + || { [ "$EVENT_NAME" = pull_request ] && [ "$BASE_REF" = master ]; }; then + echo "variants=[$avx2,$noavx2]" >> "$GITHUB_OUTPUT" + echo "noavx2=true" >> "$GITHUB_OUTPUT" + else + echo "variants=[$avx2]" >> "$GITHUB_OUTPUT" + echo "noavx2=false" >> "$GITHUB_OUTPUT" + fi build() { echo "$1"; echo "build=true" >> "$GITHUB_OUTPUT"; exit 0; } case "$EVENT_NAME" in pull_request) + [ "$BASE_REF" != master ] || build "A pull request into master, building the merge." if [ "$PR_HEAD_REPO" = "$REPO" ]; then echo "A branch of this repository: its push run builds this commit." echo "build=false" >> "$GITHUB_OUTPUT" @@ -121,13 +142,8 @@ jobs: strategy: fail-fast: false matrix: - variant: - - name: "AVX2" - suffix: "avx2" - cmake_flags: "-DENABLE_AVX2=ON" - - name: "No AVX2" - suffix: "noavx2" - cmake_flags: "-DENABLE_AVX2=OFF" + # AVX2 always, without AVX2 for master only: see the job `changes` + variant: ${{ fromJSON(needs.changes.outputs.variants) }} steps: - name: Checkout repository @@ -177,6 +193,7 @@ jobs: # the unit tests run at the end of the build and load lua51.dll (the Lua screens), but ref/luajit has only its import # library. LuaJIT of the same 2.0 line is built here and put on PATH for them; it doesn't go into the uploaded build - name: Build lua51.dll for the unit tests + if: matrix.variant.tests shell: cmd run: | for /f "usebackq delims=" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSDIR=%%i" @@ -298,13 +315,8 @@ jobs: strategy: fail-fast: false matrix: - variant: - - name: "AVX2" - suffix: "avx2" - cmake_flags: "-DENABLE_AVX2=ON" - - name: "No AVX2" - suffix: "noavx2" - cmake_flags: "-DENABLE_AVX2=OFF" + # AVX2 always, without AVX2 for master only: see the job `changes` + variant: ${{ fromJSON(needs.changes.outputs.variants) }} steps: - name: Checkout repository @@ -571,7 +583,7 @@ jobs: publish: name: Publish public download - needs: [windows, linux] + needs: [changes, windows, linux] if: github.event_name != 'pull_request' runs-on: ubuntu-24.04 permissions: @@ -589,6 +601,7 @@ jobs: path: dist/maszyna-windows-x64 - name: Download Windows build (no AVX2) + if: needs.changes.outputs.noavx2 == 'true' uses: actions/download-artifact@v4 with: name: maszyna-windows-x64-noavx2-${{ env.CONFIG_WIN }} @@ -601,6 +614,7 @@ jobs: path: dist/maszyna-linux-x64 - name: Download Linux build (no AVX2) + if: needs.changes.outputs.noavx2 == 'true' uses: actions/download-artifact@v4 with: name: maszyna-linux-x64-noavx2-${{ env.CONFIG_LINUX }} @@ -612,6 +626,7 @@ jobs: # the artifacts lose the executable bit for dir in maszyna-linux-x64 maszyna-linux-x64-noavx2; do + [ -d "$dir" ] || continue find "$dir" -type f -exec sh -c 'file -b "$1" | grep -q "^ELF" && chmod +x "$1"' _ {} \; if [ -d "$dir/linuxpython64/bin" ]; then chmod +x "$dir"/linuxpython64/bin/* @@ -619,9 +634,12 @@ jobs: done (cd maszyna-windows-x64 && zip -qr9 ../maszyna-windows-x64.zip .) - (cd maszyna-windows-x64-noavx2 && zip -qr9 ../maszyna-windows-x64-noavx2.zip .) tar -czf maszyna-linux-x64.tar.gz -C maszyna-linux-x64 . - tar -czf maszyna-linux-x64-noavx2.tar.gz -C maszyna-linux-x64-noavx2 . + # without AVX2: master only + if [ -d maszyna-windows-x64-noavx2 ]; then + (cd maszyna-windows-x64-noavx2 && zip -qr9 ../maszyna-windows-x64-noavx2.zip .) + tar -czf maszyna-linux-x64-noavx2.tar.gz -C maszyna-linux-x64-noavx2 . + fi ls -la - name: Publish rolling release of the branch @@ -636,23 +654,26 @@ jobs: tag="build-$slug" base="${{ github.server_url }}/${{ github.repository }}/releases/download/$tag" + assets=(dist/maszyna-windows-x64.zip dist/maszyna-linux-x64.tar.gz) + links=("- Windows: $base/maszyna-windows-x64.zip" "- Linux: $base/maszyna-linux-x64.tar.gz") + if [ -f dist/maszyna-windows-x64-noavx2.zip ]; then + assets+=(dist/maszyna-windows-x64-noavx2.zip dist/maszyna-linux-x64-noavx2.tar.gz) + links+=("- Windows, CPUs without AVX2 (older than Haswell, 2013): $base/maszyna-windows-x64-noavx2.zip" + "- Linux, CPUs without AVX2: $base/maszyna-linux-x64-noavx2.tar.gz") + else + links+=("- CPUs without AVX2 (older than Haswell, 2013): built for master only, see the release build-master") + fi notes="$(printf '%s\n' \ "Automatic build of branch \`$BRANCH\`, commit $SHA, replaced by every push to the branch." \ "" \ "Download without a GitHub account:" \ - "- Windows: $base/maszyna-windows-x64.zip" \ - "- Windows, CPUs without AVX2 (older than Haswell, 2013): $base/maszyna-windows-x64-noavx2.zip" \ - "- Linux: $base/maszyna-linux-x64.tar.gz" \ - "- Linux, CPUs without AVX2: $base/maszyna-linux-x64-noavx2.tar.gz" \ + "${links[@]}" \ "" \ "Unpack over a MaSzyna installation (the game data isn't included). Build log: $RUN_URL")" gh release delete "$tag" --yes --cleanup-tag || true gh release create "$tag" \ - dist/maszyna-windows-x64.zip \ - dist/maszyna-windows-x64-noavx2.zip \ - dist/maszyna-linux-x64.tar.gz \ - dist/maszyna-linux-x64-noavx2.tar.gz \ + "${assets[@]}" \ --target "$SHA" \ --prerelease \ --latest=false \