-
-
Notifications
You must be signed in to change notification settings - Fork 0
233 lines (193 loc) · 7.02 KB
/
code-quality.yml
File metadata and controls
233 lines (193 loc) · 7.02 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
# Code Quality and Coverage Workflow
# Runs code quality checks, generates coverage reports, and enforces quality gates
#
# Features:
# - Code coverage with Codecov integration
# - PHPStan static analysis
# - Bundle size analysis
# - Quality gate enforcement
name: Code Quality
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
permissions:
contents: read
pull-requests: write
env:
MIN_COVERAGE: 70
MAX_BUNDLE_SIZE: 50000
jobs:
js-coverage:
name: JavaScript Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests with coverage
run: npm run test:unit -- --coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage/coverage-final.json
flags: javascript
name: js-coverage
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Check coverage threshold
run: |
COVERAGE=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')
echo "JavaScript coverage: $COVERAGE%"
if (( $(echo "$COVERAGE < ${{ env.MIN_COVERAGE }}" | bc -l) )); then
echo "::error::JavaScript coverage ($COVERAGE%) is below minimum threshold (${{ env.MIN_COVERAGE }}%)"
exit 1
fi
echo "✅ JavaScript coverage meets threshold"
php-coverage:
name: PHP Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mysql, zip, xdebug
tools: composer
coverage: xdebug
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run PHPUnit with coverage
run: |
./vendor/bin/phpunit --coverage-clover coverage.xml --coverage-text
env:
XDEBUG_MODE: coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
flags: php
name: php-coverage
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Check coverage threshold
run: |
COVERAGE=$(grep -oP 'Lines:\s+\K[\d.]+' <<< "$(./vendor/bin/phpunit --coverage-text 2>/dev/null)")
echo "PHP coverage: $COVERAGE%"
if (( $(echo "$COVERAGE < ${{ env.MIN_COVERAGE }}" | bc -l) )); then
echo "::warning::PHP coverage ($COVERAGE%) is below minimum threshold (${{ env.MIN_COVERAGE }}%)"
fi
static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
tools: composer
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run PHPStan
run: |
if [ -f "phpstan.neon" ]; then
./vendor/bin/phpstan analyse --error-format=github
else
echo "PHPStan configuration not found, skipping"
fi
continue-on-error: true
- name: Run PHPMD
run: |
if command -v phpmd &> /dev/null; then
phpmd . github phpmd.xml --exclude vendor,node_modules,build
fi
continue-on-error: true
bundle-analysis:
name: Bundle Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build for production
run: npm run build
- name: Analyze bundle size
run: |
echo "## Bundle Size Analysis" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Calculate total size
TOTAL_SIZE=0
echo "| File | Size (bytes) | Size (KB) |" >> $GITHUB_STEP_SUMMARY
echo "|------|-------------|-----------|" >> $GITHUB_STEP_SUMMARY
for file in build/*.js build/*.css build/blocks/*/*.js build/blocks/*/*.css; do
if [ -f "$file" ]; then
SIZE=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file")
SIZE_KB=$(echo "scale=2; $SIZE / 1024" | bc)
FILENAME=$(basename "$file")
echo "| $FILENAME | $SIZE | ${SIZE_KB}KB |" >> $GITHUB_STEP_SUMMARY
TOTAL_SIZE=$((TOTAL_SIZE + SIZE))
fi
done
echo "" >> $GITHUB_STEP_SUMMARY
TOTAL_KB=$(echo "scale=2; $TOTAL_SIZE / 1024" | bc)
echo "**Total: ${TOTAL_KB}KB**" >> $GITHUB_STEP_SUMMARY
echo "Total bundle size: ${TOTAL_SIZE} bytes (${TOTAL_KB}KB)"
if [ "$TOTAL_SIZE" -gt "${{ env.MAX_BUNDLE_SIZE }}" ]; then
echo "::warning::Bundle size (${TOTAL_SIZE}) exceeds recommended maximum (${{ env.MAX_BUNDLE_SIZE }})"
fi
- name: Run size-limit check
run: |
if npm run size 2>/dev/null; then
echo "✅ Bundle size within limits"
else
echo "::warning::Bundle size check failed or not configured"
fi
continue-on-error: true
quality-gate:
name: Quality Gate
runs-on: ubuntu-latest
needs: [js-coverage, php-coverage, static-analysis, bundle-analysis]
if: always()
steps:
- name: Check quality gate status
run: |
JS_COVERAGE="${{ needs.js-coverage.result }}"
PHP_COVERAGE="${{ needs.php-coverage.result }}"
STATIC="${{ needs.static-analysis.result }}"
BUNDLE="${{ needs.bundle-analysis.result }}"
echo "## Quality Gate Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| JavaScript Coverage | $JS_COVERAGE |" >> $GITHUB_STEP_SUMMARY
echo "| PHP Coverage | $PHP_COVERAGE |" >> $GITHUB_STEP_SUMMARY
echo "| Static Analysis | $STATIC |" >> $GITHUB_STEP_SUMMARY
echo "| Bundle Analysis | $BUNDLE |" >> $GITHUB_STEP_SUMMARY
# Fail if critical checks failed
if [[ "$JS_COVERAGE" == "failure" ]] || [[ "$PHP_COVERAGE" == "failure" ]]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "❌ **Quality gate failed** - Coverage requirements not met" >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ **Quality gate passed**" >> $GITHUB_STEP_SUMMARY