Skip to content

ci:Python script for executable logic #255

ci:Python script for executable logic

ci:Python script for executable logic #255

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: Build the docker image
# if: steps.cache-build.outputs.cache-hit != 'true'
run: |
docker build --build-arg user_id=$(id -u) -f docker/Dockerfile.dev -t dev .
- name: Run the unit-test-build.py inside the docker container
# if: steps.cache-build.outputs.cache-hit != 'true'
run: |
docker run --rm -v "$PWD:/home/jenkins" -w /home/jenkins --user $(id -u):4996 dev bash -c "
python3 .ci/unit-test-build.py &&
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