Skip to content

Commit

Permalink
added coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
klaxalk committed Nov 29, 2023
1 parent 625e413 commit e484fc9
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 7 deletions.
59 changes: 59 additions & 0 deletions .ci/publish_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -e

trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR

ARTIFACT_FOLDER=$1
WORKSPACE=/tmp/workspace

# install lcov
sudo apt-get -y -q install lcov

# clone the sources

LIST=mrs
ARCH=amd64

YAML_FILE=$LIST.yaml

REPOS=$(./.ci/parse_yaml.py $YAML_FILE $ARCH)

mkdir -p $WORKSPACE/src
cd $WORKSPACE/src

echo "$REPOS" | while IFS= read -r REPO; do

PACKAGE=$(echo "$REPO" | awk '{print $1}')
URL=$(echo "$REPO" | awk '{print $2}')
TEST=$(echo "$REPO" | awk '{print $6}')

if [[ "$TEST" != "True" ]]; then
continue
fi

git clone $URL $PACKAGE

done

# are there any coverage files?

ARGS=""

for file in `ls $ARTIFACT_FOLDER | grep ".info"`; do

ARGS="${ARGS} -a ${ARTIFACT_FOLDER}/${file}"

done

lcov $ARGS --output-file /tmp/coverage.info

genhtml -o /tmp/coverage_html /tmp/coverage.info | tee /tmp/coverage.log

COVERAGE_PCT=`cat /tmp/coverage.log | tail -n 1 | awk '{print $2}'`

echo "Coverage: $COVERAGE_PCT"

pip install pybadges
python -m pybadges --left-text="test coverage" --right-text="${COVERAGE_PCT}" --right-color='#0c0' > /tmp/coverage_html/badge.svg
18 changes: 13 additions & 5 deletions .ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR

LIST=mrs
VARIANT=testing
PACKAGE_NAME=$1
REPOSITORY_NAME=$1
ARTIFACT_FOLDER=$2
WORKSPACE=/tmp/workspace

YAML_FILE=${LIST}.yaml
Expand All @@ -28,8 +29,9 @@ curl https://ctu-mrs.github.io/ppa-$VARIANT/add_ppa.sh | bash

sudo apt-get -y -q install ros-noetic-desktop
sudo apt-get -y -q install ros-noetic-mrs-uav-system
sudo apt-get -y -q install lcov

REPOS=$(./.ci/get_repo_source.py $YAML_FILE $VARIANT $ARCH $PACKAGE_NAME)
REPOS=$(./.ci/get_repo_source.py $YAML_FILE $VARIANT $ARCH $REPOSITORY_NAME)

echo "$0: creating workspace"

Expand All @@ -38,8 +40,8 @@ cd $WORKSPACE
source /opt/ros/noetic/setup.bash
catkin init

catkin config --profile reldeb --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo
catkin profile set reldeb
catkin config --profile debug --cmake-args -DCMAKE_BUILD_TYPE=Debug
catkin profile set debug

cd src

Expand All @@ -65,10 +67,16 @@ rosdep install --from-path .

echo "$0: building the workspace"

catkin build
catkin build --limit-status-rate 0.2

echo "$0: testing"

catkin test

echo "$0: tests finished"

echo "$0: storing coverage data"

lcov --capture --directory ${WORKSPACE} --output-file /tmp/coverage.original
lcov --remove /tmp/coverage.original "*/test/*" --output-file /tmp/coverage.removed || echo "$0: coverage tracefile is empty"
lcov --extract /tmp/coverage.removed "*/workspace/*" --output-file $ARTIFACT_FOLDER/$REPOSITORY_NAME.info || echo "$0: coverage tracefile is empty"
53 changes: 51 additions & 2 deletions .github/workflows/rostest_to_release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: rostest_to_release
name: rostest_to_release_coverage

on:
workflow_call:
Expand All @@ -10,7 +10,21 @@ on:

jobs:

init-artifacts:
runs-on: ubuntu-20.04
steps:
- id: execute
run: |
mkdir -p /tmp/artifacts
touch /tmp/artifacts/void
- name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: /tmp/artifacts/

generate-jobs:
needs: init-artifacts
runs-on: ubuntu-20.04
outputs:
packages: ${{ steps.generate.outputs.packages }}
Expand All @@ -32,6 +46,11 @@ jobs:
matrix:
job: ${{ fromJson(needs.generate-jobs.outputs.packages) }}
steps:
- name: Load artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: /tmp/artifacts/
- uses: actions/checkout@v3
with:
fetch-depth: 0
Expand All @@ -45,7 +64,12 @@ jobs:
token: ${{ secrets.PUSH_TOKEN }}
- id: test
run: |
.ci/test.sh "${{ matrix.job }}"
.ci/test.sh "${{ matrix.job }}" /tmp/artifacts
- name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: /tmp/artifacts/

merge_and_push:
runs-on: ubuntu-20.04
Expand All @@ -60,3 +84,28 @@ jobs:
- id: merge
run: |
.ci/merge_push_to_release.sh
publish_coverage:
runs-on: ubuntu-20.04
needs: test-job
steps:
- name: Load artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: /tmp/artifacts/
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: 'recursive'
- id: test
run: |
ls -la /tmp/artifacts
./.ci/publish_coverage.sh /tmp/artifacts
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: /tmp/coverage_html
allow_empty_commit: true
force_orphan: true

0 comments on commit e484fc9

Please sign in to comment.