Repository navigation
387 lines (320 loc) · 12.2 KB
/
Copy pathcode-quality-gates.yml
File metadata and controls
387 lines (320 loc) · 12.2 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
name: Code Quality Gates
on:
push:
branches: ['**']
pull_request:
branches: [main]
env:
COVERAGE_THRESHOLD: 85
COMPLEXITY_THRESHOLD: 10
jobs:
eslint-frontend:
name: ESLint - Frontend Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Run ESLint
id: eslint
run: |
npm run lint --workspace=apps/frontend -- --format json --output-file eslint-report.json || true
# Parse and display results
node -e "
const fs = require('fs');
const report = JSON.parse(fs.readFileSync('eslint-report.json', 'utf8'));
let errors = 0, warnings = 0;
report.forEach(file => {
errors += file.errorCount;
warnings += file.warningCount;
});
console.log(\`ESLint Results: \${errors} errors, \${warnings} warnings\`);
if (errors > 0) {
console.log('::error::ESLint found errors');
process.exit(1);
}
"
- name: Upload ESLint report
if: always()
uses: actions/upload-artifact@v4
with:
name: eslint-report
path: eslint-report.json
retention-days: 30
eslint-backend:
name: ESLint - Backend Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Run ESLint
id: eslint
run: |
npm run lint --workspace=apps/backend -- --format json --output-file eslint-report.json || true
# Parse and display results
node -e "
const fs = require('fs');
const report = JSON.parse(fs.readFileSync('eslint-report.json', 'utf8'));
let errors = 0, warnings = 0;
report.forEach(file => {
errors += file.errorCount;
warnings += file.warningCount;
});
console.log(\`ESLint Results: \${errors} errors, \${warnings} warnings\`);
if (errors > 0) {
console.log('::error::ESLint found errors');
process.exit(1);
}
"
- name: Upload ESLint report
if: always()
uses: actions/upload-artifact@v4
with:
name: eslint-backend-report
path: eslint-report.json
retention-days: 30
clippy-contracts:
name: Clippy - Rust Contract Quality
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
components: clippy
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: |
contracts
- name: Run Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
code-coverage:
name: Code Coverage Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Generate frontend coverage
run: npm run test:coverage:frontend
- name: Generate backend coverage
run: npm run test:coverage:backend
- name: Generate SDK coverage
run: npm run test:coverage --workspace=packages/sdk
- name: Check coverage thresholds
run: |
node <<'NODE'
const fs = require('fs');
const threshold = Number(process.env.COVERAGE_THRESHOLD);
const workspaces = [
['Frontend', 'apps/frontend/coverage/coverage-summary.json'],
['Backend', 'apps/backend/coverage/coverage-summary.json'],
['SDK', 'packages/sdk/coverage/coverage-summary.json'],
];
let failed = false;
for (const [name, reportPath] of workspaces) {
if (!fs.existsSync(reportPath)) {
console.error(`::error::${name} coverage report is missing: ${reportPath}`);
failed = true;
continue;
}
const report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
const lines = report.total?.lines?.pct;
if (typeof lines !== 'number') {
console.error(`::error::${name} coverage report has no total line percentage`);
failed = true;
continue;
}
console.log(`${name} line coverage: ${lines}% (minimum ${threshold}%)`);
if (lines < threshold) {
console.error(`::error::${name} line coverage is below ${threshold}%`);
failed = true;
}
}
if (failed) process.exit(1);
NODE
env:
COVERAGE_THRESHOLD: ${{ env.COVERAGE_THRESHOLD }}
- name: Upload coverage reports
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: |
apps/backend/coverage/
apps/frontend/coverage/
packages/sdk/coverage/
retention-days: 30
contracts-coverage:
name: Contracts Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov
- name: Generate contract coverage and enforce threshold
run: |
set -o pipefail
cargo llvm-cov \
--workspace \
--all-features \
--summary-only \
--fail-under-lines "$COVERAGE_THRESHOLD" \
-- --test-threads=1 \
2>&1 | tee contracts-coverage-summary.txt
echo "Contract line coverage minimum: ${COVERAGE_THRESHOLD}%"
- name: Upload contract coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: contracts-coverage-report
path: contracts-coverage-summary.txt
retention-days: 30
- name: Add contract coverage to workflow summary
if: always()
run: |
echo "## Contract Coverage" >> "$GITHUB_STEP_SUMMARY"
echo "Minimum line coverage: **${COVERAGE_THRESHOLD}%**" >> "$GITHUB_STEP_SUMMARY"
if [ -f contracts-coverage-summary.txt ]; then
echo '```' >> "$GITHUB_STEP_SUMMARY"
tail -20 contracts-coverage-summary.txt >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
fi
complexity-analysis:
name: Complexity Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Install complexity analyzer
run: npm install -g complexity-report
- name: Analyze backend complexity
run: |
complexity-report --format json --output backend-complexity.json apps/backend/src || true
node -e "
const fs = require('fs');
const threshold = ${{ env.COMPLEXITY_THRESHOLD }};
try {
const report = JSON.parse(fs.readFileSync('backend-complexity.json', 'utf8'));
let highComplexity = [];
report.forEach(file => {
if (file.complexity > threshold) {
highComplexity.push(\`\${file.name}: \${file.complexity}\`);
}
});
if (highComplexity.length > 0) {
console.log('::warning::High complexity files detected:');
highComplexity.forEach(f => console.log(\` - \${f}\`));
}
} catch (e) {
console.log('Complexity analysis skipped');
}
"
continue-on-error: true
- name: Upload complexity report
if: always()
uses: actions/upload-artifact@v4
with:
name: complexity-report
path: backend-complexity.json
retention-days: 30
quality-gates-summary:
name: Quality Gates Summary
runs-on: ubuntu-latest
needs: [eslint-frontend, eslint-backend, clippy-contracts, code-coverage, contracts-coverage, complexity-analysis]
if: always()
steps:
- name: Generate quality report
run: |
echo "## 📊 Code Quality Gates Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| ESLint (Frontend) | ${{ needs.eslint-frontend.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| ESLint (Backend) | ${{ needs.eslint-backend.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Clippy (Contracts) | ${{ needs.clippy-contracts.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| JavaScript Workspace Coverage | ${{ needs.code-coverage.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Contract Coverage | ${{ needs.contracts-coverage.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Complexity Analysis | ${{ needs.complexity-analysis.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Quality Standards" >> $GITHUB_STEP_SUMMARY
echo "- **Coverage Threshold:** ${{ env.COVERAGE_THRESHOLD }}%" >> $GITHUB_STEP_SUMMARY
echo "- **Complexity Threshold:** ${{ env.COMPLEXITY_THRESHOLD }}" >> $GITHUB_STEP_SUMMARY
echo "- **Linting:** Strict mode (errors block merge)" >> $GITHUB_STEP_SUMMARY
- name: Fail if quality gates failed
if: |
always() && (
needs.eslint-frontend.result == 'failure' ||
needs.eslint-backend.result == 'failure' ||
needs.clippy-contracts.result == 'failure' ||
needs.code-coverage.result == 'failure' ||
needs.contracts-coverage.result == 'failure'
)
run: |
echo "❌ Code quality gates failed"
exit 1
- name: Comment PR with quality report
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const summary = `
## 📊 Code Quality Gates
| Check | Status |
|-------|--------|
| ESLint (Frontend) | ${{ needs.eslint-frontend.result }} |
| ESLint (Backend) | ${{ needs.eslint-backend.result }} |
| Clippy (Contracts) | ${{ needs.clippy-contracts.result }} |
| JavaScript Workspace Coverage | ${{ needs.code-coverage.result }} |
| Contract Coverage | ${{ needs.contracts-coverage.result }} |
| Complexity Analysis | ${{ needs.complexity-analysis.result }} |
### Quality Standards
- **Coverage Threshold:** ${{ env.COVERAGE_THRESHOLD }}%
- **Complexity Threshold:** ${{ env.COMPLEXITY_THRESHOLD }}
- **Linting:** Strict mode (errors block merge)
[View detailed reports](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: summary
});