Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 137 additions & 35 deletions .github/workflows/Code_Coverage.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# This is a basic workflow that is manually triggered

# ─────────────────────────────────────────────────────────────────────────────
# CXXGraph – Code Coverage
#
# Generates an LCOV / gcovr HTML report and uploads to Codecov.
# Runs on: Ubuntu 24.04 + GCC 14 (latest stable toolchain with best gcov support)
#
# Two modes:
# • push → upload to Codecov (requires CODECOV_TOKEN secret)
# • PR → generate report & attach as artifact (no token needed)
# ─────────────────────────────────────────────────────────────────────────────
name: Code Coverage

on:
Expand All @@ -11,51 +19,145 @@ on:
permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CPM_SOURCE_CACHE: ~/.cache/cpm

jobs:
codacy-coverage-reporter:
runs-on: ubuntu-latest
name: codecov-coverage-reporter
coverage:
name: "Coverage · GCC 14 · C++17"
runs-on: ubuntu-24.04
timeout-minutes: 30

steps:
#- name: Install gtest manually
# run: sudo apt-get install libgtest-dev

#- name: Install benchmark manually
# run: |
# git clone https://github.com/google/benchmark.git
# git clone https://github.com/google/googletest.git benchmark/googletest
# cd benchmark
# cmake -E make_directory "build"
# cmake -E chdir "build" cmake -DCMAKE_BUILD_TYPE=Release ../
# cmake --build "build" --config Release
# sudo cmake --build "build" --config Release --target install
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Update apt repo
run: sudo apt-get update
# ── Toolchain ─────────────────────────────────────────────────────
- name: Install dependencies
run: |
sudo apt-get update -q
sudo apt-get install -y --no-install-recommends \
gcc-14 g++-14 lcov gcovr ninja-build

- name: Install tools manually
run: sudo apt-get install lcov gcovr
- name: Install Ninja
uses: seanmiddleditch/gha-setup-ninja@v5

- uses: actions/checkout@v6
# ── CPM cache ─────────────────────────────────────────────────────
- name: Cache CPM packages
uses: actions/cache@v4
with:
path: ~/.cache/cpm
key: cpm-ubuntu-coverage-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: cpm-ubuntu-coverage-

# ── Configure ─────────────────────────────────────────────────────
- name: Configure CMake
run: cmake -DTEST=ON -DCODE_COVERAGE=ON -B ${{github.workspace}}/build; sudo apt-get install lcov gcovr
env:
CC: gcc-14
CXX: g++-14
run: |
cmake -B build \
-G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_CXX_EXTENSIONS=OFF \
-DTEST=ON \
-DCODE_COVERAGE=ON

# ── Build & run tests ─────────────────────────────────────────────
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build
run: cmake --build build --parallel

- name: run
working-directory: ${{github.workspace}}/build/test
- name: Run tests
working-directory: build/test
run: ./test_exe

- name: create Report
working-directory: ${{github.workspace}}/build/test
run: lcov --capture --directory .. --output-file coverage.info --ignore-errors mismatch
# ── Generate LCOV report ──────────────────────────────────────────
- name: Capture coverage data
working-directory: build
run: |
lcov \
--capture \
--directory . \
--output-file coverage_raw.info \
--ignore-errors mismatch \
--gcov-tool gcov-14

- name: Remove noise (system / third-party headers)
working-directory: build
run: |
lcov \
--remove coverage_raw.info \
'/usr/*' \
'*/googletest/*' \
'*/googlemock/*' \
'*/zlib/*' \
'*/test/*' \
'*/benchmark/*' \
'*/CPM_packages/*' \
--output-file coverage.info \
--ignore-errors unused

- name: Show coverage summary
working-directory: build
run: lcov --summary coverage.info

# ── Generate browsable HTML report ────────────────────────────────
- name: Generate HTML report
working-directory: build
run: |
genhtml coverage.info \
--output-directory coverage_html \
--title "CXXGraph Coverage" \
--legend \
--show-details \
--highlight

# ── Also generate gcovr XML (for tooling / IDE integrations) ──────
- name: Generate gcovr XML
working-directory: build
run: |
gcovr \
--root .. \
--exclude '.*googletest.*' \
--exclude '.*googlemock.*' \
--exclude '.*zlib.*' \
--exclude '.*test.*' \
--exclude '.*CPM_packages.*' \
--xml coverage.xml \
--xml-pretty

# ── Upload to Codecov ─────────────────────────────────────────────
- name: Upload to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build/coverage.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true

# ── Attach HTML report as artifact (always, useful on PRs) ────────
- name: Upload HTML coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report-html
path: build/coverage_html/
retention-days: 14

- uses: codecov/codecov-action@v5.5.2
- name: Upload LCOV file
if: always()
uses: actions/upload-artifact@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
file: ${{github.workspace}}/build/test/coverage.info # optional
flags: unittests # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
name: coverage-lcov
path: build/coverage.info
retention-days: 14
Loading
Loading