-
-
Notifications
You must be signed in to change notification settings - Fork 1
226 lines (182 loc) · 6.54 KB
/
code-quality.yml
File metadata and controls
226 lines (182 loc) · 6.54 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
name: Code Quality
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
php-quality:
name: PHP Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, xml, curl, json, pdo, pdo_mysql, redis
tools: php-cs-fixer, phpstan, phpcs, psalm
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Run PHP CodeSniffer
run: vendor/bin/phpcs --standard=PSR-12 --report=junit src/ app/ --report-file=reports/phpcs.xml
continue-on-error: true
- name: Run PHP CS Fixer
run: vendor/bin/php-cs-fixer fix --dry-run --diff --verbose --format=junit > reports/php-cs-fixer.xml
continue-on-error: true
- name: Run PHPStan
run: vendor/bin/phpstan analyse --error-format=junit > reports/phpstan.xml
continue-on-error: true
- name: Run Psalm
run: vendor/bin/psalm --output-format=junit > reports/psalm.xml
continue-on-error: true
- name: Upload quality reports
uses: actions/upload-artifact@v6
if: always()
with:
name: php-quality-reports
path: reports/
javascript-quality:
name: JavaScript Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run ESLint
run: npm run lint -- --format=junit --output-file=reports/eslint.xml
continue-on-error: true
- name: Run Prettier
run: npm run format:check -- --output-file=reports/prettier.xml
continue-on-error: true
- name: Run TypeScript compiler
run: npm run type-check -- --output-file=reports/typescript.xml
continue-on-error: true
- name: Upload quality reports
uses: actions/upload-artifact@v6
if: always()
with:
name: js-quality-reports
path: reports/
complexity-analysis:
name: Complexity Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, xml, curl, json, pdo, pdo_mysql, redis
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Run PHPMD
run: vendor/bin/phpmd src/,app/ xml cleancode,codesize,controversial,design,naming,unusedcode --reportfile reports/phpmd.xml
continue-on-error: true
- name: Run PHPLOC
run: vendor/bin/phploc src/,app/ --count-tests --log-xml=reports/phploc.xml
- name: Upload complexity reports
uses: actions/upload-artifact@v6
if: always()
with:
name: complexity-reports
path: reports/
sonarcloud:
name: SonarCloud Analysis
runs-on: ubuntu-latest
needs: [php-quality, javascript-quality, complexity-analysis]
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, xml, curl, json, pdo, pdo_mysql, redis
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '18'
cache: 'npm'
- name: Install npm dependencies
run: npm ci
- name: Run tests with coverage
run: |
vendor/bin/phpunit --coverage-clover=coverage.xml --log-junit=reports/tests.xml
npm run test:coverage
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
quality-gate:
name: Quality Gate
runs-on: ubuntu-latest
needs: [php-quality, javascript-quality, complexity-analysis, sonarcloud]
if: github.event_name == 'pull_request'
steps:
- name: Download all reports
uses: actions/download-artifact@v7
with:
path: reports/
- name: Check quality metrics
run: |
# Check if any critical issues exist
if grep -r "severity=\"critical\"" reports/; then
echo "❌ Critical issues found - blocking merge"
exit 1
fi
# Check code coverage
COVERAGE=$(grep -o 'coverage="[0-9]*\.[0-9]*"' reports/tests.xml | head -1 | cut -d'"' -f2)
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "❌ Code coverage below 80% - blocking merge"
exit 1
fi
echo "✅ Quality gate passed"
- name: Comment PR with quality report
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const path = require('path');
// Read quality reports
const reportsDir = 'reports';
let summary = '## Code Quality Report\n\n';
// Add coverage info
try {
const testReport = fs.readFileSync(path.join(reportsDir, 'tests.xml'), 'utf8');
const coverage = testReport.match(/coverage="([\d.]+)"/);
if (coverage) {
summary += `📊 **Code Coverage**: ${coverage[1]}%\n\n`;
}
} catch (e) {
console.log('Could not read test report');
}
// Add quality metrics
summary += '### Quality Metrics\n';
summary += '- ✅ No critical issues\n';
summary += '- ✅ Code coverage ≥ 80%\n';
summary += '- ✅ All quality checks passed\n\n';
summary += '### Detailed Reports\n';
summary += '- [PHP Quality](./reports/php-quality-reports)\n';
summary += '- [JavaScript Quality](./reports/js-quality-reports)\n';
summary += '- [Complexity Analysis](./reports/complexity-reports)\n';
summary += '- [SonarCloud](https://sonarcloud.io/dashboard?id=${{ github.repository }})\n';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});