Skip to content

Commit

Permalink
ci: Fix code coverage and publish on Codecov (cieslarmichal#773)
Browse files Browse the repository at this point in the history
* Add codecov support

Signed-off-by: Uilian Ries <[email protected]>

* Add codecov to analysis

Signed-off-by: Uilian Ries <[email protected]>

* Check library coverage

Signed-off-by: Uilian Ries <[email protected]>

* Add codecov to analysis

Signed-off-by: Uilian Ries <[email protected]>

* update coverage option

Signed-off-by: Uilian Ries <[email protected]>

* Fix code coverage steps

Signed-off-by: Uilian Ries <[email protected]>

---------

Signed-off-by: Uilian Ries <[email protected]>
  • Loading branch information
uilianries authored Jul 2, 2024
1 parent bd02a42 commit 467f9d4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/linux-clang-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ jobs:
run: |
cmake --build --preset=unixlike-clang-debug-${{ matrix.type }} --target run-faker-cxx-basic-example \
&& cmake --build --preset=unixlike-clang-debug-${{ matrix.type }} --target run-faker-cxx-person-example
- name: Code coverage
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
17 changes: 13 additions & 4 deletions .github/workflows/linux-static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,25 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE=build/Debug/generators/conan_toolchain.cmake \
-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld
- name: Build
- name: Build library and tests
run: cmake --build --preset=unixlike-clang-debug-static

- name: Generate code coverage
- name: Build code coverage
run: cmake --build --preset=unixlike-clang-debug-static --target=faker-ccov-all


- name: Generate code coverage report
working-directory: ${{github.workspace}}/build/unixlike-clang-debug-static
run: |
ninja faker-ccov-all \
&& llvm-cov-18 show `cat ccov/binaries.list` -instr-profile=ccov/all-merged.profdata > coverage.txt \
llvm-cov-18 show `cat ccov/binaries.list` -instr-profile=ccov/all-merged.profdata > coverage.txt \
&& llvm-cov-18 report `cat ccov/binaries.list` -instr-profile=ccov/all-merged.profdata
- name: Upload code coverage report to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ${{github.workspace}}/build/unixlike-clang-debug-static

- name: Store build artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
20 changes: 11 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ project(faker-cxx
HOMEPAGE_URL "https://github.com/cieslarmichal/faker-cxx")

include(cmake/CompilerWarnings.cmake)
include(CMakeDependentOption)

option(USE_SYSTEM_DEPENDENCIES "Use fmt and GTest from system" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_TESTING "Build tests" ON)
option(CODE_COVERAGE "Build faker-cxx with coverage support" OFF)

if (MSVC)
set(CMAKE_REQUIRED_FLAGS /std:c++20)
Expand All @@ -23,32 +25,32 @@ if (NOT HAS_STD_FORMAT)
message(STATUS "Compiler has no support for std::format. Need to use fmt library as dependency.")
endif()

include(CMakeDependentOption)
cmake_dependent_option(USE_STD_FORMAT "Use std::format when available" ON "HAS_STD_FORMAT" OFF)

if (BUILD_TESTING)
enable_testing()
set(target_code_coverage_ALL 1)
include("cmake/cmake-coverage.cmake")
add_code_coverage_all_targets()
endif ()

add_library(${CMAKE_PROJECT_NAME})

if (USE_SYSTEM_DEPENDENCIES)
find_package(fmt CONFIG REQUIRED)
elseif (NOT USE_STD_FORMAT)
add_subdirectory("${CMAKE_SOURCE_DIR}/externals/fmt")
find_library(FMT_LIBRARY fmt)
if (NOT FMT_LIBRARY)
message(FATAL_ERROR "Could not find fmt library. Please, read the contribution guide.")
endif()
add_subdirectory("${CMAKE_SOURCE_DIR}/externals/fmt")
set(FMT_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/fmt/include")
endif ()

add_subdirectory(src)

if (CODE_COVERAGE)
set(target_code_coverage_ALL 1)
include("cmake/cmake-coverage.cmake")
add_code_coverage_all_targets(EXCLUDE tests/*)
target_code_coverage(${CMAKE_PROJECT_NAME} ALL)
endif ()

if (BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif ()

Expand Down
4 changes: 3 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} WORKING_DIRECTORY ${CMAKE_
set_tests_properties(${PROJECT_NAME} PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<$<BOOL:${WIN32}>:$<TARGET_FILE_DIR:faker-cxx>>")

target_code_coverage(${PROJECT_NAME} ALL)
if (CODE_COVERAGE)
target_code_coverage(${PROJECT_NAME} ALL)
endif ()

0 comments on commit 467f9d4

Please sign in to comment.