forked from wibotic/wibotic-ros-can-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (70 loc) · 3.06 KB
/
run-unit-tests.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
name: Run unit tests
on:
workflow_dispatch:
# TODO: ENABLE WHEN READY
# pull_request:
# branches:
# - ros2-devel
jobs:
test:
name: Run unit tests
runs-on: self-hosted
env:
HUSARION_ROS_BUILD_TYPE: hardware
ROS_DISTRO: humble
TEST_RESULT_FILENAME: last_run_results.txt
COVERAGE_RESULT_FILENAME: coverage_results.log
steps:
- name: Prepare filesystem
working-directory: ${{ runner.temp }}
run: |
touch ${{ env.TEST_RESULT_FILENAME }}
touch ${{ env.COVERAGE_RESULT_FILENAME }}
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
path: ros2_ws/src/wibotic_ros
- name: Resolve dependencies
working-directory: ros2_ws
run: |
sudo apt update
rosdep update --rosdistro $ROS_DISTRO
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y
- name: Build
working-directory: ros2_ws
run: |
source /opt/ros/$ROS_DISTRO/setup.bash
if [ -f install/setup.bash ]; then source install/setup.bash; fi
colcon build --symlink-install --parallel-workers $(nproc) --packages-up-to panther --cmake-args -DCMAKE_CXX_FLAGS='-fprofile-arcs -ftest-coverage'
- name: Test
working-directory: ros2_ws
run: |
source install/setup.bash
colcon test --packages-up-to panther --retest-until-pass 10 --event-handlers console_cohesion+ --return-code-on-test-failure
echo "result=$?" >> ${{ runner.temp }}/${{ env.TEST_RESULT_FILENAME }}
colcon lcov-result --packages-up-to panther --verbose >> ${{ runner.temp }}/${{ env.COVERAGE_RESULT_FILENAME }}
lines_cov=$(cat ${{ runner.temp }}/${{ env.COVERAGE_RESULT_FILENAME }} | grep -E 'lines' | head -1)
functions_cov=$(cat ${{ runner.temp }}/${{ env.COVERAGE_RESULT_FILENAME }} | grep -E 'functions' | head -1)
branches_cov=$(cat ${{ runner.temp }}/${{ env.COVERAGE_RESULT_FILENAME }} | grep -E 'branches' | head -1)
echo "lines_cov=$lines_cov">> ${{ runner.temp }}/${{ env.TEST_RESULT_FILENAME }}
echo "functions_cov=$functions_cov" >> ${{ runner.temp }}/${{ env.TEST_RESULT_FILENAME }}
echo "branches_cov=$branches_cov" >> ${{ runner.temp }}/${{ env.TEST_RESULT_FILENAME }}
- name: Collect unit tests output
working-directory: ${{ runner.temp }}
id: unit-tests-output
run: cat ${{ env.TEST_RESULT_FILENAME }} >> "$GITHUB_OUTPUT"
- name: Validate tests result
uses: nick-fields/assert-action@v1
with:
expected: 0
actual: ${{ steps.unit-tests-output.outputs.result }}
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
**Test coverage of modified packages:**
${{ steps.unit-tests-output.outputs.lines_cov }}
${{ steps.unit-tests-output.outputs.functions_cov }}
${{ steps.unit-tests-output.outputs.branches_cov }}