From ebd5fdd634ceb68f241b698967a66b54fe26470e Mon Sep 17 00:00:00 2001 From: Ivan Pinezhaninov Date: Sun, 3 Dec 2023 14:09:08 +0300 Subject: [PATCH] Codecov added --- .github/workflows/build-and-test.yml | 17 ++++++++++++++++- CMakeLists.txt | 12 +++++++++++- README.md | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 7a59411..0f13502 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,6 +1,6 @@ name: build and test -on: [push] +on: push jobs: build: @@ -62,6 +62,7 @@ jobs: run: > cmake -B ${{ steps.strings.outputs.build-output-dir }} -DASYNC_PROMISE_BUILD_TESTS=ON + -DASYNC_PROMISE_CODECOV=ON -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} @@ -76,3 +77,17 @@ jobs: # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest --build-config ${{ matrix.build_type }} + + - name: Prepare coverage reports + if: ${{ success() && 'ubuntu-latest' == matrix.os && 'g++' == matrix.cpp_compiler }} + run: | + sudo apt update && sudo apt install -y lcov + cd ${{ steps.strings.outputs.build-output-dir }} + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info "/usr/*" "*/tests/src/*" "*/catch2/*" --output-file coverage.info + + - name: Upload coverage reports to Codecov + if: ${{ success() && 'ubuntu-latest' == matrix.os && 'g++' == matrix.cpp_compiler }} + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fa7934..74d71ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,12 +21,13 @@ project(async_promise LANGUAGES CXX VERSION 1.0.0) option(ASYNC_PROMISE_BUILD_EXAMPLE "Build example" OFF) option(ASYNC_PROMISE_BUILD_TESTS "Build tests" OFF) +option(ASYNC_PROMISE_CODECOV "Add test coverage" OFF) if(ASYNC_PROMISE_BUILD_EXAMPLE) add_subdirectory(example) endif() -if (ASYNC_PROMISE_BUILD_TESTS) +if(ASYNC_PROMISE_BUILD_TESTS) enable_testing() add_subdirectory(tests) endif() @@ -51,4 +52,13 @@ target_link_libraries(${TARGET} INTERFACE Threads::Threads ) +if(ASYNC_PROMISE_CODECOV AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + target_compile_options(${TARGET} INTERFACE -O0 -g --coverage) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(${TARGET} INTERFACE --coverage) + else() + target_link_libraries(${TARGET} INTERFACE --coverage) + endif() +endif() + install(FILES ${HEADERS} DESTINATION include) diff --git a/README.md b/README.md index 87f5da0..cf3188e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # async::promise -![Build and test](https://github.com/IvanPinezhaninov/async_promise/actions/workflows/build-and-test.yml/badge.svg) +[![build and test](https://github.com/IvanPinezhaninov/async_promise/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/IvanPinezhaninov/async_promise/actions/workflows/build-and-test.yml) [![MIT License](https://img.shields.io/badge/license-mit-blue.svg?style=flat)](http://opensource.org/licenses/MIT) ## Overview