Skip to content

Commit c336632

Browse files
facontidavideclaude
andcommitted
Add code coverage job with Codecov upload and workflow_dispatch trigger
- Add workflow_dispatch trigger to enable manual runs via `gh workflow run` - Add separate `coverage` job that builds in Debug mode with `--coverage` flags - Use lcov to collect and filter coverage data (excludes 3rdparty, tests, examples) - Upload coverage.info to Codecov using CODECOV_TOKEN secret - Keep existing Release build job unchanged Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b3dbe30 commit c336632

File tree

1 file changed

+53
-7
lines changed

1 file changed

+53
-7
lines changed

.github/workflows/cmake_ubuntu.yml

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ on:
66
- master
77
pull_request:
88
types: [opened, synchronize, reopened]
9+
workflow_dispatch:
910

1011
env:
11-
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
1212
BUILD_TYPE: Release
1313

1414
jobs:
1515
build:
16-
# The CMake configure and build commands are platform agnostic and should work equally
17-
# well on Windows or Mac. You can convert this to a matrix build if you need
18-
# cross-platform coverage.
19-
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
2016
runs-on: ${{ matrix.os }}
2117
strategy:
2218
matrix:
@@ -37,8 +33,6 @@ jobs:
3733

3834
- name: Normalize build type
3935
shell: bash
40-
# The build type is Capitalized, e.g. Release, but the preset is all lowercase, e.g. release.
41-
# There is no built in way to do string manipulations on GHA as far as I know.`
4236
run: echo "BUILD_TYPE_LOWERCASE=$(echo "${BUILD_TYPE}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
4337

4438
- name: Configure CMake
@@ -52,5 +46,57 @@ jobs:
5246
- name: run test (Linux)
5347
run: ctest --test-dir build/${{env.BUILD_TYPE}}
5448

49+
coverage:
50+
runs-on: ubuntu-22.04
51+
52+
steps:
53+
- uses: actions/checkout@v6
54+
55+
- name: Install lcov
56+
run: sudo apt-get update && sudo apt-get install -y lcov
57+
58+
- name: Install Conan
59+
id: conan
60+
uses: turtlebrowser/get-conan@main
61+
62+
- name: Create default profile
63+
run: conan profile detect
64+
65+
- name: Install conan dependencies
66+
run: conan install conanfile.py -s build_type=Debug --build=missing
67+
68+
- name: Configure CMake with coverage
69+
shell: bash
70+
run: |
71+
cmake --preset conan-debug \
72+
-DCMAKE_C_FLAGS="--coverage" \
73+
-DCMAKE_CXX_FLAGS="--coverage"
74+
75+
- name: Build
76+
shell: bash
77+
run: cmake --build --preset conan-debug
78+
79+
- name: Run tests
80+
run: ctest --test-dir build/Debug --output-on-failure
81+
82+
- name: Collect coverage
83+
run: |
84+
lcov --capture --directory build/Debug \
85+
--output-file coverage.info \
86+
--ignore-errors mismatch
87+
lcov --remove coverage.info \
88+
'/usr/*' \
89+
'*/3rdparty/*' \
90+
'*/tests/*' \
91+
'*/examples/*' \
92+
'*/sample_nodes/*' \
93+
'*/tools/*' \
94+
--output-file coverage.info \
95+
--ignore-errors unused
96+
lcov --list coverage.info
97+
5598
- name: Upload coverage reports to Codecov
5699
uses: codecov/codecov-action@v5
100+
with:
101+
files: coverage.info
102+
token: ${{ secrets.CODECOV_TOKEN }}

0 commit comments

Comments
 (0)