Skip to content

Commit a91084d

Browse files
committed
ci: add coverage reporting
1 parent 4a21a5a commit a91084d

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

.github/workflows/coverage.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
3+
name: Coverage
4+
5+
on:
6+
push:
7+
branches: [master, ros2]
8+
pull_request:
9+
branches: [master, ros2]
10+
11+
permissions:
12+
contents: read
13+
14+
concurrency:
15+
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
coverage:
20+
name: "${{ matrix.component.name }} (ROS ${{ matrix.ros_distro }})"
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 60
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
ros_distro: [kilted]
27+
component:
28+
# Add more entries here when enabling coverage for more modules.
29+
# Example:
30+
# - name: mavros
31+
# packages: mavros
32+
# source_filter: ".*/mavros/.*"
33+
- name: libmavconn
34+
packages: libmavconn
35+
source_filter: ".*/libmavconn/.*"
36+
37+
env:
38+
ROS_DISTRO: ${{ matrix.ros_distro }}
39+
COMPONENT_NAME: ${{ matrix.component.name }}
40+
COMPONENT_PACKAGES: ${{ matrix.component.packages }}
41+
COMPONENT_FILTER: ${{ matrix.component.source_filter }}
42+
43+
steps:
44+
- uses: actions/checkout@v6
45+
46+
- uses: ros-tooling/setup-ros@v0.7
47+
with:
48+
required-ros-distributions: ${{ env.ROS_DISTRO }}
49+
50+
- name: Install Coverage Tools
51+
run: |
52+
sudo apt-get update
53+
sudo apt-get install -y python3-gcovr
54+
55+
- name: Install Dependencies
56+
shell: bash
57+
run: |
58+
source /opt/ros/${ROS_DISTRO}/setup.bash
59+
rosdep update
60+
rosdep install --from-paths . --ignore-src --rosdistro ${ROS_DISTRO} -y
61+
62+
- name: Build With Coverage
63+
shell: bash
64+
run: |
65+
source /opt/ros/${ROS_DISTRO}/setup.bash
66+
colcon build --packages-up-to ${COMPONENT_PACKAGES} --cmake-args \
67+
-DCMAKE_BUILD_TYPE=Debug \
68+
-DCMAKE_C_FLAGS=--coverage \
69+
-DCMAKE_CXX_FLAGS=--coverage
70+
71+
- name: Run Tests
72+
shell: bash
73+
run: |
74+
source /opt/ros/${ROS_DISTRO}/setup.bash
75+
source install/setup.bash
76+
colcon test --packages-select ${COMPONENT_PACKAGES}
77+
colcon test-result --verbose
78+
79+
- name: Generate Coverage Report
80+
shell: bash
81+
run: |
82+
mkdir -p coverage/${COMPONENT_NAME}
83+
gcovr \
84+
--root "${GITHUB_WORKSPACE}" \
85+
--filter "${COMPONENT_FILTER}" \
86+
--xml-pretty \
87+
--output "coverage/${COMPONENT_NAME}/coverage.xml" \
88+
--html-details "coverage/${COMPONENT_NAME}/coverage.html" \
89+
--exclude-unreachable-branches \
90+
"${GITHUB_WORKSPACE}/build"
91+
92+
- name: Upload Coverage Artifact
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: coverage-${{ matrix.component.name }}-${{ matrix.ros_distro }}
96+
path: coverage/${{ matrix.component.name }}
97+
if-no-files-found: error

0 commit comments

Comments
 (0)