-
Notifications
You must be signed in to change notification settings - Fork 3
252 lines (207 loc) · 8.29 KB
/
code-quality.yml
File metadata and controls
252 lines (207 loc) · 8.29 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
name: Code Quality - Advanced Checks
on:
pull_request:
types: [opened, synchronize, reopened, edited]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
issues: write
jobs:
# Check commit messages for Conventional Commits compliance
commit-lint:
name: Commit Message Lint
runs-on: ubuntu-latest
# Skip commit lint for PRs targeting main (release merges have old commits)
if: github.event_name == 'pull_request' && github.base_ref != 'main'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check commit messages
uses: wagoid/commitlint-github-action@v6
with:
configFile: .commitlintrc.json
# Check for TODO/FIXME comments
todo-check:
name: TODO/FIXME Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Find TODOs and FIXMEs
uses: actions/github-script@v7
with:
script: |
const { execSync } = require('child_process');
try {
const todos = execSync('git grep -n -i "TODO\\|FIXME\\|XXX\\|HACK" -- "*.py" "*.ts" "*.tsx" "*.js" "*.jsx" "*.vue" || true').toString();
if (todos.trim()) {
const lines = todos.trim().split('\n');
const count = lines.length;
const comment = `## 📝 TODO/FIXME Found: ${count}\n\n` +
`TODO/FIXME comments detected in code:\n\n` +
'```\n' + lines.slice(0, 20).join('\n') + '\n```\n\n' +
(count > 20 ? `... and ${count - 20} more entries\n\n` : '') +
`💡 Consider creating issues for these tasks.`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}
} catch (error) {
core.info('No TODOs found or error occurred: ' + error.message);
}
# Code complexity check (Python)
complexity-check-python:
name: Python - Complexity Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install tools
run: |
pip install radon
- name: Check cyclomatic complexity
working-directory: ./api
run: |
echo "## 🔍 Cyclomatic Complexity Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Files with high complexity (> 10):" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
radon cc src -s -a --total-average >> $GITHUB_STEP_SUMMARY || true
continue-on-error: true
- name: Check maintainability index
working-directory: ./api
run: |
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📊 Maintainability Index" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
radon mi src -s >> $GITHUB_STEP_SUMMARY || true
continue-on-error: true
# File size check
file-size-check:
name: File Size Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for large files
uses: actions/github-script@v7
with:
script: |
const { execSync } = require('child_process');
const fs = require('fs');
const maxSize = 500; // KB
const files = execSync('find . -type f -name "*.py" -o -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" -o -name "*.vue" | grep -v node_modules | grep -v .venv | grep -v dist | grep -v build').toString().split('\n').filter(Boolean);
const largeFiles = [];
for (const file of files) {
try {
const stats = fs.statSync(file);
const sizeKB = stats.size / 1024;
if (sizeKB > maxSize) {
largeFiles.push({ file, size: sizeKB.toFixed(2) });
}
} catch (e) {
// Skip files that can't be read
}
}
if (largeFiles.length > 0) {
const comment = `## ⚠️ Large Files Detected\n\n` +
`The following files exceed ${maxSize} KB:\n\n` +
largeFiles.map(f => `- \`${f.file}\` - ${f.size} KB`).join('\n') +
`\n\n💡 Consider splitting these files into smaller modules.`;
core.info(comment);
} else {
core.info('No large files found.');
}
# Code duplication check
duplication-check:
name: Code Duplication Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install tools
run: pip install pylint
- name: Check for code duplication (Python)
working-directory: ./api
run: |
echo "## 🔄 Code Duplication Report (Python)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
pylint --disable=all --enable=duplicate-code src/ >> $GITHUB_STEP_SUMMARY || true
continue-on-error: true
# Dependency review and analysis
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v4
with:
fail-on-severity: moderate
comment-summary-in-pr: always
continue-on-error: true
# Performance hints check
performance-hints:
name: Performance Hints
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for performance anti-patterns
uses: actions/github-script@v7
with:
script: |
const { execSync } = require('child_process');
const issues = [];
// Python anti-patterns
try {
const pyLoops = execSync('git grep -n "for.*in.*range.*len" -- "*.py" || true').toString();
if (pyLoops.trim()) {
issues.push('🐌 Found `for i in range(len(x))` loops - use `enumerate()` instead');
}
} catch (e) {}
try {
const pyAppend = execSync('git grep -n "\\.append.*for.*in" -- "*.py" || true').toString();
if (pyAppend.trim()) {
issues.push('🐌 Found loops with `.append()` - consider list comprehensions');
}
} catch (e) {}
// JavaScript/TypeScript anti-patterns
try {
const jsForIn = execSync('git grep -n "for.*in.*Array\\|for.*in.*\\[" -- "*.ts" "*.tsx" "*.js" "*.jsx" || true').toString();
if (jsForIn.trim()) {
issues.push('🐌 Found `for...in` loops for arrays - use `for...of` or `.forEach()` instead');
}
} catch (e) {}
if (issues.length > 0) {
core.info('## 💡 Performance Hints\n\n' + issues.join('\n'));
}
# Summary
quality-checks-summary:
name: Quality Checks Summary
runs-on: ubuntu-latest
needs: [commit-lint, todo-check, complexity-check-python, file-size-check, duplication-check, dependency-review, performance-hints]
if: always()
steps:
- name: Create summary
run: |
echo "# 🎯 Code Quality Checks Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All advanced quality checks have been executed." >> $GITHUB_STEP_SUMMARY
echo "Review the individual job results for details." >> $GITHUB_STEP_SUMMARY