diff --git a/.github/workflows/ci_coverage.yml b/.github/workflows/ci_coverage.yml new file mode 100644 index 0000000..c15738b --- /dev/null +++ b/.github/workflows/ci_coverage.yml @@ -0,0 +1,93 @@ +# SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin +# SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik +# SPDX-License-Identifier: CC0-1.0 + +name: Coverage + +on: + push: + branches: + - 'main' + pull_request: + types: + - unlabeled + workflow_dispatch: + +concurrency: + group: coverage-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name != 'push' }} + +env: + SEQAN3_NO_VERSION_CHECK: 1 + TZ: Europe/Berlin + +defaults: + run: + shell: bash -Eeuxo pipefail {0} + +jobs: + build: + runs-on: ubuntu-latest + name: ${{ matrix.compiler }} + if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' || github.event.label.name == 'lint' + strategy: + fail-fast: false + matrix: + compiler: ["gcc-14"] + container: + image: ghcr.io/seqan/${{ matrix.compiler }} + volumes: + - /home/runner:/home/runner + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Load ccache + uses: actions/cache@v4 + with: + path: /home/runner/.ccache + save-always: true + key: ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}-${{ github.ref }} + + - name: Configure tests + run: | + mkdir build && cd build + cmake .. -DCMAKE_BUILD_TYPE=Coverage + make gtest_main + + - name: Build tests + working-directory: build + run: | + ccache -z + make -k + ccache -svvx + + - name: Run tests + working-directory: build + run: ctest . -j --output-on-failure + + - name: Generate coverage report + run: | + gcovr --root ${GITHUB_WORKSPACE} \ + ${GITHUB_WORKSPACE}/build \ + --filter ${GITHUB_WORKSPACE}/include \ + --filter ${GITHUB_WORKSPACE}/src \ + --exclude-lines-by-pattern '^\s*$' \ + --exclude-lines-by-pattern '^\s*};$' \ + --exclude-lines-by-pattern '^\s*\.[^\s]* = .*[\n,]$' \ + --exclude-lines-by-pattern '^\s*\.[^\s]* = .*}\);$' \ + --exclude-lines-by-pattern '^\s*\.[^\s]* =(\s+\".*\")+' \ + --exclude-unreachable-branches \ + --exclude-throw-branches \ + --exclude-noncode-lines \ + -j \ + --cobertura \ + --output ${GITHUB_WORKSPACE}/build/coverage_report.xml + + - name: Submit coverage report + uses: codecov/codecov-action@v3.1.5 + with: + files: build/coverage_report.xml + fail_ci_if_error: false diff --git a/.github/workflows/ci_lint.yml b/.github/workflows/ci_lint.yml index 70f61a5..457670d 100644 --- a/.github/workflows/ci_lint.yml +++ b/.github/workflows/ci_lint.yml @@ -34,12 +34,21 @@ jobs: steps: - name: "Cancel macOS" run: echo "Cancelling macOS" + cancel_coverage: + name: Cancel running Workflows + concurrency: + group: coverage-${{ github.event.pull_request.number }} + cancel-in-progress: true + runs-on: ubuntu-latest + steps: + - name: "Cancel Coverage" + run: echo "Cancelling Coverage" lint: name: Lint concurrency: group: lint-${{ github.event.pull_request.number }} cancel-in-progress: true - needs: [cancel_linux, cancel_macos] + needs: [cancel_linux, cancel_macos, cancel_coverage] runs-on: ubuntu-latest timeout-minutes: 15 steps: diff --git a/cmake/test/config.cmake b/cmake/test/config.cmake index 31ea3c0..f411a7d 100644 --- a/cmake/test/config.cmake +++ b/cmake/test/config.cmake @@ -2,6 +2,8 @@ # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik # SPDX-License-Identifier: CC0-1.0 +include (test/coverage) + CPMGetPackage (googletest) list (APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure") # Must be before `enable_testing ()`. diff --git a/cmake/test/coverage.cmake b/cmake/test/coverage.cmake new file mode 100644 index 0000000..442fd5c --- /dev/null +++ b/cmake/test/coverage.cmake @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin +# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik +# SPDX-License-Identifier: BSD-3-Clause + +# Add a custom build type: Coverage +set (CMAKE_CXX_FLAGS_COVERAGE + "${CMAKE_CXX_FLAGS_DEBUG} --coverage -fprofile-arcs -ftest-coverage -fprofile-abs-path" + CACHE STRING "Flags used by the C++ compiler during coverage builds." FORCE) +set (CMAKE_C_FLAGS_COVERAGE + "${CMAKE_C_FLAGS_DEBUG} --coverage -fprofile-arcs -ftest-coverage -fprofile-abs-path" + CACHE STRING "Flags used by the C compiler during coverage builds." FORCE) +set (CMAKE_EXE_LINKER_FLAGS_COVERAGE + "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Wl,-lgcov" + CACHE STRING "Flags used for linking binaries during coverage builds." FORCE) +set (CMAKE_SHARED_LINKER_FLAGS_COVERAGE + "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -Wl,-lgcov" + CACHE STRING "Flags used by the shared libraries linker during coverage builds." FORCE) + +mark_as_advanced (CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE)