Skip to content

Commit 19662f1

Browse files
committed
[add] pipeline for generating code coverage on pull requests.
1 parent 928d6e3 commit 19662f1

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

.github/workflows/coverage.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Code Coverage
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
push:
8+
branches: [main]
9+
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
16+
defaults:
17+
run:
18+
shell: bash
19+
20+
jobs:
21+
coverage:
22+
name: Generate code coverage with cargo-llvm-cov
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout Repository
27+
uses: actions/checkout@v4
28+
29+
- name: Cache cargo builds
30+
uses: Swatinem/rust-cache@v2
31+
32+
- name: Install Rust toolchain with llvm-tools-preview
33+
uses: dtolnay/rust-toolchain@stable
34+
with:
35+
components: llvm-tools-preview
36+
37+
- name: Install cargo-llvm-cov
38+
uses: taiki-e/install-action@cargo-llvm-cov
39+
40+
- name: Install Linux deps for winit/wgpu
41+
run: |
42+
sudo apt-get update
43+
sudo apt-get install -y \
44+
pkg-config libx11-dev libxcb1-dev libxcb-render0-dev \
45+
libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev \
46+
libwayland-dev libudev-dev \
47+
libvulkan-dev libvulkan1 mesa-vulkan-drivers vulkan-tools
48+
49+
- name: Install Linux deps for audio
50+
run: |
51+
sudo apt-get install -y libasound2-dev
52+
53+
- name: Configure Vulkan (Ubuntu)
54+
run: |
55+
echo "WGPU_BACKEND=vulkan" >> "$GITHUB_ENV"
56+
# Prefer Mesa's software Vulkan (lavapipe) for headless availability
57+
echo "VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json" >> "$GITHUB_ENV"
58+
vulkaninfo --summary || true
59+
60+
- name: Generate coverage JSON (summary only)
61+
run: |
62+
cargo llvm-cov --workspace \
63+
--features lambda-rs/with-vulkan,lambda-rs/audio-output-device \
64+
--json --summary-only \
65+
--output-path coverage.json
66+
67+
- name: Extract total line coverage percentage
68+
id: cov
69+
run: |
70+
pct=$(jq -r '(.data[0].totals.lines.percent // 0)' coverage.json)
71+
covered=$(jq -r '(.data[0].totals.lines.covered // 0)' coverage.json)
72+
total=$(jq -r '(.data[0].totals.lines.count // 0)' coverage.json)
73+
echo "pct=$pct" >> "$GITHUB_OUTPUT"
74+
echo "covered=$covered" >> "$GITHUB_OUTPUT"
75+
echo "total=$total" >> "$GITHUB_OUTPUT"
76+
77+
- name: Comment on PR
78+
if: github.event_name == 'pull_request'
79+
uses: actions/github-script@v7
80+
with:
81+
script: |
82+
const pct = `${{ steps.cov.outputs.pct }}`;
83+
const covered = `${{ steps.cov.outputs.covered }}`;
84+
const total = `${{ steps.cov.outputs.total }}`;
85+
86+
const body = [
87+
'### ✅ Coverage Report',
88+
'',
89+
'| Metric | Value |',
90+
'|--------|-------|',
91+
`| **Total Line Coverage** | ${pct}% |`,
92+
`| **Lines Covered** | ${covered} / ${total} |`,
93+
'',
94+
'*Generated by [cargo-llvm-cov](https://github.com/taiki-e/cargo-llvm-cov)*'
95+
].join('\n');
96+
97+
const { owner, repo } = context.repo;
98+
const issue_number = context.issue.number;
99+
await github.rest.issues.createComment({ owner, repo, issue_number, body });
100+
101+
- name: Upload coverage JSON as artifact
102+
uses: actions/upload-artifact@v4
103+
with:
104+
name: coverage-report
105+
path: coverage.json
106+
retention-days: 30

0 commit comments

Comments
 (0)