From c01007b9ddaba8d8829cc4702d8d689a0f2c4411 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 11 Nov 2026 10:49:03 +0100 Subject: [PATCH 1/6] ci: measure the coverage of the core library by the unit tests A new Coverage workflow builds the unit tests with GCC and gcov (unoptimised, the tests and the core library only), runs them and reports with gcovr: the totals and the per-file table in the summary of the run, the HTML report and the SonarQube generic coverage file in the unit-test-coverage artifact. The report isn't sent to SonarQube Cloud. The project's quality gate (Sonar way) fails a pull request whose new code is covered in less than 80%; that condition isn't evaluated today because sonar-project.properties excludes every file from coverage, and sending the report would turn it on. --- .github/workflows/coverage.yml | 131 +++++++++++++++++++++++++++++++++ tests/unit/COVERAGE.md | 2 + 2 files changed, 133 insertions(+) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000..4577e3795 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,131 @@ +# .github/workflows/coverage.yml +# UNTRUSTED CONTEXT. This workflow runs fork-authored code. +# It must never reference `secrets.*`. It only builds, runs the unit tests and +# uploads a report; nothing here feeds the SonarQube Cloud analysis. +# +# Coverage of the game's core library (eu07_core) by the unit tests, measured with +# gcov on a GCC build: the report goes to the summary of the run and to an artifact. +# It is not sent to SonarQube Cloud on purpose: the project's quality gate ("Sonar +# way") fails a pull request whose new code is covered in less than 80%, a condition +# that isn't evaluated as long as sonar-project.properties excludes every file from +# coverage. Wiring this report in would turn that condition on. + +name: Coverage + +on: + push: + branches: + - master + pull_request: + types: [ opened, reopened, synchronize ] + +permissions: {} + +# A newer push to a pull request cancels the run for its older commit; a push to master +# gets a group of its own (its commit), so the runs on master are never cancelled. +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.sha }} + cancel-in-progress: true + +jobs: + coverage: + name: Unit test coverage (GCC) + runs-on: ubuntu-24.04 + timeout-minutes: 60 + permissions: + contents: read + steps: + - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 + with: + submodules: recursive + + - name: Set up Python 3.14 + uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 + with: + python-version: '3.14' + + # the same packages as the Build workflow: the game is configured as a whole, + # though only the unit tests and the core library they link are built + - 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 + python3 -m pip install --no-cache-dir gcovr==8.3 + + - 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 + + # see the Build workflow + - 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 + + # unoptimised, so every line keeps its own code and the counts are those of the source + - name: Configure (CMake) + run: | + cmake -S . -B build \ + -DCMAKE_BUILD_TYPE=Debug \ + -DWITH_BETTER_RENDERER=OFF \ + -DWITH_ZMQ=OFF -DWITH_OPENVR=OFF -DUSE_LTO=OFF \ + -DCMAKE_CXX_FLAGS="--coverage -O0 -Wno-attributes -fno-inline-functions-called-once" \ + -DPython3_EXECUTABLE="$(which python3)" + + # the tests alone: the game itself isn't linked, so they aren't run by its build + - name: Build the unit tests + run: cmake --build build --target eu07_unit_tests -j"$(nproc)" + + - name: Run the unit tests + run: ./build/tests/unit/eu07_unit_tests + + # the game's own sources only: no submodules, no vendored code, not the tests themselves + - name: Coverage report + run: | + mkdir -p coverage-report/html + gcovr --root . build \ + --exclude 'ref/' --exclude 'imgui/' --exclude 'stb/' --exclude 'tests/' --exclude 'build/' \ + --gcov-ignore-parse-errors=negative_hits.warn_once_per_file \ + --gcov-ignore-errors=no_working_dir_found \ + --print-summary \ + --txt coverage-report/coverage.txt \ + --html-details coverage-report/html/index.html \ + --sonarqube coverage-report/coverage-sonarqube.xml \ + --json-summary-pretty --json-summary coverage-report/coverage-summary.json \ + | tee coverage-report/summary.txt + { + echo '## Unit test coverage of the core library' + echo + echo 'GCC, unoptimised build, `eu07_unit_tests`. Lines run by the tests, per source file of the game the tests compile.' + echo + echo '```' + grep -E '^(lines|functions|branches):' coverage-report/summary.txt + echo '```' + echo + echo '
Per file' + echo + echo '```' + cat coverage-report/coverage.txt + echo '```' + echo + echo '
' + } >> "$GITHUB_STEP_SUMMARY" + + - name: Upload the coverage report + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: unit-test-coverage + path: coverage-report + retention-days: 14 + if-no-files-found: error diff --git a/tests/unit/COVERAGE.md b/tests/unit/COVERAGE.md index aafcc27a6..03dfaca11 100644 --- a/tests/unit/COVERAGE.md +++ b/tests/unit/COVERAGE.md @@ -21,6 +21,8 @@ Coverage was measured on Windows with MSVC's SanitizerCoverage (`/fsanitize-cove The aim is branch coverage with the rest explained below, not 100%. +The numbers above are from 2026-11-01. Since then the **Coverage** workflow (`.github/workflows/coverage.yml`) measures every push and pull request: a GCC build of the unit tests with gcov, lines, functions and branches per source file of the core library. The totals and the per-file table are in the summary of the workflow run, and the HTML report with the lines marked is in its `unit-test-coverage` artifact. Its counts are source lines and gcov's branches, so they differ somewhat from the blocks in the table. The report isn't sent to SonarQube Cloud: the project's quality gate would then require 80% coverage of the new code of every pull request. + ## Code nothing in the game runs Nothing creates these objects or calls these functions anywhere in the game, which was checked against the whole source tree. A refactor can delete them, or leave them untested. From 4533fafd9365be47d61ba25eea22695b364e8b42 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 11 Nov 2026 11:02:59 +0100 Subject: [PATCH 2/6] ci: leave yaml-cpp out of the coverage report The first run of the Coverage workflow listed 66 files of betterRenderer/thirdparty/yaml-cpp, all at 0%: the library is linked by every target of the game, so it's built with the coverage flags as well. They made up 4388 of the 16592 lines and took the total from 84.4% to 62.1%. betterRenderer/ is excluded as it is in sonar-project.properties. --- .github/workflows/coverage.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4577e3795..802213970 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -90,12 +90,14 @@ jobs: - name: Run the unit tests run: ./build/tests/unit/eu07_unit_tests - # the game's own sources only: no submodules, no vendored code, not the tests themselves + # the game's own sources only: no submodules, no vendored code, not the tests themselves. + # betterRenderer/ is left out for its thirdparty/yaml-cpp, which every target of the game links and so builds here - name: Coverage report run: | mkdir -p coverage-report/html gcovr --root . build \ - --exclude 'ref/' --exclude 'imgui/' --exclude 'stb/' --exclude 'tests/' --exclude 'build/' \ + --exclude 'ref/' --exclude 'imgui/' --exclude 'stb/' --exclude 'betterRenderer/' \ + --exclude 'tests/' --exclude 'build/' \ --gcov-ignore-parse-errors=negative_hits.warn_once_per_file \ --gcov-ignore-errors=no_working_dir_found \ --print-summary \ From c008d0cdca9d745475b4ecc20f0fb05977b31ea7 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 11 Nov 2026 11:03:09 +0100 Subject: [PATCH 3/6] ci: fail the coverage report step when gcovr fails The step pipes gcovr into tee, and the default shell of a run step has no pipefail: an error of gcovr after it printed the totals would have left the step green with an incomplete report. --- .github/workflows/coverage.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 802213970..f580c5a16 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -94,6 +94,8 @@ jobs: # betterRenderer/ is left out for its thirdparty/yaml-cpp, which every target of the game links and so builds here - name: Coverage report run: | + # a failure of gcovr fails the step, though its output goes through tee + set -o pipefail mkdir -p coverage-report/html gcovr --root . build \ --exclude 'ref/' --exclude 'imgui/' --exclude 'stb/' --exclude 'betterRenderer/' \ From 666153473bbfc50f8bcfc8f6ea1a91ac0bad847d Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 11 Nov 2026 11:33:12 +0100 Subject: [PATCH 4/6] ci: install gcovr from wheels only SonarQube Cloud failed the quality gate of the pull request on this line (githubactions:S8541, a new vulnerability): without --only-binary :all: pip may run the setup script of a source package. gcovr 8.3 and its five dependencies all have wheels for Python 3.14 on Linux, as the first two runs show. --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index f580c5a16..b77c8494e 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -55,7 +55,7 @@ jobs: libpng-dev libopenal-dev libluajit-5.1-dev \ libserialport-dev libsndfile1-dev \ xorg-dev libxkbcommon-dev libwayland-dev wayland-protocols - python3 -m pip install --no-cache-dir gcovr==8.3 + python3 -m pip install --no-cache-dir --only-binary :all: gcovr==8.3 - name: Build current OpenAL Soft run: | From 33cedc45a54530c214a20ca60007ed53a14e004c Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 11 Nov 2026 11:33:12 +0100 Subject: [PATCH 5/6] docs: the Coverage workflow runs on pull requests and on pushes to master COVERAGE.md said every push; a push to another branch without a pull request isn't measured. --- tests/unit/COVERAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/COVERAGE.md b/tests/unit/COVERAGE.md index 03dfaca11..3ed9d14e8 100644 --- a/tests/unit/COVERAGE.md +++ b/tests/unit/COVERAGE.md @@ -21,7 +21,7 @@ Coverage was measured on Windows with MSVC's SanitizerCoverage (`/fsanitize-cove The aim is branch coverage with the rest explained below, not 100%. -The numbers above are from 2026-11-01. Since then the **Coverage** workflow (`.github/workflows/coverage.yml`) measures every push and pull request: a GCC build of the unit tests with gcov, lines, functions and branches per source file of the core library. The totals and the per-file table are in the summary of the workflow run, and the HTML report with the lines marked is in its `unit-test-coverage` artifact. Its counts are source lines and gcov's branches, so they differ somewhat from the blocks in the table. The report isn't sent to SonarQube Cloud: the project's quality gate would then require 80% coverage of the new code of every pull request. +The numbers above are from 2026-11-01. Since then the **Coverage** workflow (`.github/workflows/coverage.yml`) measures every pull request and every push to master: a GCC build of the unit tests with gcov, lines, functions and branches per source file of the core library. The totals and the per-file table are in the summary of the workflow run, and the HTML report with the lines marked is in its `unit-test-coverage` artifact. Its counts are source lines and gcov's branches, so they differ somewhat from the blocks in the table. The report isn't sent to SonarQube Cloud: the project's quality gate would then require 80% coverage of the new code of every pull request. ## Code nothing in the game runs From e64546385bef936373def01d463fc11c5a93984a Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 11 Nov 2026 14:26:41 +0100 Subject: [PATCH 6/6] ci: pin actions/checkout in the Coverage workflow to v6.1.0, as in build_bin.yml --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index b77c8494e..d2f00bccd 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -35,7 +35,7 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 with: submodules: recursive