-
Notifications
You must be signed in to change notification settings - Fork 0
235 lines (200 loc) · 7.37 KB
/
Copy pathquality-gates.yml
File metadata and controls
235 lines (200 loc) · 7.37 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
name: 🚪 Quality Gates
on:
pull_request:
branches: [main]
push:
branches: [main]
env:
NODE_VERSION: 18.x
# Quality Gate Thresholds
MIN_COVERAGE: 80
MAX_BUNDLE_SIZE: 500KB
MAX_BUILD_TIME: 300 # seconds
jobs:
# Coverage Gate
coverage-gate:
name: 📊 Coverage Gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run coverage
run: npm run test:coverage
- name: Check coverage threshold
run: |
COVERAGE=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')
echo "Current coverage: $COVERAGE%"
echo "Required coverage: $MIN_COVERAGE%"
if (( $(echo "$COVERAGE < $MIN_COVERAGE" | bc -l) )); then
echo "❌ Coverage $COVERAGE% is below threshold $MIN_COVERAGE%"
exit 1
else
echo "✅ Coverage gate passed: $COVERAGE%"
fi
# Performance Gate
performance-gate:
name: ⚡ Performance Gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build with timing
run: |
START_TIME=$(date +%s)
npm run build:prod
END_TIME=$(date +%s)
BUILD_TIME=$((END_TIME - START_TIME))
echo "Build time: ${BUILD_TIME}s"
echo "Max allowed: ${MAX_BUILD_TIME}s"
if [ $BUILD_TIME -gt $MAX_BUILD_TIME ]; then
echo "❌ Build time ${BUILD_TIME}s exceeds limit ${MAX_BUILD_TIME}s"
exit 1
else
echo "✅ Performance gate passed: ${BUILD_TIME}s"
fi
- name: Check bundle size
run: |
cp public/manifest.json dist/
cp -r icons dist/
# Calculate total size
TOTAL_SIZE=$(du -sb dist/ | cut -f1)
TOTAL_SIZE_KB=$((TOTAL_SIZE / 1024))
MAX_SIZE_KB=$(echo $MAX_BUNDLE_SIZE | sed 's/KB//')
echo "Bundle size: ${TOTAL_SIZE_KB}KB"
echo "Max allowed: ${MAX_SIZE_KB}KB"
if [ $TOTAL_SIZE_KB -gt $MAX_SIZE_KB ]; then
echo "❌ Bundle size ${TOTAL_SIZE_KB}KB exceeds limit ${MAX_SIZE_KB}KB"
exit 1
else
echo "✅ Bundle size gate passed: ${TOTAL_SIZE_KB}KB"
fi
# TypeScript Strictness Gate
typescript-gate:
name: 📝 TypeScript Gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Verify strict mode compliance
run: |
# Check tsconfig.json for strict settings
STRICT_SETTINGS=(
"strict"
"noImplicitAny"
"strictNullChecks"
"noImplicitReturns"
"noUnusedLocals"
"noUnusedParameters"
)
for setting in "${STRICT_SETTINGS[@]}"; do
if ! grep -q "\"$setting\": true" tsconfig.json; then
echo "❌ Required TypeScript setting '$setting' is not enabled"
exit 1
fi
done
echo "✅ All strict TypeScript settings are enabled"
- name: Type check with strict settings
run: npm run typecheck
# Linting Gate
lint-gate:
name: 🧹 Lint Gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linting
run: npm run lint
- name: Check for TODO/FIXME comments in main branch
if: github.ref == 'refs/heads/main'
run: |
TODO_COUNT=$(find src -type f \( -name "*.ts" -o -name "*.tsx" \) -exec grep -l "TODO\|FIXME\|XXX" {} \; | wc -l)
if [ $TODO_COUNT -gt 0 ]; then
echo "❌ Found $TODO_COUNT files with TODO/FIXME comments in main branch"
find src -type f \( -name "*.ts" -o -name "*.tsx" \) -exec grep -Hn "TODO\|FIXME\|XXX" {} \;
exit 1
else
echo "✅ No TODO/FIXME comments found in main branch"
fi
# Security Gate
security-gate:
name: 🔒 Security Gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Security audit
run: |
# Run npm audit and capture output
if ! npm audit --audit-level high; then
echo "❌ High-severity vulnerabilities found"
exit 1
else
echo "✅ No high-severity vulnerabilities found"
fi
- name: Check for sensitive data patterns
run: |
SENSITIVE_PATTERNS=(
"password"
"secret"
"token"
"key.*=.*['\"][^'\"]{20,}"
"api.*key"
)
for pattern in "${SENSITIVE_PATTERNS[@]}"; do
if find src -type f -name "*.ts" -o -name "*.tsx" | xargs grep -i "$pattern" | grep -v "// safe:" ; then
echo "⚠️ Potential sensitive data pattern found: $pattern"
echo "Add '// safe: reason' comment if this is intentional"
fi
done
# Final Gate Summary
gate-summary:
name: 📋 Quality Gates Summary
needs: [coverage-gate, performance-gate, typescript-gate, lint-gate, security-gate]
if: always()
runs-on: ubuntu-latest
steps:
- name: Generate summary
run: |
echo "## Quality Gates Results" >> $GITHUB_STEP_SUMMARY
echo "| Gate | Status |" >> $GITHUB_STEP_SUMMARY
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Coverage | ${{ needs.coverage-gate.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Performance | ${{ needs.performance-gate.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| TypeScript | ${{ needs.typescript-gate.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Linting | ${{ needs.lint-gate.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security | ${{ needs.security-gate.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
- name: Fail if any gate failed
if: |
needs.coverage-gate.result != 'success' ||
needs.performance-gate.result != 'success' ||
needs.typescript-gate.result != 'success' ||
needs.lint-gate.result != 'success' ||
needs.security-gate.result != 'success'
run: |
echo "❌ One or more quality gates failed"
exit 1