diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index cb4a048..5fcb448 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 }} diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml new file mode 100644 index 0000000..135984f --- /dev/null +++ b/.github/workflows/coverage.yaml @@ -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/setup-gcc@v1.3 + 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 }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 772e787..f1da020 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index d13d668..c6867d2 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake new file mode 100644 index 0000000..6b3a811 --- /dev/null +++ b/cmake/CodeCoverage.cmake @@ -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() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 268dd6c..1cd90d7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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)