Skip to content

ci:Python script for executable logic #273

ci:Python script for executable logic

ci:Python script for executable logic #273

Workflow file for this run

name: Code Coverage
on: [workflow_call, pull_request, push]
jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: write
env:
BUILD_TYPE: Debug
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache CMake files
id: cache-build
uses: actions/cache@v3
with:
path: cmake-build-unit-tests
key: ${{ runner.os }}-cmake-build-unit-tests-${{ hashFiles('**/*.cpp', '**/*.h', '**/*.cmake', '**/*.txt', '**/*.c', '**/*.s') }}
- name: sccache cache backup from cache
uses: actions/cache@v3
with:
path: sccache_backup
key: ${{ runner.os }}-sccache-${{ hashFiles('**/*.cpp', '**/*.h', '**/*.cmake', '**/*.txt', '**/*.c', '**/*.s') }}
restore-keys: |
${{ runner.os }}-sccache-
- name: Create Docker volume if not exists
run: |
if ! docker volume inspect sccache_cache_volume >/dev/null 2>&1; then
docker volume create sccache_cache_volume
fi
- name: Build the docker image
run: |
docker build -f docker/Dockerfile.dev -t dev .
- name: Copy restored sccache backup into Docker volume
run: |
mkdir -p sccache_backup
docker run --rm \
-v sccache_cache_volume:/to_volume \
-v "$PWD/sccache_backup:/from_host" \
busybox \
sh -c "cp -a /from_host/. /to_volume/" || true
- name: Run the unit-test-build.py inside the docker container
run: |
docker run --rm -v "$PWD:/home/jenkins" -v "sccache_cache_volume:/home/jenkins/.cache/sccache" -w /home/jenkins -e SCCACHE_DIR=/home/jenkins/.cache/sccache --user $(id -u):4996 dev bash -c "
set -e
python3 .ci/unit-test-build.py &&
UNIT_TEST_EXIT_CODE=$?
if [ $UNIT_TEST_EXIT_CODE -ne 0 ]; then
echo "❌ Unit tests failed with exit code $UNIT_TEST_EXIT_CODE"
exit $UNIT_TEST_EXIT_CODE
fi
lcov --no-external --capture --directory . \
--output-file cmake-build-unit-tests/coverage_unfiltered.info &&
# Filter out 3rd party and mock files
lcov --remove cmake-build-unit-tests/coverage_unfiltered.info \
'*libs/3rdparty/googletest/*' \
'*/mock/*' \
'*/gmock/*' \
'*/gtest/*' \
'*/test/*' \
--output-file cmake-build-unit-tests/coverage.info &&
# Generate HTML coverage report
genhtml cmake-build-unit-tests/coverage.info \
--output-directory cmake-build-unit-tests/coverage &&
# Zip the coverage report
mv cmake-build-unit-tests/coverage code_coverage &&
zip -r code_coverage.zip code_coverage
LinePercentage=\$(lcov --summary cmake-build-unit-tests/coverage.info | grep 'lines' | awk '{print \$2}') &&
echo \"Line Percentage: \$LinePercentage\" # Debug print &&
wget \"https://img.shields.io/badge/coverage-\${LinePercentage}25-brightgreen.svg\" -O line_coverage_badge.svg &&
FunctionPercentage=\$(lcov --summary cmake-build-unit-tests/coverage.info | grep 'functions' | awk '{print \$2}') &&
echo \"Function Percentage: \$FunctionPercentage\" # Debug print &&
wget \"https://img.shields.io/badge/coverage-\${FunctionPercentage}25-brightgreen.svg\" -O function_coverage_badge.svg &&
mkdir coverage_badges &&
mv line_coverage_badge.svg coverage_badges/ &&
mv function_coverage_badge.svg coverage_badges/ &&
zip -r coverage_badges.zip coverage_badges
"
- name: Upload code coverage artifact
uses: actions/upload-artifact@v4
with:
name: code_coverage
path: code_coverage.zip
- name: Upload Coverage Badge
uses: actions/upload-artifact@v4
with:
name: coverage_badges
path: coverage_badges.zip
- name: Copy updated sccache out of Docker volume
run: |
mkdir -p sccache_backup
docker run --rm \
-v sccache_cache_volume:/from_volume \
-v "$PWD/sccache_backup:/to_host" \
busybox \
sh -c "cp -a /from_volume/. /to_host/"