Skip to content

Commit

Permalink
test download
Browse files Browse the repository at this point in the history
  • Loading branch information
KmakD committed May 14, 2024
1 parent 53c1868 commit c970b83
Showing 1 changed file with 55 additions and 56 deletions.
111 changes: 55 additions & 56 deletions .github/workflows/run-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,30 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build
uses: docker/build-push-action@v5
with:
context: .
file: ./.github/Dockerfile
platforms: linux/arm64
push: false
tags: panther:test
load: true # Allows you to load built images into Docker on the runner environment
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: Save built Docker image (optional)
- name: Save built Docker image
run: docker save panther:test | gzip > panther-test.tar.gz

- name: Upload artifact (optional)
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: docker-image
Expand All @@ -38,69 +49,57 @@ jobs:
test:
name: Run unit tests
runs-on: self-hosted
needs:
- build
env:
HUSARION_ROS_BUILD_TYPE: hardware
ROS_DISTRO: humble
TEST_RESULT_FILENAME: last_run_results.txt
COVERAGE_RESULT_FILENAME: coverage_results.log
steps:
- name: Download Docker image from artifacts
uses: actions/download-artifact@v3
with:
name: docker-image

# - name: Load Docker image
# run: |
# gzip -dc your-image-name.tar.gz | docker load

- 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/panther_ros

- name: Resolve dependencies
working-directory: ros2_ws
run: |
vcs import < src/panther_ros/panther/panther_hardware.repos src
sudo apt update
rosdep update --rosdistro $ROS_DISTRO
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y
# - 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: 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: Collect unit tests output
# working-directory: ${{ runner.temp }}
# id: unit-tests-output
# run: cat ${{ env.TEST_RESULT_FILENAME }} >> "$GITHUB_OUTPUT"

- 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: Validate tests result
# uses: nick-fields/assert-action@v1
# with:
# expected: 0
# actual: ${{ steps.unit-tests-output.outputs.result }}

- 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 }}
# - 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 }}

0 comments on commit c970b83

Please sign in to comment.