Add code coverage as PR comment (#1162)

* Add code coverage as PR comment

* Workaround for test coverage permission issue
This commit is contained in:
Eric Gregory authored and GitHub committed 2026-02-26 20:39:26 -05:00
1 parent b6c96133c6
commit 351e48013c
3 files changed
+68 -2

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
name: coverage-comment
on:
workflow_run:
workflows: [test]
types: [completed]
jobs:
comment:
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
name: coverage
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Post coverage comment
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
PR=$(cat pr_number.txt)
{
echo "## Test Coverage"
echo ""
echo '```'
cat coverage_summary.txt
echo '```'
} > comment_body.md
gh pr comment "$PR" --body-file comment_body.md
+25 -2
View File
@@ -17,11 +17,11 @@ jobs:
- name: Install build dependencies from debian/control
run: |
sudo apt-get update
sudo apt-get install --yes devscripts equivs ninja-build
sudo apt-get install --yes devscripts equivs ninja-build lcov
sudo mk-build-deps -i -r -t "apt-get --yes" debian/control
- name: Configure
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DUSE_STATIC_MPVQT=ON
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DUSE_STATIC_MPVQT=ON -DCOVERAGE=ON
- name: Build
run: cmake --build build
@@ -30,3 +30,26 @@ jobs:
run: |
cd build
ctest --output-on-failure
- name: Collect coverage
run: |
lcov --capture --directory build --output-file coverage.info \
--ignore-errors mismatch
lcov --remove coverage.info \
'/usr/*' '*/external/*' '*/tests/*' '*/build/*' \
--output-file coverage.info \
--ignore-errors unused
lcov --summary coverage.info 2>&1 | grep -v 'no data found' > coverage_summary.txt
- name: Save PR number
if: github.event_name == 'pull_request'
run: echo "${{ github.event.pull_request.number }}" > pr_number.txt
- name: Upload coverage artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: coverage
path: |
coverage_summary.txt
pr_number.txt
+6
View File
@@ -15,6 +15,7 @@ option(OPENELEC "Make an OpenELEC build" OFF)
option(LINUX_X11POWER "Enable non D-Bus screensaver management" OFF)
option(USE_STATIC_MPVQT "Build MpvQt from bundled submodule instead of using system library" OFF)
option(MACOS_LAUNCH_WRAPPER "Wrap macOS binary in a shell script to block DYLD_FRAMEWORK_PATH injection" OFF)
option(COVERAGE "Gemerate test code coverage with gcov" OFF)
if (NOT CHECK_FOR_UPDATES)
add_definitions(-DDISABLE_UPDATE_CHECK)
@@ -35,6 +36,11 @@ if(BUILD_TARGET STREQUAL "RPI")
Message(STATUS "Build for Raspberry PI target")
endif(BUILD_TARGET STREQUAL "RPI")
if(COVERAGE)
add_compile_options(--coverage -fno-inline)
add_link_options(--coverage)
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME Core)