-
Notifications
You must be signed in to change notification settings - Fork 0
323 lines (262 loc) · 12 KB
/
code-quality.yml
File metadata and controls
323 lines (262 loc) · 12 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
name: Code Quality
on:
pull_request:
branches: [main, develop]
paths-ignore:
- 'docs/**'
- '**/*.md'
- '!CLAUDE.md'
- '.github/ISSUE_TEMPLATE/**'
- 'LICENSE'
- '.vscode/**'
workflow_call:
permissions:
contents: read
concurrency:
group: code-quality-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
complexity:
name: Complexity & Maintainability
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: ${{ vars.NODE_VERSION || '22' }}
cache: 'yarn'
- name: Cache TypeScript build
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
**/tsconfig.tsbuildinfo
**/.tsbuildinfo
key: tsc-${{ runner.os }}-${{ hashFiles('**/tsconfig.json') }}-${{ hashFiles('**/*.ts') }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Check complexity & maintainability
run: |
echo "## Complexity & Maintainability Check" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Run ESLint with complexity rules (sonarjs plugin)
yarn lint 2>&1 | tee lint-output.txt || true
# Count complexity warnings
COMPLEXITY_WARNINGS=$(grep -c "complexity\|max-depth\|max-lines-per-function\|cognitive-complexity" lint-output.txt || echo "0")
echo "- Complexity warnings: $COMPLEXITY_WARNINGS" >> $GITHUB_STEP_SUMMARY
if [ "$COMPLEXITY_WARNINGS" -gt 20 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "❌ Too many complexity issues ($COMPLEXITY_WARNINGS > 20)" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "✅ Complexity within acceptable limits" >> $GITHUB_STEP_SUMMARY
fi
dead-code:
name: Dead Code Detection
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: ${{ vars.NODE_VERSION || '22' }}
cache: 'yarn'
- name: Cache npx tools
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ~/.npm/_npx
key: npx-tools-${{ runner.os }}-${{ hashFiles('.github/workflows/*.yml') }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run Knip (dead code detection)
run: |
echo "## Dead Code Detection (Knip)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
npx knip --reporter markdown >> $GITHUB_STEP_SUMMARY 2>&1 || true
npx knip --no-exit-code || true
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Dead code analysis complete (review above for potential cleanup)" >> $GITHUB_STEP_SUMMARY
duplicate-code:
name: Duplicate Code Detection
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: ${{ vars.NODE_VERSION || '22' }}
cache: 'yarn'
- name: Cache npx tools
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ~/.npm/_npx
key: npx-tools-${{ runner.os }}-${{ hashFiles('.github/workflows/*.yml') }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run jscpd (duplicate detection)
run: |
echo "## Duplicate Code Detection (jscpd)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
npx jscpd src --min-lines 10 --min-tokens 50 --reporters markdown --output ./jscpd-report || JSCPD_EXIT=$?
if [ -f "./jscpd-report/jscpd-report.md" ]; then
cat ./jscpd-report/jscpd-report.md >> $GITHUB_STEP_SUMMARY
fi
DUPLICATION=$(npx jscpd src --min-lines 10 --min-tokens 50 --reporters json --output ./jscpd-json 2>/dev/null && cat ./jscpd-json/jscpd-report.json | node -e "const d=JSON.parse(require('fs').readFileSync(0));console.log(d.statistics?.total?.percentageTokens||0)" || echo "0")
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Duplication: ${DUPLICATION}%**" >> $GITHUB_STEP_SUMMARY
if [ "$(echo "$DUPLICATION > 5" | bc -l 2>/dev/null || echo 0)" = "1" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "❌ Code duplication too high (${DUPLICATION}% > 5%)" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "✅ Code duplication within acceptable limits" >> $GITHUB_STEP_SUMMARY
fi
- name: Upload duplication report
if: always()
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: jscpd-report
path: jscpd-report/
retention-days: 7
if-no-files-found: ignore
bundle-size:
name: Bundle Size Check
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: ${{ vars.NODE_VERSION || '22' }}
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build project
run: yarn build
- name: Check bundle size
run: |
MAX_SIZE_MB=50
ACTUAL_SIZE=$(du -sm dist | cut -f1)
echo "## Bundle Size Report" >> $GITHUB_STEP_SUMMARY
echo "- Current: ${ACTUAL_SIZE}MB" >> $GITHUB_STEP_SUMMARY
echo "- Limit: ${MAX_SIZE_MB}MB" >> $GITHUB_STEP_SUMMARY
if [ "$ACTUAL_SIZE" -gt "$MAX_SIZE_MB" ]; then
echo "::error::Bundle size ${ACTUAL_SIZE}MB exceeds limit ${MAX_SIZE_MB}MB"
exit 1
fi
echo "✅ Bundle size within limits" >> $GITHUB_STEP_SUMMARY
dependency-size-delta:
name: Dependency Size Delta
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.event_name == 'pull_request'
steps:
- name: Checkout PR branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: ${{ vars.NODE_VERSION || '22' }}
cache: 'yarn'
- name: Install PR dependencies
run: yarn install --frozen-lockfile
- name: Measure PR node_modules size
run: |
PR_SIZE=$(du -sm node_modules | cut -f1)
echo "PR_SIZE=$PR_SIZE" >> $GITHUB_ENV
- name: Checkout base branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.base_ref }}
clean: false
- name: Install base dependencies
run: |
rm -rf node_modules
yarn install --frozen-lockfile
- name: Compare dependency sizes
run: |
BASE_SIZE=$(du -sm node_modules | cut -f1)
DELTA=$((PR_SIZE - BASE_SIZE))
echo "## Dependency Size Delta" >> $GITHUB_STEP_SUMMARY
echo "| Branch | Size |" >> $GITHUB_STEP_SUMMARY
echo "|--------|------|" >> $GITHUB_STEP_SUMMARY
echo "| Base (${{ github.base_ref }}) | ${BASE_SIZE}MB |" >> $GITHUB_STEP_SUMMARY
echo "| PR | ${{ env.PR_SIZE }}MB |" >> $GITHUB_STEP_SUMMARY
echo "| **Delta** | ${DELTA}MB |" >> $GITHUB_STEP_SUMMARY
if [ "$DELTA" -gt 10 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ Dependency size increased by ${DELTA}MB" >> $GITHUB_STEP_SUMMARY
elif [ "$DELTA" -lt -10 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "🎉 Dependency size decreased by ${DELTA#-}MB" >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Dependency size change within acceptable range" >> $GITHUB_STEP_SUMMARY
fi
typedoc-validation:
name: TypeDoc Validation
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: ${{ vars.NODE_VERSION || '22' }}
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run TypeDoc validation
run: |
echo "## TypeDoc Validation" >> $GITHUB_STEP_SUMMARY
npx typedoc src --out typedoc-output 2>&1 | tee typedoc-output.txt || true
WARNING_COUNT=$(grep -c "Warning:" typedoc-output.txt || echo "0")
echo "- Warnings: $WARNING_COUNT" >> $GITHUB_STEP_SUMMARY
echo "- Limit: 20" >> $GITHUB_STEP_SUMMARY
if [ "$WARNING_COUNT" -gt 20 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "❌ Too many TypeDoc warnings ($WARNING_COUNT > 20)" >> $GITHUB_STEP_SUMMARY
echo "::error::TypeDoc warnings ($WARNING_COUNT) exceed limit (20)"
exit 1
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ TypeDoc validation passed" >> $GITHUB_STEP_SUMMARY
fi
quality-summary:
name: Quality Summary
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [complexity, dead-code, duplicate-code, bundle-size, typedoc-validation]
if: always()
steps:
- name: Check job results
run: |
echo "## Code Quality Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Complexity & Maintainability | ${{ needs.complexity.result == 'success' && '✅ Pass' || (needs.complexity.result == 'skipped' && '⏭️ Skipped' || '❌ Fail') }} |" >> $GITHUB_STEP_SUMMARY
echo "| Dead Code Detection | ${{ needs.dead-code.result == 'success' && '✅ Pass' || (needs.dead-code.result == 'skipped' && '⏭️ Skipped' || '❌ Fail') }} |" >> $GITHUB_STEP_SUMMARY
echo "| Duplicate Code Detection | ${{ needs.duplicate-code.result == 'success' && '✅ Pass' || (needs.duplicate-code.result == 'skipped' && '⏭️ Skipped' || '❌ Fail') }} |" >> $GITHUB_STEP_SUMMARY
echo "| Bundle Size Check | ${{ needs.bundle-size.result == 'success' && '✅ Pass' || (needs.bundle-size.result == 'skipped' && '⏭️ Skipped' || '❌ Fail') }} |" >> $GITHUB_STEP_SUMMARY
echo "| TypeDoc Validation | ${{ needs.typedoc-validation.result == 'success' && '✅ Pass' || (needs.typedoc-validation.result == 'skipped' && '⏭️ Skipped' || '❌ Fail') }} |" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.complexity.result }}" == "failure" ]] || \
[[ "${{ needs.duplicate-code.result }}" == "failure" ]] || \
[[ "${{ needs.bundle-size.result }}" == "failure" ]] || \
[[ "${{ needs.typedoc-validation.result }}" == "failure" ]]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "❌ Code quality checks failed" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ All code quality checks passed" >> $GITHUB_STEP_SUMMARY
fi