Skip to content

Commit 8c04962

Browse files
authored
Add Code Coverage using Codecov (#7)
1 parent 5ebc75f commit 8c04962

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

.github/codecov.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Based on https://docs.codecov.com/docs/common-recipe-list#set-non-blocking-status-checks
2+
coverage:
3+
status:
4+
project:
5+
default:
6+
informational: true
7+
patch:
8+
default:
9+
informational: true
10+
# Based on https://docs.codecov.com/docs/flags#recommended-automatic-flag-management
11+
flag_management:
12+
default_rules:
13+
carryforward: true
14+
statuses:
15+
- type: project
16+
informational: true
17+
- type: patch
18+
informational: true

.github/workflows/cmake.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ on:
66
pull_request:
77
branches: [ "main" ]
88

9-
env:
10-
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11-
BUILD_TYPE: Release
12-
139
jobs:
1410
build:
1511
strategy:
1612
matrix:
13+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
14+
build: [Release, Debug]
1715
os: [ubuntu-latest, windows-latest]
1816
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
1917
# You can convert this to a matrix build if you need cross-platform coverage.
@@ -26,16 +24,39 @@ jobs:
2624
- name: Configure CMake
2725
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
2826
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
29-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
27+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build}}
3028

3129
- name: Build
3230
# Build your program with the given configuration
33-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
31+
run: cmake --build ${{github.workspace}}/build --config ${{matrix.build}}
3432

3533
- name: Test
3634
working-directory: ${{github.workspace}}/build
3735
# Execute tests defined by the CMake configuration.
3836
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
3937
# Use debug flag to show all exeucted tests
40-
run: ctest --debug -C ${{env.BUILD_TYPE}}
41-
38+
run: ctest --debug -C ${{matrix.build}}
39+
40+
# Coverage collection based on https://about.codecov.io/blog/how-to-set-up-codecov-with-c-plus-plus-and-github-actions/
41+
- name: Prepare Coverage
42+
if: ${{ (matrix.OS == 'windows-latest') && ( matrix.build == 'Debug') }}
43+
run: |
44+
choco install OpenCppCoverage -y
45+
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
46+
47+
- name: Get Coverage
48+
if: ${{ (matrix.OS == 'windows-latest') && ( matrix.build == 'Debug') }}
49+
working-directory: ${{github.workspace}}/build/Src/libCZI_UnitTests/${{matrix.build}}
50+
shell: cmd
51+
run: OpenCppCoverage.exe --export_type cobertura:${{github.workspace}}\coverage.xml --config_file "${{github.workspace}}\opencppcoverage.txt" -- libCZI_UnitTests.exe
52+
53+
- name: Upload Coverage
54+
uses: codecov/codecov-action@v3
55+
if: ${{ (matrix.OS == 'windows-latest') && ( matrix.build == 'Debug') }}
56+
with:
57+
files: ./coverage.xml
58+
fail_ci_if_error: true
59+
verbose: true
60+
# Only one flag to be safe with
61+
# https://docs.codecov.com/docs/flags#one-to-one-relationship-of-flags-to-uploads
62+
flags: ${{matrix.OS}}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# libCZI
22
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL_v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
33
[![REUSE status](https://api.reuse.software/badge/github.com/ZEISS/libczi)](https://api.reuse.software/info/github.com/ZEISS/libczi)
4+
[![codecov](https://codecov.io/gh/ZEISS/libczi/branch/main/graph/badge.svg?token=AZ8dGsDrWU)](https://codecov.io/gh/ZEISS/libczi)
45
[![CMake](https://github.com/ZEISS/libczi/actions/workflows/cmake.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/libczi/actions/workflows/cmake.yml)
56
[![CodeQL](https://github.com/ZEISS/libczi/actions/workflows/codeql.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/libczi/actions/workflows/codeql.yml)
67
[![GitHub Pages](https://github.com/ZEISS/libczi/actions/workflows/pages.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/libczi/actions/workflows/pages.yml)

Src/libCZI/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,3 @@ install(TARGETS libCZIStatic
296296
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
297297
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
298298
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
299-

opencppcoverage.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2017-2022 Carl Zeiss Microscopy GmbH
2+
#
3+
# SPDX-License-Identifier: LGPL-3.0-or-later
4+
sources=Src\libCZI\
5+
modules=libCZI

0 commit comments

Comments
 (0)