forked from SoroLabs/SoroTask
-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (169 loc) · 6.78 KB
/
Copy pathcoverage.yml
File metadata and controls
196 lines (169 loc) · 6.78 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
name: Code Coverage
on:
pull_request:
branches: [main, develop]
push:
branches: [main, develop]
concurrency:
group: coverage-${{ github.ref }}
cancel-in-progress: true
jobs:
coverage:
name: Generate Coverage Reports
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# ============== RUST COVERAGE ==============
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: contract
- name: Install tarpaulin
run: cargo install cargo-tarpaulin --locked
continue-on-error: true
- name: Generate Rust coverage
working-directory: contract
run: |
mkdir -p ../coverage/rust
cargo tarpaulin \
--out Xml \
--output-dir ../coverage/rust \
--timeout 600 \
--exclude-files "fuzz/*" \
--skip-clean \
--lib \
--tests \
--release 2>&1 || echo "⚠️ Rust coverage generation encountered errors (pre-existing codebase issues). This is expected and will be fixed."
continue-on-error: true
# ============== NODE.JS COVERAGE ==============
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
- name: Install root dependencies
run: npm ci
- name: Install frontend dependencies
working-directory: frontend
run: npm ci
- name: Generate frontend coverage
working-directory: frontend
run: npm run test:coverage
continue-on-error: true
- name: Create coverage directories
run: |
mkdir -p coverage/frontend
mkdir -p coverage/rust
- name: Move frontend coverage to root
run: |
if [ -d "frontend/coverage" ]; then
cp -r frontend/coverage/* coverage/frontend/ || true
fi
shell: bash
# ============== CODECOV UPLOAD ==============
- name: Upload Rust coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/rust/cobertura.xml
flags: rust
name: rust-coverage
fail_ci_if_error: false
verbose: true
- name: Upload frontend coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/frontend/coverage-final.json
flags: frontend
name: frontend-coverage
fail_ci_if_error: false
verbose: true
# ============== PR COMMENT ==============
- name: Comment PR with coverage summary
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let coverageComment = '## 📊 Code Coverage Report\n\n';
let hasContent = false;
let rustAvailable = false;
// Parse Rust coverage
try {
const xmlPath = './coverage/rust/cobertura.xml';
if (fs.existsSync(xmlPath)) {
const xml = fs.readFileSync(xmlPath, 'utf8');
const lineRateMatch = xml.match(/line-rate="([\d.]+)"/);
const branchRateMatch = xml.match(/branch-rate="([\d.]+)"/);
if (lineRateMatch || branchRateMatch) {
coverageComment += '### 🦀 Rust Backend (Contract)\n';
if (lineRateMatch) {
const lineCoverage = (parseFloat(lineRateMatch[1]) * 100).toFixed(2);
coverageComment += `- **Line Coverage**: ${lineCoverage}%\n`;
}
if (branchRateMatch) {
const branchCoverage = (parseFloat(branchRateMatch[1]) * 100).toFixed(2);
coverageComment += `- **Branch Coverage**: ${branchCoverage}%\n`;
}
coverageComment += '\n';
hasContent = true;
rustAvailable = true;
}
}
} catch (e) {
console.log('Rust coverage not available');
}
if (!rustAvailable) {
coverageComment += '### 🦀 Rust Backend (Contract)\n⚠️ **Status**: Build errors in codebase - coverage not available\n_Will be enabled once contract code is updated_\n\n';
}
// Parse Node.js coverage
try {
const summaryPath = './coverage/frontend/coverage-summary.json';
if (fs.existsSync(summaryPath)) {
const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8'));
const total = summary.total;
coverageComment += '### 📱 Frontend (Next.js)\n';
coverageComment += `- **Statements**: ${total.statements.pct}%\n`;
coverageComment += `- **Branches**: ${total.branches.pct}%\n`;
coverageComment += `- **Functions**: ${total.functions.pct}%\n`;
coverageComment += `- **Lines**: ${total.lines.pct}%\n\n`;
hasContent = true;
}
} catch (e) {
console.log('Frontend coverage not available');
}
if (hasContent) {
coverageComment += `---\n[View detailed report on Codecov](https://codecov.io/gh/${{ github.repository }}/pull/${{ github.event.number }})`;
// Find or create bot comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body &&
comment.body.includes('Code Coverage Report')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: coverageComment,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: coverageComment,
});
}
}