18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 22:07:55 +01:00
Files
maszyna/.github/workflows/coverage.yml
T
jerrrrycho 8038e4df37 Merge staging into build/ci-compiler-cache-master
# Conflicts:
#	.github/workflows/build.yml
#	.github/workflows/build_bin.yml
2026-11-29 11:46:35 +01:00

180 lines
7.4 KiB
YAML

# .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:
# A pull request that changes only documentation or the scenario tests (cases and their runner, which aren't built)
# doesn't need the coverage build. The check is a job-level
# condition, not `paths-ignore` on the trigger: a workflow that doesn't start leaves a required check "pending"
# for ever, while a skipped job (its name is fixed) counts as passed. A push, and anything this step can't
# decide, runs the build.
changes:
name: Which files changed
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
pull-requests: read
outputs:
code: ${{ steps.files.outputs.code }}
steps:
- name: List the changed files
id: files
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
if [ "$EVENT_NAME" != pull_request ]; then
echo "code=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if ! files="$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" --jq '.[] | .filename, (.previous_filename // empty)')" || [ -z "$files" ]; then
echo "The list of changed files is not available, building."
echo "code=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# what is not built: *.md, docs/, LICENSE and tests/scenarios/ (not *.txt: CMakeLists.txt is code)
if printf '%s\n' "$files" | grep -Evq '(\.md$|^docs/|^LICENSE|^tests/scenarios/)'; then
echo "code=true" >> "$GITHUB_OUTPUT"
else
echo "Only documentation or scenario tests changed, the coverage build is skipped."
echo "code=false" >> "$GITHUB_OUTPUT"
fi
coverage:
name: Unit test coverage (GCC)
needs: changes
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 60
permissions:
contents: read
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.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
timeout-minutes: 15
uses: ./.github/actions/apt-install
with:
packages: >-
build-essential pkg-config
libgl1-mesa-dev libglew-dev libglfw3-dev
libpng-dev libopenal-dev libluajit-5.1-dev
libserialport-dev libsndfile1-dev
libx11-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxrandr-dev
libxkbcommon-dev libwayland-dev wayland-protocols
- name: Install gcovr
run: |
python3 -m pip install --no-cache-dir --only-binary :all: 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_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: |
# 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 '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 '<details><summary>Per file</summary>'
echo
echo '```'
cat coverage-report/coverage.txt
echo '```'
echo
echo '</details>'
} >> "$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