-
-
Notifications
You must be signed in to change notification settings - Fork 0
404 lines (336 loc) · 12 KB
/
qa.yml
File metadata and controls
404 lines (336 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# Comprehensive QA Pipeline
# Uses `core php` CLI where available, reports results via PR comments and SARIF
#
# Results:
# - PR comment with summary table
# - SARIF upload to GitHub Security tab
# - JSON artifacts for downstream processing
name: QA Pipeline
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
security-events: write
env:
PHP_VERSION: '8.3'
CORE_VERSION: 'latest'
jobs:
# ============================================================
# Install Core CLI
# ============================================================
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
core-version: ${{ steps.core.outputs.version }}
steps:
- name: Install Core CLI
id: core
run: |
# Try to download core CLI, fall back to skip if not available
if curl -fsSL "https://github.com/host-uk/core/releases/latest/download/core-linux-amd64.tar.gz" -o core.tar.gz 2>/dev/null; then
tar -xzf core.tar.gz
sudo mv core /usr/local/bin/core
chmod +x /usr/local/bin/core
echo "version=$(core --version 2>/dev/null || echo 'unknown')" >> $GITHUB_OUTPUT
echo "available=true" >> $GITHUB_OUTPUT
else
echo "version=unavailable" >> $GITHUB_OUTPUT
echo "available=false" >> $GITHUB_OUTPUT
fi
# ============================================================
# Tests
# ============================================================
test:
name: Tests
runs-on: ubuntu-latest
outputs:
tests: ${{ steps.test.outputs.tests }}
assertions: ${{ steps.test.outputs.assertions }}
status: ${{ steps.test.outputs.status }}
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
coverage: xdebug
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress
- name: Run tests
id: test
run: |
set +e
OUTPUT=$(vendor/bin/phpunit --log-junit test-results.xml 2>&1)
EXIT_CODE=$?
echo "$OUTPUT"
# Extract test counts
TESTS=$(echo "$OUTPUT" | grep -oP '\d+(?= tests)' | head -1 || echo "0")
ASSERTIONS=$(echo "$OUTPUT" | grep -oP '\d+(?= assertions)' | head -1 || echo "0")
echo "tests=${TESTS:-0}" >> $GITHUB_OUTPUT
echo "assertions=${ASSERTIONS:-0}" >> $GITHUB_OUTPUT
if [ $EXIT_CODE -eq 0 ]; then
echo "status=✓" >> $GITHUB_OUTPUT
else
echo "status=✗" >> $GITHUB_OUTPUT
fi
exit $EXIT_CODE
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: test-results.xml
# ============================================================
# Static Analysis - PHPStan
# ============================================================
phpstan:
name: PHPStan
runs-on: ubuntu-latest
outputs:
errors: ${{ steps.stan.outputs.errors }}
status: ${{ steps.stan.outputs.status }}
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
coverage: none
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress
- name: Run PHPStan
id: stan
run: |
set +e
vendor/bin/phpstan analyse --error-format=json --no-progress > phpstan.json 2>&1
EXIT_CODE=$?
# Also run for GitHub format
vendor/bin/phpstan analyse --error-format=github --no-progress 2>&1 || true
ERRORS=$(jq '.totals.file_errors // 0' phpstan.json 2>/dev/null || echo "0")
echo "errors=${ERRORS}" >> $GITHUB_OUTPUT
if [ $EXIT_CODE -eq 0 ]; then
echo "status=✓" >> $GITHUB_OUTPUT
else
echo "status=✗" >> $GITHUB_OUTPUT
fi
exit $EXIT_CODE
- name: Upload PHPStan results
if: always()
uses: actions/upload-artifact@v4
with:
name: phpstan-results
path: phpstan.json
# ============================================================
# Static Analysis - Psalm
# ============================================================
psalm:
name: Psalm
runs-on: ubuntu-latest
outputs:
errors: ${{ steps.psalm.outputs.errors }}
status: ${{ steps.psalm.outputs.status }}
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
coverage: none
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress
- name: Run Psalm
id: psalm
run: |
set +e
vendor/bin/psalm --output-format=json --show-info=false > psalm.json 2>&1
EXIT_CODE=$?
# Generate SARIF for GitHub Security
vendor/bin/psalm --output-format=sarif --show-info=false > psalm.sarif 2>&1 || true
ERRORS=$(jq 'length' psalm.json 2>/dev/null || echo "0")
echo "errors=${ERRORS}" >> $GITHUB_OUTPUT
if [ $EXIT_CODE -eq 0 ]; then
echo "status=✓" >> $GITHUB_OUTPUT
else
echo "status=✗" >> $GITHUB_OUTPUT
fi
exit $EXIT_CODE
- name: Upload Psalm SARIF
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: psalm.sarif
category: psalm
continue-on-error: true
- name: Upload Psalm results
if: always()
uses: actions/upload-artifact@v4
with:
name: psalm-results
path: |
psalm.json
psalm.sarif
# ============================================================
# Code Style
# ============================================================
style:
name: Code Style
runs-on: ubuntu-latest
outputs:
files: ${{ steps.fmt.outputs.files }}
status: ${{ steps.fmt.outputs.status }}
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
extensions: dom, curl, libxml, mbstring, zip
coverage: none
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress
- name: Check code style
id: fmt
run: |
set +e
OUTPUT=$(vendor/bin/pint --test --format=json 2>&1)
EXIT_CODE=$?
echo "$OUTPUT" > pint.json
FILES=$(echo "$OUTPUT" | jq '.files | length' 2>/dev/null || echo "0")
echo "files=${FILES}" >> $GITHUB_OUTPUT
if [ $EXIT_CODE -eq 0 ]; then
echo "status=✓" >> $GITHUB_OUTPUT
else
echo "status=⚠" >> $GITHUB_OUTPUT
fi
# Don't fail on style issues, just report
exit 0
- name: Upload style results
if: always()
uses: actions/upload-artifact@v4
with:
name: style-results
path: pint.json
# ============================================================
# Security Audit
# ============================================================
security:
name: Security
runs-on: ubuntu-latest
outputs:
vulnerabilities: ${{ steps.audit.outputs.vulnerabilities }}
status: ${{ steps.audit.outputs.status }}
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
extensions: dom, curl, libxml, mbstring, zip
coverage: none
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress
- name: Security audit
id: audit
run: |
set +e
composer audit --format=json > audit.json 2>&1
EXIT_CODE=$?
VULNS=$(jq '.advisories | to_entries | map(.value | length) | add // 0' audit.json 2>/dev/null || echo "0")
echo "vulnerabilities=${VULNS}" >> $GITHUB_OUTPUT
if [ $EXIT_CODE -eq 0 ]; then
echo "status=✓" >> $GITHUB_OUTPUT
else
echo "status=✗" >> $GITHUB_OUTPUT
fi
# Report but don't fail
exit 0
- name: Upload audit results
if: always()
uses: actions/upload-artifact@v4
with:
name: audit-results
path: audit.json
# ============================================================
# Summary Report
# ============================================================
report:
name: Report
runs-on: ubuntu-latest
needs: [test, phpstan, psalm, style, security]
if: always()
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./results
- name: Generate summary
id: summary
run: |
cat << 'EOF' > summary.md
## QA Pipeline Results
| Check | Status | Details |
|-------|--------|---------|
| Tests | ${{ needs.test.outputs.status }} | ${{ needs.test.outputs.tests }} tests, ${{ needs.test.outputs.assertions }} assertions |
| PHPStan | ${{ needs.phpstan.outputs.status }} | ${{ needs.phpstan.outputs.errors }} errors |
| Psalm | ${{ needs.psalm.outputs.status }} | ${{ needs.psalm.outputs.errors }} issues |
| Code Style | ${{ needs.style.outputs.status }} | ${{ needs.style.outputs.files }} files need formatting |
| Security | ${{ needs.security.outputs.status }} | ${{ needs.security.outputs.vulnerabilities }} vulnerabilities |
<details>
<summary>Artifacts</summary>
- `test-results.xml` - JUnit test results
- `phpstan.json` - PHPStan analysis
- `psalm.json` / `psalm.sarif` - Psalm analysis
- `pint.json` - Code style report
- `audit.json` - Security audit
</details>
---
*Generated by [core php qa](https://github.com/host-uk/core) pipeline*
EOF
cat summary.md >> $GITHUB_STEP_SUMMARY
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const summary = fs.readFileSync('summary.md', 'utf8');
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('QA Pipeline Results')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: summary
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: summary
});
}
- name: Upload combined results
uses: actions/upload-artifact@v4
with:
name: qa-summary
path: |
summary.md
results/