From 2566c1db872e993fab7cf2c0d6f93b74c884d5f5 Mon Sep 17 00:00:00 2001 From: Antoine Lambert Date: Fri, 8 Sep 2023 00:07:20 +0200 Subject: [PATCH] gha: Add code coverage report workflow for C++ It uses gcovr to compute code coverage for libtalipot-core and its plugins then update the report to coveralls for analysis. This should help adding missing tests to ensure more code is covered. --- .github/workflows/code-coverage.yml | 89 +++++++++++++++++++++++++++++ cmake/TalipotUseFile.cmake | 4 ++ gcovr.cfg | 1 + 3 files changed, 94 insertions(+) create mode 100644 .github/workflows/code-coverage.yml create mode 100644 gcovr.cfg diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 0000000000..76c95bbc4b --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,89 @@ +name: code-coverage +on: [push, pull_request] +jobs: + ubuntu: + name: Talipot C++ code coverage + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + - name: Checkout Talipot code + uses: actions/checkout@v3 + - name: Apt update + run: sudo apt update + - name: Install Talipot build dependencies + run: sudo apt install + cmake + ccache + ninja-build + libqhull-dev + libyajl-dev + libgraphviz-dev + libpython3-dev + libcppunit-dev + binutils-dev + libzstd-dev + libgit2-dev + qtbase5-dev + libqt5webkit5-dev + libquazip5-dev + libglew-dev + libfreetype6-dev + libfribidi-dev + libfontconfig-dev + python3 + python3-pip + doxygen + graphviz + xvfb + - name: Install sip + run: | + sudo pip3 install --upgrade pip + sudo pip3 install sip + - name: Prepare ccache timestamp + id: get-current-date + run: | + echo "date=$(date -u "+%Y-%m-%d-%H-%m-%S")" >> $GITHUB_OUTPUT + shell: bash + - name: Cache files + uses: actions/cache@v3 + with: + path: ~/.ccache + key: ${{ matrix.config.os }}-ccache-${{ steps.get-current-date.outputs.date }} + restore-keys: | + ${{ matrix.config.os }}-ccache- + - name: Create build directory + run: mkdir build + - name: Configure Talipot build with CMake + working-directory: ./build + run: cmake .. -G Ninja + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_INSTALL_PREFIX=$PWD/install + -DTALIPOT_BUILD_TESTS=ON + -DTALIPOT_USE_CCACHE=ON + -DTALIPOT_BUILD_DOC=OFF + -DTALIPOT_CODE_COVERAGE=ON + - name: Talipot build + working-directory: ./build + run: ninja -j4 + - name: Run Talipot unit tests + working-directory: ./build + run: xvfb-run ninja tests + - name: Generate and upload code coverage report + uses: threeal/gcovr-action@main + with: + excludes: | + build/* + library/talipot-gui/* + library/talipot-ogl/* + library/talipot-python/* + plugins/interactor/* + plugins/view/* + software/* + tests/* + thirdparty/* + utils/* + coveralls-send: true + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/cmake/TalipotUseFile.cmake b/cmake/TalipotUseFile.cmake index 7e531b1c08..501eefcbba 100644 --- a/cmake/TalipotUseFile.cmake +++ b/cmake/TalipotUseFile.cmake @@ -389,6 +389,10 @@ MACRO(TALIPOT_SET_COMPILER_OPTIONS_AND_DEFINITIONS) " -no_warning_for_no_symbols -c ") ENDIF(APPLE) + IF(CMAKE_COMPILER_IS_GNUCXX AND TALIPOT_CODE_COVERAGE) + TALIPOT_SET_CXX_FLAGS("-fprofile-arcs -ftest-coverage -O0") + ENDIF(CMAKE_COMPILER_IS_GNUCXX AND TALIPOT_CODE_COVERAGE) + ENDMACRO(TALIPOT_SET_COMPILER_OPTIONS_AND_DEFINITIONS) # for backward compatibility with Talipot < 5.1 for external projects diff --git a/gcovr.cfg b/gcovr.cfg new file mode 100644 index 0000000000..8deed2d485 --- /dev/null +++ b/gcovr.cfg @@ -0,0 +1 @@ +gcov-ignore-errors = no_working_dir_found