feat(repo): Generate code coverage on pull requests #1
Workflow file for this run
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: | |
| pull_request: | |
| branches: [main] | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| coverage: | |
| name: Generate code coverage with cargo-llvm-cov | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Cache cargo builds | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Install Rust toolchain with llvm-tools-preview | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: llvm-tools-preview | |
| - name: Install cargo-llvm-cov | |
| uses: taiki-e/install-action@cargo-llvm-cov | |
| - name: Install Linux deps for winit/wgpu | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| pkg-config libx11-dev libxcb1-dev libxcb-render0-dev \ | |
| libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev \ | |
| libwayland-dev libudev-dev \ | |
| libvulkan-dev libvulkan1 mesa-vulkan-drivers vulkan-tools | |
| - name: Install Linux deps for audio | |
| run: | | |
| sudo apt-get install -y libasound2-dev | |
| - name: Configure Vulkan (Ubuntu) | |
| run: | | |
| echo "WGPU_BACKEND=vulkan" >> "$GITHUB_ENV" | |
| # Prefer Mesa's software Vulkan (lavapipe) for headless availability | |
| echo "VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json" >> "$GITHUB_ENV" | |
| vulkaninfo --summary || true | |
| - name: Generate coverage JSON (summary only) | |
| run: | | |
| cargo llvm-cov --workspace \ | |
| --features lambda-rs/with-vulkan,lambda-rs/audio-output-device \ | |
| --json --summary-only \ | |
| --output-path coverage.json | |
| - name: Extract total line coverage percentage | |
| id: cov | |
| run: | | |
| pct=$(jq -r '(.data[0].totals.lines.percent // 0)' coverage.json) | |
| covered=$(jq -r '(.data[0].totals.lines.covered // 0)' coverage.json) | |
| total=$(jq -r '(.data[0].totals.lines.count // 0)' coverage.json) | |
| echo "pct=$pct" >> "$GITHUB_OUTPUT" | |
| echo "covered=$covered" >> "$GITHUB_OUTPUT" | |
| echo "total=$total" >> "$GITHUB_OUTPUT" | |
| - name: Comment on PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const pct = `${{ steps.cov.outputs.pct }}`; | |
| const covered = `${{ steps.cov.outputs.covered }}`; | |
| const total = `${{ steps.cov.outputs.total }}`; | |
| const body = [ | |
| '### ✅ Coverage Report', | |
| '', | |
| '| Metric | Value |', | |
| '|--------|-------|', | |
| `| **Total Line Coverage** | ${pct}% |`, | |
| `| **Lines Covered** | ${covered} / ${total} |`, | |
| '', | |
| '*Generated by [cargo-llvm-cov](https://github.com/taiki-e/cargo-llvm-cov)*' | |
| ].join('\n'); | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.issue.number; | |
| await github.rest.issues.createComment({ owner, repo, issue_number, body }); | |
| - name: Upload coverage JSON as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: coverage.json | |
| retention-days: 30 |