Skip to content

Task/bitfield/tests #10

Task/bitfield/tests

Task/bitfield/tests #10

name: Code Coverage
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build_cmake_linux_coverage:
name: Code Coverage on Linux
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Install Linux dependencies
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install ninja-build protobuf-compiler lcov g++-13 gcc-13
echo "CXX=g++-13" >> ${GITHUB_ENV}
echo "CC=gcc-13" >> ${GITHUB_ENV}
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-G Ninja .
-DCMAKE_C_COMPILER=gcc-13
-DCMAKE_CXX_COMPILER=g++-13
-DSPB_PROTO_BUILD_TESTS=ON
-DCMAKE_BUILD_TYPE=Debug
-DSPB_PROTO_USE_COVERAGE=ON
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --target unit_tests
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# 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 --output-on-failure
lcov --capture -o coverage.info --directory . --exclude '/usr/*' --exclude '*/test/*' --gcov-tool gcov-13
genhtml coverage.info --output-directory report
- name: Upload Coverage Results
uses: coverallsapp/github-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ${{ steps.strings.outputs.build-output-dir }}/coverage.info
- name: Update Coverage Badge
uses: we-cli/coverage-badge-action@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}