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