-
Notifications
You must be signed in to change notification settings - Fork 2
61 lines (50 loc) · 1.75 KB
/
coverage.yml
File metadata and controls
61 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Code Coverage
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y lcov cmake ninja-build g++ libgtest-dev
- name: Configure project with coverage flags
run: cmake -B build -DENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug -G Ninja
- name: Build the project
run: cmake --build build
- name: Run tests
run: cd build && ctest --output-on-failure
- name: Generate coverage report
run: |
cd build
lcov --directory . --capture --output-file coverage.info \
--rc geninfo_auto_base=1 --ignore-errors mismatch
lcov --remove coverage.info '/usr/*' '*/tests/*' --output-file coverage.filtered.info
genhtml coverage.filtered.info --output-directory coverage-report
- name: Show coverage summary
run: |
cd build
lcov --summary coverage.filtered.info
- name: Upload coverage report as artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: build/coverage-report
- name: Enforce coverage threshold
run: |
cd build
THRESHOLD=100
COVERAGE=$(lcov --summary coverage.filtered.info | grep "lines" | awk '{ print $2 }' | sed 's/%//')
echo "Total coverage: $COVERAGE%"
if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
echo "❌ Coverage below threshold of ${THRESHOLD}%"
exit 1
else
echo "✅ Coverage is above threshold"
fi