This repository was archived by the owner on Dec 17, 2025. It is now read-only.
chore: Show coverage badge #175
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: Badge Status | |
| on: | |
| push: | |
| branches: [ main, dev ] | |
| pull_request: | |
| branches: [ main, dev ] | |
| schedule: | |
| # Run daily at 02:00 UTC | |
| - cron: '0 2 * * *' | |
| jobs: | |
| status: | |
| name: Update Status | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ninja-build libspdlog-dev gcc-11 g++-11 lcov python3-pip | |
| python3 -m pip install --user anybadge | |
| - name: Set up CMake | |
| uses: jwlawson/actions-setup-cmake@v1.14 | |
| with: | |
| cmake-version: 3.20.0 | |
| - name: Quick build test (with coverage) | |
| run: | | |
| cmake -B build -G Ninja \ | |
| -DCMAKE_C_COMPILER=gcc-11 \ | |
| -DCMAKE_CXX_COMPILER=g++-11 \ | |
| -DCMAKE_BUILD_TYPE=Debug \ | |
| -DWITH_UNIT_TEST=ON \ | |
| -DCMAKE_CXX_FLAGS="--coverage" \ | |
| -DCMAKE_C_FLAGS="--coverage" | |
| cmake --build build --parallel 4 | |
| - name: Quick test run | |
| working-directory: build | |
| run: ctest --output-on-failure | |
| - name: Generate coverage report | |
| run: | | |
| lcov --capture --directory build --output-file coverage.badge.info | |
| lcov --remove coverage.badge.info '/usr/*' '*/test/*' '*/build/*' --output-file coverage.badge.info | |
| echo "Coverage summary:" && lcov --summary coverage.badge.info | |
| PCT=$(lcov --summary coverage.badge.info | awk '/lines/ {gsub("%","", $2); print $2}') | |
| echo "CODE_COVERAGE=$PCT" >> $GITHUB_ENV | |
| - name: Generate coverage badge | |
| env: | |
| PATH: ${{ env.HOME }}/.local/bin:${{ env.PATH }} | |
| run: | | |
| anybadge --value=${CODE_COVERAGE} --file=coverage.svg --label="coverage" --suffix="%" \ | |
| 0=red 50=orange 70=yellow 80=yellowgreen 90=green | |
| - name: Upload coverage badge artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-badge | |
| path: coverage.svg | |
| - name: Generate badge data | |
| run: | | |
| echo "BUILD_STATUS=passing" >> $GITHUB_ENV | |
| echo "TESTS_COUNT=$(ctest --test-dir build --show-only=json-v1 | jq '.tests | length')" >> $GITHUB_ENV |