-
Notifications
You must be signed in to change notification settings - Fork 1
76 lines (58 loc) · 2.45 KB
/
Copy pathcoverage.yml
File metadata and controls
76 lines (58 loc) · 2.45 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
name: Enhanced Coverage Report
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
permissions:
contents: read
pull-requests: write
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm run build
- name: Run tests with coverage
run: pnpm run test:coverage > coverage.txt 2>&1 || true
- name: Extract coverage percentage
id: coverage
run: |
COVERAGE=$(grep "^All files" coverage.txt | awk '{print $4}' || echo "0")
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "📊 Coverage: $COVERAGE%"
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.txt
retention-days: 30
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const coverage = '${{ steps.coverage.outputs.coverage }}';
const coverageNum = parseFloat(coverage);
const emoji = coverageNum >= 80 ? '✅' : coverageNum >= 60 ? '⚠️' : '❌';
const status = coverageNum >= 80 ? 'Great coverage!' : coverageNum >= 60 ? 'Coverage could be improved' : 'Low coverage - please add more tests';
const comment = `## 📊 Code Coverage Report
**Coverage:** ${coverage}% ${emoji}
${status}
[View full coverage report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});