Skip to content

Commit f41b73b

Browse files
committed
Improvements on CI/CD
1 parent f9de4ab commit f41b73b

5 files changed

Lines changed: 764 additions & 81 deletions

File tree

Lines changed: 137 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
# This is a basic workflow that is manually triggered
2-
1+
# ─────────────────────────────────────────────────────────────────────────────
2+
# CXXGraph – Code Coverage
3+
#
4+
# Generates an LCOV / gcovr HTML report and uploads to Codecov.
5+
# Runs on: Ubuntu 24.04 + GCC 14 (latest stable toolchain with best gcov support)
6+
#
7+
# Two modes:
8+
# • push → upload to Codecov (requires CODECOV_TOKEN secret)
9+
# • PR → generate report & attach as artifact (no token needed)
10+
# ─────────────────────────────────────────────────────────────────────────────
311
name: Code Coverage
412

513
on:
@@ -11,51 +19,145 @@ on:
1119
permissions:
1220
contents: read
1321

22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
env:
27+
CPM_SOURCE_CACHE: ~/.cache/cpm
28+
1429
jobs:
15-
codacy-coverage-reporter:
16-
runs-on: ubuntu-latest
17-
name: codecov-coverage-reporter
30+
coverage:
31+
name: "Coverage · GCC 14 · C++17"
32+
runs-on: ubuntu-24.04
33+
timeout-minutes: 30
34+
1835
steps:
19-
#- name: Install gtest manually
20-
# run: sudo apt-get install libgtest-dev
2136

22-
#- name: Install benchmark manually
23-
# run: |
24-
# git clone https://github.com/google/benchmark.git
25-
# git clone https://github.com/google/googletest.git benchmark/googletest
26-
# cd benchmark
27-
# cmake -E make_directory "build"
28-
# cmake -E chdir "build" cmake -DCMAKE_BUILD_TYPE=Release ../
29-
# cmake --build "build" --config Release
30-
# sudo cmake --build "build" --config Release --target install
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 1
3141

32-
- name: Update apt repo
33-
run: sudo apt-get update
42+
# ── Toolchain ─────────────────────────────────────────────────────
43+
- name: Install dependencies
44+
run: |
45+
sudo apt-get update -q
46+
sudo apt-get install -y --no-install-recommends \
47+
gcc-14 g++-14 lcov gcovr ninja-build
3448
35-
- name: Install tools manually
36-
run: sudo apt-get install lcov gcovr
49+
- name: Install Ninja
50+
uses: seanmiddleditch/gha-setup-ninja@v5
3751

38-
- uses: actions/checkout@v6
52+
# ── CPM cache ─────────────────────────────────────────────────────
53+
- name: Cache CPM packages
54+
uses: actions/cache@v4
55+
with:
56+
path: ~/.cache/cpm
57+
key: cpm-ubuntu-coverage-${{ hashFiles('**/CMakeLists.txt') }}
58+
restore-keys: cpm-ubuntu-coverage-
3959

60+
# ── Configure ─────────────────────────────────────────────────────
4061
- name: Configure CMake
41-
run: cmake -DTEST=ON -DCODE_COVERAGE=ON -B ${{github.workspace}}/build; sudo apt-get install lcov gcovr
62+
env:
63+
CC: gcc-14
64+
CXX: g++-14
65+
run: |
66+
cmake -B build \
67+
-G Ninja \
68+
-DCMAKE_BUILD_TYPE=Debug \
69+
-DCMAKE_CXX_STANDARD=17 \
70+
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
71+
-DCMAKE_CXX_EXTENSIONS=OFF \
72+
-DTEST=ON \
73+
-DCODE_COVERAGE=ON
4274
75+
# ── Build & run tests ─────────────────────────────────────────────
4376
- name: Build
44-
# Build your program with the given configuration
45-
run: cmake --build ${{github.workspace}}/build
77+
run: cmake --build build --parallel
4678

47-
- name: run
48-
working-directory: ${{github.workspace}}/build/test
79+
- name: Run tests
80+
working-directory: build/test
4981
run: ./test_exe
5082

51-
- name: create Report
52-
working-directory: ${{github.workspace}}/build/test
53-
run: lcov --capture --directory .. --output-file coverage.info --ignore-errors mismatch
83+
# ── Generate LCOV report ──────────────────────────────────────────
84+
- name: Capture coverage data
85+
working-directory: build
86+
run: |
87+
lcov \
88+
--capture \
89+
--directory . \
90+
--output-file coverage_raw.info \
91+
--ignore-errors mismatch \
92+
--gcov-tool gcov-14
93+
94+
- name: Remove noise (system / third-party headers)
95+
working-directory: build
96+
run: |
97+
lcov \
98+
--remove coverage_raw.info \
99+
'/usr/*' \
100+
'*/googletest/*' \
101+
'*/googlemock/*' \
102+
'*/zlib/*' \
103+
'*/test/*' \
104+
'*/benchmark/*' \
105+
'*/CPM_packages/*' \
106+
--output-file coverage.info \
107+
--ignore-errors unused
108+
109+
- name: Show coverage summary
110+
working-directory: build
111+
run: lcov --summary coverage.info
112+
113+
# ── Generate browsable HTML report ────────────────────────────────
114+
- name: Generate HTML report
115+
working-directory: build
116+
run: |
117+
genhtml coverage.info \
118+
--output-directory coverage_html \
119+
--title "CXXGraph Coverage" \
120+
--legend \
121+
--show-details \
122+
--highlight
123+
124+
# ── Also generate gcovr XML (for tooling / IDE integrations) ──────
125+
- name: Generate gcovr XML
126+
working-directory: build
127+
run: |
128+
gcovr \
129+
--root .. \
130+
--exclude '.*googletest.*' \
131+
--exclude '.*googlemock.*' \
132+
--exclude '.*zlib.*' \
133+
--exclude '.*test.*' \
134+
--exclude '.*CPM_packages.*' \
135+
--xml coverage.xml \
136+
--xml-pretty
137+
138+
# ── Upload to Codecov ─────────────────────────────────────────────
139+
- name: Upload to Codecov
140+
uses: codecov/codecov-action@v5
141+
with:
142+
token: ${{ secrets.CODECOV_TOKEN }}
143+
files: build/coverage.info
144+
flags: unittests
145+
name: codecov-umbrella
146+
fail_ci_if_error: true
147+
148+
# ── Attach HTML report as artifact (always, useful on PRs) ────────
149+
- name: Upload HTML coverage report
150+
if: always()
151+
uses: actions/upload-artifact@v4
152+
with:
153+
name: coverage-report-html
154+
path: build/coverage_html/
155+
retention-days: 14
54156

55-
- uses: codecov/codecov-action@v5.5.2
157+
- name: Upload LCOV file
158+
if: always()
159+
uses: actions/upload-artifact@v4
56160
with:
57-
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
58-
file: ${{github.workspace}}/build/test/coverage.info # optional
59-
flags: unittests # optional
60-
name: codecov-umbrella # optional
61-
fail_ci_if_error: true # optional (default = false)
161+
name: coverage-lcov
162+
path: build/coverage.info
163+
retention-days: 14

0 commit comments

Comments
 (0)