From c336632955447c01605541a5c73be1392bc7dd5c Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Fri, 30 Jan 2026 19:48:24 +0100 Subject: [PATCH 1/4] 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 --- .github/workflows/cmake_ubuntu.yml | 60 ++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake_ubuntu.yml b/.github/workflows/cmake_ubuntu.yml index ca4c87344..abd1f5df6 100644 --- a/.github/workflows/cmake_ubuntu.yml +++ b/.github/workflows/cmake_ubuntu.yml @@ -6,17 +6,13 @@ on: - master pull_request: types: [opened, synchronize, reopened] + workflow_dispatch: env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release jobs: build: - # The CMake configure and build commands are platform agnostic and should work equally - # well on Windows or Mac. You can convert this to a matrix build if you need - # cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix runs-on: ${{ matrix.os }} strategy: matrix: @@ -37,8 +33,6 @@ jobs: - name: Normalize build type shell: bash - # The build type is Capitalized, e.g. Release, but the preset is all lowercase, e.g. release. - # There is no built in way to do string manipulations on GHA as far as I know.` run: echo "BUILD_TYPE_LOWERCASE=$(echo "${BUILD_TYPE}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - name: Configure CMake @@ -52,5 +46,57 @@ jobs: - name: run test (Linux) run: ctest --test-dir build/${{env.BUILD_TYPE}} + coverage: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v6 + + - name: Install lcov + run: sudo apt-get update && sudo apt-get install -y lcov + + - name: Install Conan + id: conan + uses: turtlebrowser/get-conan@main + + - name: Create default profile + run: conan profile detect + + - name: Install conan dependencies + run: conan install conanfile.py -s build_type=Debug --build=missing + + - name: Configure CMake with coverage + shell: bash + run: | + cmake --preset conan-debug \ + -DCMAKE_C_FLAGS="--coverage" \ + -DCMAKE_CXX_FLAGS="--coverage" + + - name: Build + shell: bash + run: cmake --build --preset conan-debug + + - name: Run tests + run: ctest --test-dir build/Debug --output-on-failure + + - name: Collect coverage + run: | + lcov --capture --directory build/Debug \ + --output-file coverage.info \ + --ignore-errors mismatch + lcov --remove coverage.info \ + '/usr/*' \ + '*/3rdparty/*' \ + '*/tests/*' \ + '*/examples/*' \ + '*/sample_nodes/*' \ + '*/tools/*' \ + --output-file coverage.info \ + --ignore-errors unused + lcov --list coverage.info + - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5 + with: + files: coverage.info + token: ${{ secrets.CODECOV_TOKEN }} From 109ab7792ab070a30b55fc20d0e6530ef5c41c24 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Sun, 1 Feb 2026 18:43:19 +0100 Subject: [PATCH 2/4] 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 --- .github/workflows/cmake_ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake_ubuntu.yml b/.github/workflows/cmake_ubuntu.yml index abd1f5df6..0c846a38e 100644 --- a/.github/workflows/cmake_ubuntu.yml +++ b/.github/workflows/cmake_ubuntu.yml @@ -47,7 +47,7 @@ jobs: run: ctest --test-dir build/${{env.BUILD_TYPE}} coverage: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v6 From 65c5c08eb399a18ce8ea7df6849fd8e5da6af37c Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Sun, 1 Feb 2026 19:19:32 +0100 Subject: [PATCH 3/4] 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 --- .github/workflows/cmake_ubuntu.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake_ubuntu.yml b/.github/workflows/cmake_ubuntu.yml index 0c846a38e..de95c6af3 100644 --- a/.github/workflows/cmake_ubuntu.yml +++ b/.github/workflows/cmake_ubuntu.yml @@ -69,8 +69,8 @@ jobs: shell: bash run: | cmake --preset conan-debug \ - -DCMAKE_C_FLAGS="--coverage" \ - -DCMAKE_CXX_FLAGS="--coverage" + -DCMAKE_C_FLAGS="--coverage -fprofile-update=atomic" \ + -DCMAKE_CXX_FLAGS="--coverage -fprofile-update=atomic" - name: Build shell: bash @@ -83,7 +83,8 @@ jobs: run: | lcov --capture --directory build/Debug \ --output-file coverage.info \ - --ignore-errors mismatch + --ignore-errors mismatch \ + --ignore-errors negative lcov --remove coverage.info \ '/usr/*' \ '*/3rdparty/*' \ From 6ce22ad0bfa6bc5796314fd6dbdc1384dc077425 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Sun, 1 Feb 2026 19:34:51 +0100 Subject: [PATCH 4/4] Add Codecov coverage badge to README Co-Authored-By: Claude Opus 4.5 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 286c838bd..0a52d208b 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![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) [![ros2](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/ros2.yaml/badge.svg)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/ros2.yaml) [![pixi (Conda)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/pixi.yaml/badge.svg)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/pixi.yaml) +[![codecov](https://codecov.io/github/BehaviorTree/BehaviorTree.CPP/graph/badge.svg)](https://app.codecov.io/github/BehaviorTree/BehaviorTree.CPP) # BehaviorTree.CPP 4.8