Skip to content

Commit 1571da2

Browse files
Add code coverage job with Codecov upload and workflow_dispatch trigger (#1068)
* Add code coverage job with Codecov upload and workflow_dispatch trigger - Add workflow_dispatch trigger to enable manual runs via `gh workflow run` - Add separate `coverage` job that builds in Debug mode with `--coverage` flags - Use lcov to collect and filter coverage data (excludes 3rdparty, tests, examples) - Upload coverage.info to Codecov using CODECOV_TOKEN secret - Keep existing Release build job unchanged Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix coverage CI: use ubuntu-24.04 for lcov 2.x support The --ignore-errors mismatch and --ignore-errors unused flags require lcov 2.x, which is not available on ubuntu-22.04. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix coverage CI: use atomic profile counters and ignore negative counts Multi-threaded tests cause race conditions on gcov counters, producing negative counts that make lcov fail. Add -fprofile-update=atomic to compiler flags and --ignore-errors negative to lcov as a safety net. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Add Codecov coverage badge to README Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c6393f7 commit 1571da2

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

.github/workflows/cmake_ubuntu.yml

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ on:
66
- master
77
pull_request:
88
types: [opened, synchronize, reopened]
9+
workflow_dispatch:
910

1011
env:
11-
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
1212
BUILD_TYPE: Release
1313

1414
jobs:
1515
build:
16-
# The CMake configure and build commands are platform agnostic and should work equally
17-
# well on Windows or Mac. You can convert this to a matrix build if you need
18-
# cross-platform coverage.
19-
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
2016
runs-on: ${{ matrix.os }}
2117
strategy:
2218
matrix:
@@ -37,8 +33,6 @@ jobs:
3733

3834
- name: Normalize build type
3935
shell: bash
40-
# The build type is Capitalized, e.g. Release, but the preset is all lowercase, e.g. release.
41-
# There is no built in way to do string manipulations on GHA as far as I know.`
4236
run: echo "BUILD_TYPE_LOWERCASE=$(echo "${BUILD_TYPE}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
4337

4438
- name: Configure CMake
@@ -52,5 +46,58 @@ jobs:
5246
- name: run test (Linux)
5347
run: ctest --test-dir build/${{env.BUILD_TYPE}}
5448

49+
coverage:
50+
runs-on: ubuntu-24.04
51+
52+
steps:
53+
- uses: actions/checkout@v6
54+
55+
- name: Install lcov
56+
run: sudo apt-get update && sudo apt-get install -y lcov
57+
58+
- name: Install Conan
59+
id: conan
60+
uses: turtlebrowser/get-conan@main
61+
62+
- name: Create default profile
63+
run: conan profile detect
64+
65+
- name: Install conan dependencies
66+
run: conan install conanfile.py -s build_type=Debug --build=missing
67+
68+
- name: Configure CMake with coverage
69+
shell: bash
70+
run: |
71+
cmake --preset conan-debug \
72+
-DCMAKE_C_FLAGS="--coverage -fprofile-update=atomic" \
73+
-DCMAKE_CXX_FLAGS="--coverage -fprofile-update=atomic"
74+
75+
- name: Build
76+
shell: bash
77+
run: cmake --build --preset conan-debug
78+
79+
- name: Run tests
80+
run: ctest --test-dir build/Debug --output-on-failure
81+
82+
- name: Collect coverage
83+
run: |
84+
lcov --capture --directory build/Debug \
85+
--output-file coverage.info \
86+
--ignore-errors mismatch \
87+
--ignore-errors negative
88+
lcov --remove coverage.info \
89+
'/usr/*' \
90+
'*/3rdparty/*' \
91+
'*/tests/*' \
92+
'*/examples/*' \
93+
'*/sample_nodes/*' \
94+
'*/tools/*' \
95+
--output-file coverage.info \
96+
--ignore-errors unused
97+
lcov --list coverage.info
98+
5599
- name: Upload coverage reports to Codecov
56100
uses: codecov/codecov-action@v5
101+
with:
102+
files: coverage.info
103+
token: ${{ secrets.CODECOV_TOKEN }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![conan Windows](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/cmake_windows.yml/badge.svg)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/cmake_windows.yml)
44
[![ros2](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/ros2.yaml/badge.svg)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/ros2.yaml)
55
[![pixi (Conda)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/pixi.yaml/badge.svg)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/pixi.yaml)
6+
[![codecov](https://codecov.io/github/BehaviorTree/BehaviorTree.CPP/graph/badge.svg)](https://app.codecov.io/github/BehaviorTree/BehaviorTree.CPP)
67

78
# BehaviorTree.CPP 4.8
89

0 commit comments

Comments
 (0)