Skip to content

Commit 32d17c5

Browse files
set up code coverage
1 parent 2325508 commit 32d17c5

6 files changed

Lines changed: 57 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,33 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0 # Essential for SonarCloud to see history/blame
1416

1517
- name: Install Dependencies
1618
run: |
1719
sudo apt-get update
1820
sudo apt-get install -y cmake g++ libopencv-dev
21+
pip install gcovr==8.6
1922
20-
- name: Cache GoogleTest
21-
id: cache-gtest
22-
uses: actions/cache@v4
23-
with:
24-
path: build/_deps
25-
# If you change the GTest version, the hash changes and the cache clears
26-
key: ${{ runner.os }}-gtest-${{ hashFiles('core/tests/CMakeLists.txt') }}
27-
restore-keys: |
28-
${{ runner.os }}-gtest-
23+
# Use a dedicated directory for build wrapper output
24+
# This replaces the old 'build-wrapper-action'
25+
- name: Install Build Wrapper
26+
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9
2927

30-
- name: Configure and Build
28+
- name: Run Build Wrapper
3129
run: |
32-
# -B creates the build folder if it doesn't exist
33-
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
34-
cmake --build build --config Release -j $(nproc)
30+
build-wrapper-linux-x86-64 --out-dir bw-output make coverage
3531
36-
- name: Run Tests
37-
run: |
38-
cd build
39-
ctest --output-on-failure
32+
- name: SonarCloud Scan
33+
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
37+
with:
38+
args: >
39+
-Dsonar.cfamily.build-wrapper-output=bw-output
40+
-Dsonar.coverageReportPaths=coverage.xml
4041
4142
build-web:
4243
runs-on: ubuntu-latest

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
core/build/
33
core/images/
44
build/
5-
images/
5+
images/
6+
coverage.xml

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
1414
# --- Testing ---
1515
enable_testing()
1616

17+
# --- Coverage ---
18+
option(ENABLE_COVERAGE "Enable code coverage" OFF)
19+
if(ENABLE_COVERAGE)
20+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
21+
add_compile_options(--coverage -O0 -g)
22+
add_link_options(--coverage)
23+
endif()
24+
endif()
25+
1726
# --- Subdirectories ---
1827
add_subdirectory(core)
1928
add_subdirectory(apps/native)

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ test:
5959
@cd build && cmake .. && make -j$(NPROCS)
6060
@cd build && ctest --output-on-failure
6161

62+
# 5. Coverage
63+
coverage:
64+
@echo "📊 Generating Coverage..."
65+
@mkdir -p build
66+
@find build -name "*.gcda" -delete
67+
@cd build && cmake .. -DENABLE_COVERAGE=ON && make -j$(NPROCS)
68+
@cd build && ctest --output-on-failure
69+
@echo "📈 Generating Sonar-compatible XML report..."
70+
# In gcovr 8.6, we use the search path at the end instead of --build-root
71+
gcovr --sonarqube -o coverage.xml -r . --filter core/src/ -e build/ --gcov-ignore-parse-errors=all build
72+
6273
# ------------------------------------
6374
# 🧹 CLEANUP
6475
# ------------------------------------

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Codec Explorer
22

3-
[![Build Status](https://github.com/thundermage117/codec/actions/workflows/ci.yml/badge.svg)](https://github.com/thundermage117/codec/actions/workflows/ci.yml) [![License: GPL v3](https://img.shields.io/badge/License-GPL_v3-blue.svg)](LICENSE) [![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=thundermage117_codec)](https://sonarcloud.io/summary/new_code?id=thundermage117_codec)
3+
[![Build Status](https://github.com/thundermage117/codec/actions/workflows/ci.yml/badge.svg)](https://github.com/thundermage117/codec/actions/workflows/ci.yml) [![License: GPL v3](https://img.shields.io/badge/License-GPL_v3-blue.svg)](LICENSE) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=thundermage117_codec&metric=coverage)](https://sonarcloud.io/summary/new_code?id=thundermage117_codec) [![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=thundermage117_codec)](https://sonarcloud.io/summary/new_code?id=thundermage117_codec)
44

55
An interactive codec laboratory to visualize how transform-based image compression works. The C++ core is compiled to WebAssembly, allowing for real-time, in-browser experimentation.
66

sonar-project.properties

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sonar.projectKey=thundermage117_codec
2+
sonar.organization=thundermage117
3+
4+
# Sources and Tests
5+
sonar.sources=core/src,apps/native,web/src
6+
sonar.tests=core/tests
7+
sonar.sourceEncoding=UTF-8
8+
9+
# C++ Analysis Requirements
10+
sonar.cfamily.build-wrapper-output=bw-output
11+
12+
# Use the XML report generated by gcovr in your GitHub Action
13+
sonar.coverageReportPaths=coverage.xml
14+
15+
# Exclusions to keep the noise down
16+
sonar.exclusions=web/public/**, build/**, images/**, _deps/**

0 commit comments

Comments
 (0)