Code Coverage #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Code Coverage | |
on: | |
workflow_run: | |
workflows: ["Build"] | |
types: | |
- completed | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
coverage: | |
runs-on: ubuntu-${{ vars.UBUNTU_VERSION }} | |
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Fetch all history for proper coverage reporting | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: thales-ubuntu-${{ vars.UBUNTU_VERSION }}-Debug | |
path: build/ | |
- name: Install dependencies | |
run: | | |
sudo apt update | |
sudo apt install -y lcov | |
- name: Run coverage script | |
run: | | |
chmod +x scripts/test/coverage.sh | |
./scripts/test/coverage.sh --use-existing-build | |
- name: Generate coverage report | |
run: | | |
cd build | |
lcov --directory . --capture --output-file coverage.info | |
# Remove system headers and test files from coverage report | |
lcov --remove coverage.info '/usr/*' '/opt/*' '*/third_party/*' '*/tests/*' --output-file filtered_coverage.info | |
# Generate HTML report | |
mkdir -p coverage_report | |
genhtml filtered_coverage.info --output-directory coverage_report | |
- name: Upload coverage report as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report | |
path: build/coverage_report | |
if-no-files-found: error | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
files: ./build/filtered_coverage.info | |
fail_ci_if_error: false | |
verbose: true | |
- name: Generate Badges | |
run: | | |
# Extract overall coverage percentage | |
COVERAGE_PCT=$(lcov --summary build/filtered_coverage.info | grep "lines" | awk '{print $4}' | cut -d'.' -f1) | |
echo "Coverage: $COVERAGE_PCT%" | |
# Generate badge using shields.io | |
echo "[](https://github.com/${{ github.repository }}/actions/workflows/code-coverage.yaml)" > coverage_badge.md | |
# Upload badge as artifact | |
mkdir -p badges | |
cp coverage_badge.md badges/ | |
- name: Upload badges | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-badges | |
path: badges/ | |
if-no-files-found: warn |