-
Notifications
You must be signed in to change notification settings - Fork 2
308 lines (268 loc) · 10.7 KB
/
coverage.yml
File metadata and controls
308 lines (268 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
name: Code Coverage
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
pages: write
id-token: write
defaults:
run:
shell: bash
jobs:
coverage:
name: Generate code coverage with cargo-llvm-cov
runs-on: ubuntu-latest
env:
LAMBDA_REQUIRE_GPU_ADAPTER: "1"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
# Fetch enough history for diff against base branch
fetch-depth: 0
lfs: true
- 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 update
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.
# The exact ICD filename can differ across Ubuntu images, so discover it.
LVP_ICD="$(
if [[ -d /usr/share/vulkan/icd.d ]]; then
find /usr/share/vulkan/icd.d -maxdepth 1 -type f \
\( -name '*lvp_icd*.json' -o -name '*lavapipe*.json' \) \
-print 2>/dev/null | head -n1
fi
)"
if [[ -z "$LVP_ICD" ]]; then
echo "lavapipe Vulkan ICD not found under /usr/share/vulkan/icd.d" >&2
ls -la /usr/share/vulkan/icd.d || true
else
echo "Using lavapipe ICD: $LVP_ICD"
echo "VK_ICD_FILENAMES=$LVP_ICD" >> "$GITHUB_ENV"
fi
vulkaninfo --summary || true
- name: Generate full coverage JSON
run: |
cargo llvm-cov --workspace \
--exclude lambda-demos-audio \
--exclude lambda-demos-minimal \
--exclude lambda-demos-render \
--features lambda-rs/with-vulkan,lambda-rs/audio-output-device \
--json \
--output-path coverage.json
- name: Generate HTML coverage report
run: |
cargo llvm-cov --workspace \
--exclude lambda-demos-audio \
--exclude lambda-demos-minimal \
--exclude lambda-demos-render \
--features lambda-rs/with-vulkan,lambda-rs/audio-output-device \
--html \
--output-dir coverage-html \
--no-run
- name: Get changed files in PR
if: github.event_name == 'pull_request'
id: changed
run: |
# Use GitHub's provided base/head SHAs for accurate diff
base_sha="${{ github.event.pull_request.base.sha }}"
head_sha="${{ github.event.pull_request.head.sha }}"
changed_files=$(git diff --name-only "$base_sha" "$head_sha" -- \
'*.rs' \
':(exclude)demos/**' \
| tr '\n' ' ')
echo "files=$changed_files" >> "$GITHUB_OUTPUT"
- name: Generate coverage report data
id: cov
run: |
# Extract total coverage and round to 2 decimal places
pct_raw=$(jq -r '(.data[0].totals.lines.percent // 0)' coverage.json)
pct=$(printf "%.2f" "$pct_raw")
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"
# Extract per-file coverage as JSON for changed files
jq -r '.data[0].files[] | "\(.filename)|\(.summary.lines.percent // 0)|\(.summary.lines.covered // 0)|\(.summary.lines.count // 0)"' coverage.json > file_coverage.txt
- name: Build PR coverage comment
if: github.event_name == 'pull_request'
id: comment
env:
CHANGED_FILES: ${{ steps.changed.outputs.files }}
RUN_ID: ${{ github.run_id }}
REPO: ${{ github.repository }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
run: |
# Base URL for GitHub Pages coverage (from main branch)
PAGES_BASE="https://lambda-sh.github.io/lambda/coverage"
# Get current timestamp in UTC
TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
# Short commit SHA for display
SHORT_SHA="${COMMIT_SHA:0:7}"
# Build the comment body
{
echo "### ✅ Coverage Report"
echo ""
echo "📊 [View Full HTML Report](https://github.com/${REPO}/actions/runs/${RUN_ID}) (download artifact)"
echo ""
echo "#### Overall Coverage"
echo ""
echo "| Metric | Value |"
echo "|--------|-------|"
echo "| **Total Line Coverage** | ${{ steps.cov.outputs.pct }}% |"
echo "| **Lines Covered** | ${{ steps.cov.outputs.covered }} / ${{ steps.cov.outputs.total }} |"
echo ""
# Calculate coverage for changed files
if [ -n "$CHANGED_FILES" ]; then
echo "#### Changed Files in This PR"
echo ""
echo "| File | Coverage | Lines |"
echo "|------|----------|-------|"
pr_covered=0
pr_total=0
for file in $CHANGED_FILES; do
# Find this file in coverage data (match by filename ending)
match=$(grep -E "/${file}\|" file_coverage.txt || grep -E "^${file}\|" file_coverage.txt || true)
if [ -n "$match" ]; then
file_pct=$(echo "$match" | cut -d'|' -f2)
file_covered=$(echo "$match" | cut -d'|' -f3)
file_total=$(echo "$match" | cut -d'|' -f4)
# Format percentage to 2 decimal places
file_pct_fmt=$(printf "%.2f" "$file_pct")
# Create HTML filename (replace / with path structure, add .html)
html_file=$(echo "$file" | sed 's|/|/|g').html
echo "| [\`${file}\`](${PAGES_BASE}/${html_file}) | ${file_pct_fmt}% | ${file_covered}/${file_total} |"
pr_covered=$((pr_covered + file_covered))
pr_total=$((pr_total + file_total))
else
echo "| \`${file}\` | N/A | (no coverage data) |"
fi
done
echo ""
if [ "$pr_total" -gt 0 ]; then
pr_pct=$(echo "scale=2; $pr_covered * 100 / $pr_total" | bc)
echo "**PR Files Coverage:** ${pr_pct}% (${pr_covered}/${pr_total} lines)"
fi
else
echo "*No Rust files changed in this PR.*"
fi
echo ""
echo "---"
echo "*Generated by [cargo-llvm-cov](https://github.com/taiki-e/cargo-llvm-cov) · [Latest main coverage](${PAGES_BASE})*"
echo ""
echo "<sub>Last updated: ${TIMESTAMP} · Commit: [\`${SHORT_SHA}\`](https://github.com/${REPO}/commit/${COMMIT_SHA})</sub>"
} > comment_body.md
# Store as output (handle multiline)
{
echo "body<<EOF"
cat comment_body.md
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Find existing coverage comment
if: github.event_name == 'pull_request'
id: find_comment
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('### ✅ Coverage Report')
);
return botComment ? botComment.id : null;
result-encoding: string
- name: Create or update PR comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const body = fs.readFileSync('comment_body.md', 'utf8');
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const existingCommentId = ${{ steps.find_comment.outputs.result }};
if (existingCommentId) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existingCommentId,
body,
});
console.log(`Updated existing comment ${existingCommentId}`);
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
console.log('Created new coverage comment');
}
- name: Upload coverage HTML as artifact
uses: actions/upload-artifact@v4
with:
name: coverage-html-report
path: coverage-html/
retention-days: 30
- name: Upload coverage JSON as artifact
uses: actions/upload-artifact@v4
with:
name: coverage-json
path: coverage.json
retention-days: 30
# Deploy HTML report to GitHub Pages on pushes to main
deploy-coverage:
name: Deploy coverage to GitHub Pages
needs: coverage
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Download coverage HTML artifact
uses: actions/download-artifact@v4
with:
name: coverage-html-report
path: coverage-html
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: coverage-html
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4