Skip to content

Commit 69c0ab2

Browse files
kkaeferclaude
andcommitted
Add code coverage testing with lcov to GitHub Actions
Add a dedicated Coverage job that: - Uses g++ with --coverage flag for comprehensive coverage collection - Installs and configures lcov for coverage data processing - Filters coverage to focus on main library headers (include/*) - Excludes system headers, vendor files, tests, and build artifacts - Generates HTML coverage reports with titles and legends - Uploads results to Codecov for PR comments and online tracking - Provides downloadable coverage artifacts as backup The coverage job runs independently of main builds to avoid performance overhead while providing detailed coverage metrics and PR feedback. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 6bb9732 commit 69c0ab2

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

.github/workflows/build.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,94 @@ jobs:
6464
- name: Run tests
6565
run: build/tests
6666

67+
Coverage:
68+
runs-on: ubuntu-latest
69+
70+
container:
71+
image: ubuntu:24.04
72+
73+
env:
74+
CXX: g++
75+
DEBIAN_FRONTEND: noninteractive
76+
77+
permissions:
78+
contents: read
79+
id-token: write
80+
81+
steps:
82+
- name: Update Git
83+
run: |
84+
apt-get update
85+
apt-get install -y git
86+
git --version
87+
88+
- name: Checkout repository
89+
uses: actions/checkout@v5
90+
with:
91+
submodules: true
92+
93+
- name: Install dependencies
94+
run: |
95+
apt-get install -y cmake ninja-build g++ xorg-dev lcov
96+
g++ --version
97+
cmake --version
98+
ninja --version
99+
lcov --version
100+
101+
- name: Create build directory
102+
run: mkdir -p build
103+
shell: bash
104+
105+
- name: Configure CMake for coverage
106+
working-directory: build
107+
run: cmake .. -GNinja -DCMAKE_CXX_FLAGS="--coverage" -DCMAKE_BUILD_TYPE=Debug
108+
109+
- name: Build all targets
110+
working-directory: build
111+
run: ninja
112+
113+
- name: Run tests
114+
run: build/tests
115+
116+
- name: Generate coverage report
117+
run: |
118+
# Create coverage directory
119+
mkdir -p coverage
120+
121+
# Capture coverage data
122+
lcov --capture --directory build --output-file coverage/coverage_raw.info
123+
124+
# Remove system headers, vendor files, and test files from coverage
125+
lcov --remove coverage/coverage_raw.info '/usr/*' --output-file coverage/coverage.info
126+
lcov --remove coverage/coverage.info '*/vendor/*' --output-file coverage/coverage.info
127+
lcov --remove coverage/coverage.info '*/test/*' --output-file coverage/coverage.info
128+
lcov --remove coverage/coverage.info '*/build/*' --output-file coverage/coverage.info
129+
lcov --remove coverage/coverage.info '*/CMakeFiles/*' --output-file coverage/coverage.info
130+
131+
# Only include our main header files
132+
lcov --extract coverage/coverage.info '*/include/*' --output-file coverage/coverage.info
133+
134+
# Generate HTML report
135+
genhtml coverage/coverage.info --output-directory coverage/html --title "Earcut.hpp Coverage Report" --legend
136+
137+
# Show summary
138+
lcov --summary coverage/coverage.info
139+
140+
- name: Upload coverage to Codecov
141+
uses: codecov/codecov-action@v4
142+
with:
143+
file: coverage/coverage.info
144+
flags: unittests
145+
name: codecov-umbrella
146+
fail_ci_if_error: false
147+
verbose: true
148+
149+
- name: Upload coverage reports as artifact
150+
uses: actions/upload-artifact@v4
151+
with:
152+
name: coverage-report
153+
path: coverage/
154+
67155
MacOS:
68156
strategy:
69157
fail-fast: false

0 commit comments

Comments
 (0)