-
Notifications
You must be signed in to change notification settings - Fork 53
397 lines (351 loc) · 16.6 KB
/
quality.yml
File metadata and controls
397 lines (351 loc) · 16.6 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
name: 🔍 Code Quality
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
schedule:
# 每天凌晨 2 点运行质量检查
- cron: "0 2 * * *"
jobs:
# ============================================================================
# 代码格式检查
# ============================================================================
formatting:
name: 💅 Code Formatting
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v6
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package-lock.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup pnpm
if: steps.detect-package-manager.outputs.manager == 'pnpm'
uses: pnpm/action-setup@v6
- name: 📦 Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: 📥 Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: 💅 Check Prettier formatting
run: ${{ steps.detect-package-manager.outputs.manager }} run lint
- name: 🔧 Auto-fix formatting (PR only)
if: github.event_name == 'pull_request'
run: |
${{ steps.detect-package-manager.outputs.manager }} run lint:fix
if [[ -n $(git status --porcelain) ]]; then
echo "## 💅 Formatting Changes Applied" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The following files were auto-formatted:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
git diff --name-only >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
fi
# ============================================================================
# TypeScript 类型检查
# ============================================================================
typescript:
name: 📘 TypeScript Check
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v6
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package-lock.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup pnpm
if: steps.detect-package-manager.outputs.manager == 'pnpm'
uses: pnpm/action-setup@v6
- name: 📦 Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: 📥 Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: 📘 Type check
run: ${{ steps.detect-package-manager.outputs.manager }} run type-check
- name: 📊 Generate type report
run: |
echo "## 📘 TypeScript Analysis" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ No type errors found in the codebase!" >> $GITHUB_STEP_SUMMARY
# ============================================================================
# 依赖检查
# ============================================================================
dependencies:
name: 📦 Dependencies Check
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v6
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package-lock.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup pnpm
if: steps.detect-package-manager.outputs.manager == 'pnpm'
uses: pnpm/action-setup@v6
- name: 📦 Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: 📥 Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: 🔍 Check for outdated packages
run: |
echo "## 📦 Dependency Status" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# 检查过期的包
if ${{ steps.detect-package-manager.outputs.manager }} outdated --json > outdated.json 2>/dev/null; then
if [ -s outdated.json ]; then
echo "### ⚠️ Outdated Packages" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Package | Current | Wanted | Latest |" >> $GITHUB_STEP_SUMMARY
echo "|---------|---------|--------|--------|" >> $GITHUB_STEP_SUMMARY
node -e "
const outdated = require('./outdated.json');
Object.entries(outdated).forEach(([pkg, info]) => {
console.log(\`| \${pkg} | \${info.current} | \${info.wanted} | \${info.latest} |\`);
});
" >> $GITHUB_STEP_SUMMARY
else
echo "✅ All packages are up to date!" >> $GITHUB_STEP_SUMMARY
fi
else
echo "✅ All packages are up to date!" >> $GITHUB_STEP_SUMMARY
fi
- name: 🔒 Security audit
run: |
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🔒 Security Audit" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if ${{ steps.detect-package-manager.outputs.manager }} audit --json > audit.json 2>/dev/null; then
vulnerabilities=$(node -e "
const audit = require('./audit.json');
const total = audit.metadata?.vulnerabilities?.total || 0;
console.log(total);
")
if [ "$vulnerabilities" -gt 0 ]; then
echo "⚠️ Found $vulnerabilities security vulnerabilities" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Run \`${{ steps.detect-package-manager.outputs.manager }} audit fix\` to resolve automatically fixable issues." >> $GITHUB_STEP_SUMMARY
else
echo "✅ No security vulnerabilities found!" >> $GITHUB_STEP_SUMMARY
fi
else
echo "✅ No security vulnerabilities found!" >> $GITHUB_STEP_SUMMARY
fi
# ============================================================================
# 代码复杂度分析
# ============================================================================
complexity:
name: 🧮 Code Complexity
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v6
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package-lock.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup pnpm
if: steps.detect-package-manager.outputs.manager == 'pnpm'
uses: pnpm/action-setup@v6
- name: 📦 Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: 📥 Install dependencies
run: |
${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
${{ steps.detect-package-manager.outputs.manager }} add -D eslint-plugin-complexity
- name: 🧮 Analyze code complexity
run: |
echo "## 🧮 Code Complexity Analysis" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# 分析 config-helpers.ts 的复杂度
if [ -f "utils/config-helpers.ts" ]; then
lines=$(wc -l < utils/config-helpers.ts)
functions=$(grep -c "^export.*function\|^function\|=>" utils/config-helpers.ts || echo "0")
echo "### 📊 Metrics for config-helpers.ts" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Lines of Code | $lines |" >> $GITHUB_STEP_SUMMARY
echo "| Functions | $functions |" >> $GITHUB_STEP_SUMMARY
echo "| Average Lines per Function | $((lines / (functions > 0 ? functions : 1))) |" >> $GITHUB_STEP_SUMMARY
if [ $lines -gt 500 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ **Warning**: File is getting large ($lines lines). Consider splitting into smaller modules." >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ File size is within acceptable limits." >> $GITHUB_STEP_SUMMARY
fi
fi
# Next.js 项目可分析 lib/config-helpers.ts
if [ -f "lib/config-helpers.ts" ]; then
lines=$(wc -l < lib/config-helpers.ts)
functions=$(grep -c "^export.*function\|^function\|=>" lib/config-helpers.ts || echo "0")
echo "### 📊 Metrics for lib/config-helpers.ts" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Lines of Code | $lines |" >> $GITHUB_STEP_SUMMARY
echo "| Functions | $functions |" >> $GITHUB_STEP_SUMMARY
fi
# ============================================================================
# 文档检查
# ============================================================================
documentation:
name: 📚 Documentation Check
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v6
- name: 📚 Check documentation coverage
run: |
echo "## 📚 Documentation Coverage" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# 检查 JSDoc 覆盖率 (utils 或 lib)
for target in utils/config-helpers.ts lib/config-helpers.ts; do
if [ -f "$target" ]; then
total_functions=$(grep -c "^export.*function\|^export const.*=" "$target" || echo "0")
documented_functions=$(grep -B1 "^export.*function\|^export const.*=" "$target" | grep -c "/\*\*" || echo "0")
if [ $total_functions -gt 0 ]; then
coverage=$((documented_functions * 100 / total_functions))
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Total Functions ($target) | $total_functions |" >> $GITHUB_STEP_SUMMARY
echo "| Documented Functions | $documented_functions |" >> $GITHUB_STEP_SUMMARY
echo "| Documentation Coverage | ${coverage}% |" >> $GITHUB_STEP_SUMMARY
if [ $coverage -ge 80 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Good documentation coverage!" >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ Consider adding more JSDoc comments to improve documentation coverage." >> $GITHUB_STEP_SUMMARY
fi
break
fi
fi
done
# 检查 README 文件
if [ -f "tests/README.md" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Test documentation is present." >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ Test documentation is missing." >> $GITHUB_STEP_SUMMARY
fi
# ============================================================================
# 质量总结
# ============================================================================
quality-summary:
name: 📋 Quality Summary
runs-on: ubuntu-latest
needs: [formatting, typescript, dependencies, complexity, documentation]
if: always()
steps:
- name: 📋 Generate quality report
run: |
echo "# 🔍 Code Quality Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📊 Quality Checks Status" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Code Formatting | ${{ needs.formatting.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| TypeScript | ${{ needs.typescript.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Dependencies | ${{ needs.dependencies.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Code Complexity | ${{ needs.complexity.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Documentation | ${{ needs.documentation.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# 计算总体质量分数
passed=0
total=5
${{ needs.formatting.result == 'success' }} && passed=$((passed + 1))
${{ needs.typescript.result == 'success' }} && passed=$((passed + 1))
${{ needs.dependencies.result == 'success' }} && passed=$((passed + 1))
${{ needs.complexity.result == 'success' }} && passed=$((passed + 1))
${{ needs.documentation.result == 'success' }} && passed=$((passed + 1))
score=$((passed * 100 / total))
echo "## 🎯 Overall Quality Score: ${score}%" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ $score -ge 90 ]; then
echo "🎉 **Excellent!** Your code quality is outstanding!" >> $GITHUB_STEP_SUMMARY
elif [ $score -ge 75 ]; then
echo "👍 **Good!** Your code quality is solid with room for minor improvements." >> $GITHUB_STEP_SUMMARY
elif [ $score -ge 60 ]; then
echo "⚠️ **Fair.** Consider addressing the failing quality checks." >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Needs Improvement.** Multiple quality issues need attention." >> $GITHUB_STEP_SUMMARY
fi