Skip to content

Commit

Permalink
Use gcovr to enforce code coverage everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic committed Sep 29, 2024
1 parent 5493d4b commit 9eca23e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
- name: Install debian packages
run: >-
sudo apt-get update && sudo apt-get install -y \
gcovr \
git \
lcov \
python3-colcon-common-extensions \
Expand Down Expand Up @@ -101,6 +102,10 @@ jobs:
working-directory: ${{ github.workspace }}
run: ./src/beluga/tools/run-clang-tidy.sh

- name: Enforce code coverage
working-directory: ${{ github.workspace }}
run: ./src/beluga/tools/check-code-coverage.sh

- name: Upload code coverage report
uses: codecov/codecov-action@v3
with:
Expand All @@ -109,7 +114,7 @@ jobs:
name: codecov-umbrella
fail_ci_if_error: true
verbose: true
if: ${{ matrix.upload_artifacts }}
if: ${{ matrix.upload_artifacts && !github.event.pull_request.head.repo.fork }}

build-docs:
needs: build-test
Expand Down
14 changes: 7 additions & 7 deletions tools/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@ colcon build \
--cmake-force-configure
echo ::endgroup::

LCOV_CONFIG_PATH=${SCRIPT_PATH}/../.lcovrc

echo ::group::Test
colcon lcov-result --initial
colcon lcov-result \
--initial \
--lcov-config-file ${LCOV_CONFIG_PATH}
colcon test \
--packages-select ${ROS_PACKAGES} \
--event-handlers console_cohesion+ \
--return-code-on-test-failure \
--mixin coverage-pytest
echo ::endgroup::

LCOV_CONFIG_PATH=${SCRIPT_PATH}/../.lcovrc

echo ::group::Generate code coverage results
colcon lcov-result \
--packages-select ${ROS_PACKAGES} \
--lcov-config-file ${LCOV_CONFIG_PATH} \
--verbose
--lcov-config-file ${LCOV_CONFIG_PATH}
colcon coveragepy-result \
--packages-select ${ROS_PACKAGES} \
--coverage-report-args -m \
--verbose
--coverage-report-args -m
echo ::endgroup::
25 changes: 25 additions & 0 deletions tools/check-code-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Copyright 2024 Ekumen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Enforce code coverage limits

[[ -z "${WITHIN_DEV}" ]] && echo -e "\033[1;33mWARNING: Try running this script inside the development container if you experience any issues.\033[0m"

set -o errexit

gcovr --fail-under-line 95 -j -u -f 'src/beluga/.*' -e '.*/test/.*cpp' build/
# NOTE: Enable Python code coverage checks when attained
# (cd coveragepy && python3 -m coverage report --fail-under=95)

0 comments on commit 9eca23e

Please sign in to comment.