-
Notifications
You must be signed in to change notification settings - Fork 0
462 lines (403 loc) · 15.5 KB
/
Copy pathci.yml
File metadata and controls
462 lines (403 loc) · 15.5 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
name: CI
on:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
format:
name: Check Formatting (cargo fmt)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --check
clippy:
name: Lint (cargo clippy)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: swatinem/rust-cache@v2
- name: Run Clippy (deny warnings)
run: cargo clippy -- -D warnings
unit-tests:
name: Unit Tests & Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- uses: swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-llvm-cov
- name: Run unit tests with coverage
id: tests
run: |
# Run tests with coverage, capturing both test output and coverage data
TEST_OUTPUT=$(cargo llvm-cov --bin log-workout --lcov --output-path lcov.info 2>&1)
echo "$TEST_OUTPUT"
echo "test_output<<EOF" >> "$GITHUB_OUTPUT"
echo "$TEST_OUTPUT" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Generate coverage summary
id: cov
run: |
SUMMARY=$(cargo llvm-cov report --summary-only 2>&1)
echo "summary<<EOF" >> "$GITHUB_OUTPUT"
echo "$SUMMARY" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Check coverage gate for tested files
id: gate
run: |
# Files that contain unit tests (have #[cfg(test)] blocks)
TESTED_FILES=$(grep -rl '#\[cfg(test)\]' src/ | sort)
echo "Tested files:"
echo "$TESTED_FILES"
FAIL=0
GATE_REPORT=""
for f in $TESTED_FILES; do
# Extract line coverage for this file from lcov.info
IN_FILE=0
LH=0
LF=0
while IFS= read -r line; do
case "$line" in
SF:*"$f") IN_FILE=1 ;;
SF:*) IN_FILE=0 ;;
LH:*) [ "$IN_FILE" = 1 ] && LH="${line#LH:}" ;;
LF:*) [ "$IN_FILE" = 1 ] && LF="${line#LF:}" ;;
esac
done < lcov.info
if [ "$LF" -gt 0 ]; then
PCT=$((LH * 100 / LF))
else
PCT=0
fi
STATUS="✅"
if [ "$PCT" -lt 90 ]; then
STATUS="❌"
FAIL=1
fi
GATE_REPORT="${GATE_REPORT}| ${f} | ${LH}/${LF} | ${PCT}% | ${STATUS} |\n"
echo "$f: $LH/$LF lines covered ($PCT%)"
done
echo "gate_report<<EOF" >> "$GITHUB_OUTPUT"
echo -e "$GATE_REPORT" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "gate_failed=$FAIL" >> "$GITHUB_OUTPUT"
- name: Post unit-test coverage comment
uses: actions/github-script@v7
env:
TEST_OUTPUT: ${{ steps.tests.outputs.test_output }}
SUMMARY: ${{ steps.cov.outputs.summary }}
GATE_REPORT: ${{ steps.gate.outputs.gate_report }}
GATE_FAILED: ${{ steps.gate.outputs.gate_failed }}
with:
script: |
// Access variables via process.env
const testOutput = process.env.TEST_OUTPUT;
const summary = process.env.SUMMARY;
const gateReport = process.env.GATE_REPORT;
const gateFailed = process.env.GATE_FAILED === '1';
const gateStatus = gateFailed
? '❌ **FAILED** — tested files must have ≥ 90% coverage'
: '✅ **PASSED** — all tested files have ≥ 90% coverage';
const tag = '';
const body = `${tag}
## 🧪 Unit Tests & Coverage
### Test Results
\`\`\`
${testOutput}
\`\`\`
### Coverage Summary
\`\`\`
${summary}
\`\`\`
### Coverage Gate ${gateStatus}
| File | Lines Hit/Total | Coverage | Status |
|------|----------------|----------|--------|
${gateReport}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(tag));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Upload lcov report
uses: actions/upload-artifact@v4
with:
name: unit-coverage-lcov
path: lcov.info
retention-days: 7
- name: Fail if coverage gate not met
if: steps.gate.outputs.gate_failed == '1'
run: |
echo "::error::Coverage gate failed: one or more tested files have less than 90% line coverage."
exit 1
e2e:
name: E2E Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-unknown
- uses: swatinem/rust-cache@v2
- name: Install Dioxus CLI
uses: taiki-e/install-action@v2
with:
tool: dioxus-cli
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Run E2E tests
id: e2e
run: npx playwright test
continue-on-error: true
- name: Upload screenshots on failure
if: steps.e2e.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: e2e-screenshots
path: test-results/
if-no-files-found: ignore
- name: Post failure-screenshots comment
if: steps.e2e.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const tag = '';
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
let body = `${tag}\n## 📸 E2E Test Failures\n\n`;
body += `Test failures were detected. You can view and download the full screenshots in the **Artifacts** section of the [Action Run](${runUrl}).\n\n`;
const testResultsDir = 'test-results';
if (fs.existsSync(testResultsDir)) {
const walk = (dir) => {
let files = [];
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) files.push(...walk(full));
else if (entry.name.endsWith('.png')) files.push(entry.name);
}
return files;
};
const pngNames = walk(testResultsDir);
if (pngNames.length > 0) {
body += `### Failed Screenshots Found:\n`;
pngNames.forEach(name => {
body += `- \`${name}\` \n`;
});
} else {
body += '> [!NOTE]\n> No .png files found in the test-results directory.\n';
}
} else {
body += '> [!WARNING]\n> The `test-results` directory was not found.\n';
}
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(tag));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Fail if any E2E test failed
if: steps.e2e.outcome == 'failure'
run: exit 1
lighthouse:
name: PageSpeed Insights (Lighthouse)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-unknown
- uses: swatinem/rust-cache@v2
- name: Install Dioxus CLI
uses: taiki-e/install-action@v2
with:
tool: dioxus-cli
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install Lighthouse CLI
run: npm install -g lighthouse
- name: Start dev server
run: dx serve --port 3000 &
- name: Wait for server
run: |
echo "Waiting for server to be ready..."
for i in $(seq 1 120); do
if curl -sf http://localhost:3000/LogOut/ > /dev/null 2>&1; then
echo "Server is ready."
break
fi
sleep 5
done
- name: Run Lighthouse
id: lighthouse
run: |
lighthouse http://localhost:3000/LogOut/ \
--output json html \
--output-path ./lighthouse-report \
--chrome-flags="--headless --no-sandbox --disable-dev-shm-usage" \
--quiet || true
if [ -f ./lighthouse-report.report.json ]; then
PERF=$(jq '.categories.performance.score * 100 | round' ./lighthouse-report.report.json)
A11Y=$(jq '.categories.accessibility.score * 100 | round' ./lighthouse-report.report.json)
BP=$(jq '(.categories["best-practices"].score // 0) * 100 | round' ./lighthouse-report.report.json)
SEO=$(jq '.categories.seo.score * 100 | round' ./lighthouse-report.report.json)
PWA=$(jq '(.categories.pwa.score // 0) * 100 | round' ./lighthouse-report.report.json)
echo "performance=$PERF" >> "$GITHUB_OUTPUT"
echo "accessibility=$A11Y" >> "$GITHUB_OUTPUT"
echo "best_practices=$BP" >> "$GITHUB_OUTPUT"
echo "seo=$SEO" >> "$GITHUB_OUTPUT"
echo "pwa=$PWA" >> "$GITHUB_OUTPUT"
fi
- name: Upload Lighthouse HTML report
if: always()
uses: actions/upload-artifact@v4
with:
name: lighthouse-report
path: ./lighthouse-report.report.html
if-no-files-found: ignore
retention-days: 7
- name: Post Lighthouse results comment
if: always()
uses: actions/github-script@v7
with:
script: |
const score = s => {
const n = parseInt(s) || 0;
return n >= 90 ? `🟢 ${n}` : n >= 50 ? `🟡 ${n}` : `🔴 ${n}`;
};
const perf = '${{ steps.lighthouse.outputs.performance }}';
const a11y = '${{ steps.lighthouse.outputs.accessibility }}';
const bp = '${{ steps.lighthouse.outputs.best_practices }}';
const seo = '${{ steps.lighthouse.outputs.seo }}';
const pwa = '${{ steps.lighthouse.outputs.pwa }}';
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const tag = '<!-- lighthouse-report -->';
const body = `${tag}
## 🚀 PageSpeed Insights (Lighthouse)
| Category | Score |
|----------|-------|
| ⚡ Performance | ${score(perf)} |
| ♿ Accessibility | ${score(a11y)} |
| 🛡️ Best Practices | ${score(bp)} |
| 🔍 SEO | ${score(seo)} |
| 📱 PWA | ${score(pwa)} |
> 🟢 ≥ 90 · 🟡 50–89 · 🔴 < 50
[📄 Full Lighthouse HTML report](${runUrl})`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(tag));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
preview:
name: PR Preview Build
runs-on: ubuntu-latest
needs: [format, clippy, unit-tests, e2e]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-unknown
- uses: swatinem/rust-cache@v2
- name: Install Dioxus CLI
uses: taiki-e/install-action@v2
with:
tool: dioxus-cli
- name: Build for preview
run: dx build --release --platform web
- name: Upload preview build
uses: actions/upload-artifact@v4
with:
name: pr-preview-build
path: ./target/dx/log-workout/release/web/public
retention-days: 14
- name: Post preview comment
uses: actions/github-script@v7
with:
script: |
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const tag = '<!-- pr-preview -->';
const body = `${tag}\n## 🔍 PR Preview Build\nA preview build of this PR is available as a workflow artifact.\n👉 [Download preview build](${runUrl})\n\n> To view locally, download and serve the artifact with any static file server.`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(tag));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}