Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage analysis #5

Merged
merged 4 commits into from
Dec 4, 2023
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
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DBUILD_TESTING=ON
-DBUILD_TESTING=ON
-DCODE_COVERAGE=OFF
--toolchain=conan_toolchain.cmake
-S ${{ github.workspace }}

Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Coverage

on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches:
- "master"
- "develop"
pull_request:
branches:
- "master"
- "develop"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: 🔧 Install GCC
uses: egor-tensin/[email protected]
with:
version: 13

- name: 🔧 Setup python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: pip

- name: ☁️ Install required packages
run: |
sudo apt-get install -y lcov
pip install -r requirements.txt

- name: 🐸 Create default Conan profile
run: conan profile detect

- name: ☁️ Get dependencies
run: conan install ${{ github.workspace }} --build=missing --output-folder=build --settings compiler.cppstd=20

- name: 🛠️ Configure CMake
run: >
cmake -B build
-DCMAKE_BUILD_TYPE=Release
-DBUILD_TESTING=ON
-DCODE_COVERAGE=ON
--toolchain=conan_toolchain.cmake
-S ${{ github.workspace }}

- name: 🔨 Build project
run: cmake --build build --config Release --parallel

- name: 🏃 Run test suite
working-directory: build
run: ctest --build-config Release

- name: 📊 Generate coverage reports with lcov
run: |
lcov --directory . --capture --output-file coverage.info --gcov-tool gcov-13
lcov --remove coverage.info '/usr/*' --remove coverage.info '**/.conan*' --remove coverage.info '**/test*' --output-file coverage.info
lcov --list coverage.info

- name: ☂️ Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ project(cppIni LANGUAGES CXX VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(BUILD_TESTING ON "Build test files")
option(BUILD_SHARED_LIBS ON "Build shared library files")
option(BUILD_TESTING "Build test files" ON)
option(BUILD_SHARED_LIBS "Build shared library files" ON)
option(CODE_COVERAGE "Enable coverage reporting" OFF)

include(cmake/CodeCoverage.cmake)
add_subdirectory(src)

if(BUILD_TESTING)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# cppIni - A C++20 library for reading and writing INI files

Branch | Status | Coverage
--- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---
`master` | [![Build](https://github.com/Master92/cppIni/actions/workflows/build.yaml/badge.svg?branch=master)](https://github.com/Master92/cppIni/actions/workflows/build.yaml) | [![codecov](https://codecov.io/gh/Master92/cppIni/\branch/master/graph/badge.svg?token=V66BUECAMV)](https://codecov.io/gh/Master92/cppIni)
`develop` | [![Build](https://github.com/Master92/cppIni/actions/workflows/build.yaml/badge.svg?branch=develop)](https://github.com/Master92/cppIni/actions/workflows/build.yaml) | [![codecov](https://codecov.io/gh/Master92/cppIni/\branch/develop/graph/badge.svg?token=V66BUECAMV)](https://codecov.io/gh/Master92/cppIni)
[![Release](https://img.shields.io/github/v/tag/Master92/cppIni?label=release)](https://github.com/Master92/cppIni/releases)
[![Build](https://img.shields.io/github/actions/workflow/status/Master92/cppIni/build.yaml?logo=github)](https://github.com/Master92/cppIni/actions/workflows/build.yaml)

![License](https://img.shields.io/github/license/Master92/cppIni)
![GitHub stars](https://img.shields.io/github/stars/Master92/cppIni?label=%E2%AD%90%20Stars)

Expand Down
13 changes: 13 additions & 0 deletions cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.24)

# Code coverage configuration
add_library(coverage_config INTERFACE)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message("Enabling code coverage")
target_compile_options(coverage_config INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
target_link_options(coverage_config INTERFACE --coverage)
endif()
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(PRIVATE_HEADERS
)

add_library(${PROJECT_NAME} ${SOURCES} ${API_HEADERS} ${PRIVATE_HEADERS})
target_link_libraries(${PROJECT_NAME} PUBLIC coverage_config)

include(GenerateExportHeader)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
Expand Down