Update command line args to lcov. We want to ignore any errors on fi… #39
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: coverage | |
| on: | |
| push: | |
| branches: [prerelease] | |
| pull_request: | |
| branches: [prerelease] | |
| jobs: | |
| coverage-linux: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - arch: x86_64 | |
| runner: ubuntu-latest | |
| - arch: aarch64 | |
| runner: ubuntu-24.04-arm | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y lcov cmake build-essential | |
| - name: Configure | |
| run: | | |
| cmake -S . -B build -DENABLE_COVERAGE=ON | |
| - name: Build | |
| run: cmake --build build | |
| - name: Test | |
| run: ctest --test-dir build --output-on-failure | |
| - name: Generate coverage report | |
| run: | | |
| lcov --capture --directory build --output-file coverage.info | |
| lcov --ignore-errors unused --remove coverage.info '/usr/*' --output-file coverage.info | |
| genhtml coverage.info --output-directory docs/coverage --title "yafl Code Coverage" | |
| - name: Generate coverage badge | |
| run: | | |
| chmod +x scripts/make_coverage_badge.sh | |
| scripts/make_coverage_badge.sh docs/coverage_linux_${{ matrix.arch }}.svg coverage.info | |
| - name: Upload Coverage Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-linux-${{ matrix.arch }} | |
| path: | | |
| docs/coverage | |
| docs/coverage_linux_${{ matrix.arch }}.svg | |
| coverage-windows: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - arch: x86_64 | |
| runner: windows-latest | |
| cmake_arch: x64 | |
| # Note: ARM64 Windows coverage skipped - OpenCppCoverage doesn't support ARM64 PE binaries | |
| # ARM64 coverage is validated via Linux and macOS ARM64 coverage jobs | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install OpenCppCoverage | |
| run: | | |
| choco install opencppcoverage | |
| echo "C:\Program Files (x86)\OpenCppCoverage" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
| - name: Configure | |
| run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -A ${{ matrix.cmake_arch }} | |
| - name: Build | |
| run: cmake --build build --config Debug | |
| - name: Generate Coverage Report | |
| run: | | |
| # Find OpenCppCoverage installation | |
| $opencppcoverage = Get-ChildItem -Path "C:\Program Files*" -Recurse -Filter "OpenCppCoverage.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| if (-not $opencppcoverage) { | |
| Write-Error "OpenCppCoverage.exe not found" | |
| exit 1 | |
| } | |
| Write-Host "Using OpenCppCoverage from: $($opencppcoverage.FullName)" | |
| & $opencppcoverage.FullName --sources "${{ github.workspace }}" --cover_children --export_type=html:build/coverage_report --export_type=cobertura:build/cobertura.xml -- ctest --test-dir build -C Debug --output-on-failure | |
| shell: pwsh | |
| - name: Generate Coverage Badge | |
| shell: powershell | |
| run: | | |
| if (-Not (Test-Path build/cobertura.xml)) { Write-Error "Cobertura XML not found"; exit 1 } | |
| [xml]$xml = Get-Content build/cobertura.xml | |
| $rate = $xml.coverage.'line-rate' | |
| $percentage = [math]::Round([double]$rate * 100) | |
| if ($percentage -ge 90) { $color = "brightgreen" } | |
| elseif ($percentage -ge 75) { $color = "yellow" } | |
| else { $color = "red" } | |
| $svg = @" | |
| <svg xmlns="http://www.w3.org/2000/svg" width="120" height="20"> | |
| <linearGradient id="b" x2="0" y2="100%"> | |
| <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> | |
| <stop offset="1" stop-opacity=".1"/> | |
| </linearGradient> | |
| <mask id="a"> | |
| <rect width="120" height="20" rx="3" fill="#fff"/> | |
| </mask> | |
| <g mask="url(#a)"> | |
| <rect width="70" height="20" fill="#555"/> | |
| <rect x="70" width="50" height="20" fill="$color"/> | |
| <rect width="120" height="20" fill="url(#b)"/> | |
| </g> | |
| <g fill="#fff" text-anchor="middle" | |
| font-family="DejaVu Sans,Verdana,Geneva,sans-serif" | |
| font-size="11"> | |
| <text x="35" y="14">coverage</text> | |
| <text x="95" y="14">${percentage}%</text> | |
| </g> | |
| </svg> | |
| "@ | |
| New-Item -ItemType Directory -Force -Path docs | |
| $badgePath = "docs/coverage_windows_${{ matrix.arch }}.svg" | |
| Set-Content -Path $badgePath -Value $svg | |
| if (Test-Path $badgePath) { | |
| Write-Host "Badge created: $badgePath (${percentage}% coverage)" | |
| Get-Content $badgePath | Select-Object -First 5 | |
| } else { | |
| Write-Error "Failed to create badge file" | |
| exit 1 | |
| } | |
| - name: Upload Coverage Report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-windows-${{ matrix.arch }} | |
| path: | | |
| build/coverage_report | |
| docs/coverage_windows_${{ matrix.arch }}.svg | |
| coverage-macos: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - arch: x86_64 | |
| runner: macos-15-intel | |
| cmake_arch: x86_64 | |
| - arch: aarch64 | |
| runner: macos-latest | |
| cmake_arch: arm64 | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: brew install lcov | |
| - name: Configure | |
| run: | | |
| cmake -S . -B build \ | |
| -DENABLE_COVERAGE=ON \ | |
| -DCMAKE_BUILD_TYPE=Debug \ | |
| -DCMAKE_OSX_ARCHITECTURES=${{ matrix.cmake_arch }} | |
| - name: Build | |
| run: cmake --build build | |
| - name: Test | |
| run: ctest --test-dir build --output-on-failure | |
| - name: Create gcov wrapper | |
| run: | | |
| cat > /usr/local/bin/llvm-gcov << 'EOF' | |
| #!/bin/bash | |
| exec xcrun llvm-cov gcov "$@" | |
| EOF | |
| chmod +x /usr/local/bin/llvm-gcov | |
| - name: Generate Coverage Report | |
| run: | | |
| lcov --gcov-tool llvm-gcov --capture --directory build --output-file coverage.info | |
| lcov --gcov-tool llvm-gcov --ignore-errors unused --remove coverage.info '/usr/*' --output-file coverage.info | |
| genhtml coverage.info --output-directory docs/coverage --title "yafl Code Coverage" | |
| - name: Generate Coverage Badge | |
| run: | | |
| chmod +x scripts/make_coverage_badge.sh | |
| scripts/make_coverage_badge.sh docs/coverage_macos_${{ matrix.arch }}.svg coverage.info | |
| - name: Upload Coverage Report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-macos-${{ matrix.arch }} | |
| path: | | |
| docs/coverage | |
| docs/coverage_macos_${{ matrix.arch }}.svg | |
| commit-badges: | |
| needs: [coverage-linux, coverage-macos, coverage-windows] | |
| runs-on: ubuntu-latest | |
| if: always() && github.event_name == 'push' && github.ref == 'refs/heads/prerelease' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Move badges | |
| run: | | |
| mkdir -p docs | |
| find artifacts -name "coverage_*.svg" -exec cp {} docs/ \; | |
| - name: Create GitHub Pages configuration | |
| run: | | |
| touch docs/.nojekyll | |
| - name: Commit and push coverage badges | |
| run: | | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| git add docs/coverage_*.svg docs/.nojekyll | |
| if git diff --quiet --cached; then | |
| echo "No coverage badge changes to commit" | |
| else | |
| git commit -m "Update code coverage badges [skip ci]" && git push origin prerelease | |
| fi |