Demo with a tested change. #3
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: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| coverage: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| sudo apt update | |
| sudo apt install -y lcov cmake ninja-build g++ libgtest-dev | |
| - name: Configure project with coverage flags | |
| run: cmake -B build -DENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug -G Ninja | |
| - name: Build the project | |
| run: cmake --build build | |
| - name: Run tests | |
| run: cd build && ctest --output-on-failure | |
| - name: Generate coverage report | |
| run: | | |
| cd build | |
| lcov --directory . --capture --output-file coverage.info \ | |
| --rc geninfo_auto_base=1 --ignore-errors mismatch | |
| lcov --remove coverage.info '/usr/*' '*/tests/*' --output-file coverage.filtered.info | |
| genhtml coverage.filtered.info --output-directory coverage-report | |
| - name: Show coverage summary | |
| run: | | |
| cd build | |
| lcov --summary coverage.filtered.info | |
| - name: Upload coverage report as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: build/coverage-report | |
| - name: Enforce coverage threshold | |
| run: | | |
| cd build | |
| THRESHOLD=100 | |
| COVERAGE=$(lcov --summary coverage.filtered.info | grep "lines" | awk '{ print $2 }' | sed 's/%//') | |
| echo "Total coverage: $COVERAGE%" | |
| if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then | |
| echo "❌ Coverage below threshold of ${THRESHOLD}%" | |
| exit 1 | |
| else | |
| echo "✅ Coverage is above threshold" | |
| fi |