-
Notifications
You must be signed in to change notification settings - Fork 2
feat(repo): Generate code coverage on pull requests #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
19662f1
[add] pipeline for generating code coverage on pull requests.
vmarcella 6882e45
[update] workflow to update original code coverage comment and have i…
vmarcella 0f78fea
[fix] issue with fetch-depth being too shallow and use the pull reque…
vmarcella c4ca893
[update] formatting to only show 2 digits.
vmarcella bc36ad1
[update] code coverage to be published to github pages and link to ea…
vmarcella f96a03d
[update] pipeline to update package repo before setup.
vmarcella 1aaa56a
[update] pipeline to track last update.
vmarcella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| 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 | ||
|
vmarcella marked this conversation as resolved.
|
||
|
|
||
| - name: Configure Vulkan (Ubuntu) | ||
| run: | | ||
| echo "WGPU_BACKEND=vulkan" >> "$GITHUB_ENV" | ||
| # Prefer Mesa's software Vulkan (lavapipe) for headless availability | ||
|
vmarcella marked this conversation as resolved.
|
||
| 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 }); | ||
|
vmarcella marked this conversation as resolved.
Outdated
|
||
|
|
||
| - name: Upload coverage JSON as artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: coverage-report | ||
| path: coverage.json | ||
| retention-days: 30 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.