Skip to content

Commit 9a28db8

Browse files
loks0nclaude
andauthored
Chore: Consolidate CI workflows and harden test infra (#241)
* Chore: Consolidate CI workflows and harden test infra Merge test/lint/bench workflows into a single ci.yml, add PHPStan to CI, parallelize adapter tests via matrix, replace fixed sleeps with compose healthchecks, pin composer image to 2.7, and bump checkout to v4. Also move ext-swoole to suggest so FPM-only consumers can install without --ignore-platform-reqs, and simplify phpunit.xml discovery. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Chore: Rename CI jobs and split tests into unit/e2e Rename jobs per team convention: Lint -> Format, Static Analysis -> Analyze, Benchmarks -> Benchmark. Split the single Tests matrix into three jobs: Tests / Unit (runs on host PHP, no docker), Tests / E2E / FPM, and Tests / E2E / Swoole. Adds phpunit testsuites (unit, e2e-fpm, e2e-swoole) and moves BaseTest trait to tests/ so it autoloads via its existing PSR-4 namespace. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Ignore ext-opentelemetry platform req for host PHP jobs * Pin composer platform to PHP 8.2 so lock stays 8.2-compatible * Group checks under Checks/ prefix and use matrix for E2E adapters * Rename composer lint script to format:check and align CI job * Rename composer check to analyze; remove misnamed CodeQL workflow The CodeQL workflow did not actually run CodeQL — it ran PHPStan under a misleading name. Checks / Analyze already covers that. * Replace phpbench with k6 benchmark; post results as PR comment Removes phpbench/phpbench (and its Symfony transitive deps) in favour of a k6 HTTP load test targeting the swoole adapter. The CI benchmark job runs k6 against the docker-compose swoole service, uploads the JSON + text summary as an artifact, and posts a sticky PR comment with the default k6 summary output. * Bump k6 load to 60s, shorten PR comment, use grafana/run-k6-action Also updates checkout, cache, upload-artifact, and sticky-comment actions to their latest major versions. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 49a6bd3 commit 9a28db8

16 files changed

Lines changed: 328 additions & 1422 deletions

.github/workflows/bench.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master, "*.x"]
7+
8+
jobs:
9+
format:
10+
name: Checks / Format
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v6
14+
15+
- name: Run Pint
16+
run: |
17+
docker run --rm -v "$PWD":/app -w /app composer:2.7 sh -c \
18+
"composer install --profile --ignore-platform-reqs --no-interaction && composer format:check"
19+
20+
analyze:
21+
name: Checks / Analyze
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v6
25+
26+
- uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: '8.2'
29+
extensions: swoole
30+
coverage: none
31+
32+
- name: Validate composer.json and composer.lock
33+
run: composer validate --strict
34+
35+
- name: Get composer cache directory
36+
id: composer-cache
37+
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
38+
39+
- uses: actions/cache@v5
40+
with:
41+
path: ${{ steps.composer-cache.outputs.dir }}
42+
key: composer-${{ hashFiles('composer.lock') }}
43+
restore-keys: composer-
44+
45+
- name: Install dependencies
46+
run: composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=ext-opentelemetry
47+
48+
- name: PHPStan
49+
run: composer analyze
50+
51+
unit:
52+
name: Tests / Unit
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v6
56+
57+
- uses: shivammathur/setup-php@v2
58+
with:
59+
php-version: '8.2'
60+
extensions: swoole
61+
coverage: none
62+
63+
- name: Get composer cache directory
64+
id: composer-cache
65+
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
66+
67+
- uses: actions/cache@v5
68+
with:
69+
path: ${{ steps.composer-cache.outputs.dir }}
70+
key: composer-${{ hashFiles('composer.lock') }}
71+
restore-keys: composer-
72+
73+
- name: Install dependencies
74+
run: composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=ext-opentelemetry
75+
76+
- name: Run unit tests
77+
run: vendor/bin/phpunit --configuration phpunit.xml --testsuite unit
78+
79+
e2e:
80+
name: Tests / E2E / ${{ matrix.adapter.display }}
81+
runs-on: ubuntu-latest
82+
strategy:
83+
fail-fast: false
84+
matrix:
85+
adapter:
86+
- { id: fpm, display: FPM }
87+
- { id: swoole, display: Swoole }
88+
steps:
89+
- uses: actions/checkout@v6
90+
91+
- name: Build and wait for ${{ matrix.adapter.id }} to be healthy
92+
run: docker compose up -d --build --wait ${{ matrix.adapter.id }}
93+
94+
- name: Run E2E tests
95+
run: docker compose exec -T ${{ matrix.adapter.id }} vendor/bin/phpunit --configuration phpunit.xml --testsuite e2e-${{ matrix.adapter.id }}
96+
97+
- name: Dump container logs on failure
98+
if: failure()
99+
run: docker compose logs ${{ matrix.adapter.id }}
100+
101+
benchmark:
102+
name: Benchmark
103+
runs-on: ubuntu-latest
104+
permissions:
105+
contents: read
106+
pull-requests: write
107+
steps:
108+
- uses: actions/checkout@v6
109+
110+
- name: Build and wait for swoole to be healthy
111+
run: docker compose up -d --build --wait swoole
112+
113+
- name: Setup k6
114+
uses: grafana/setup-k6-action@v1
115+
116+
- name: Run k6 benchmark
117+
uses: grafana/run-k6-action@v1
118+
with:
119+
path: tests/bench/benchmark.js
120+
flags: --summary-export=summary.json
121+
env:
122+
BASE_URL: http://localhost:9501
123+
124+
- name: Render PR comment body
125+
if: always() && hashFiles('summary.json') != ''
126+
run: |
127+
jq -r '
128+
.metrics as $m |
129+
[
130+
"### k6 benchmark",
131+
"",
132+
"| Throughput | Requests | Fail rate | p50 | p95 |",
133+
"| --- | --- | --- | --- | --- |",
134+
"| \(($m.http_reqs.rate // 0) | floor) req/s | \($m.http_reqs.count // 0) | \((($m.http_req_failed.value // 0) * 100) * 1000 | floor / 1000)% | \(($m.http_req_duration.med // 0) * 100 | floor / 100) ms | \(($m.http_req_duration["p(95)"] // 0) * 100 | floor / 100) ms |"
135+
] | .[]
136+
' summary.json > summary.md
137+
138+
- name: Upload raw k6 summary
139+
if: always()
140+
uses: actions/upload-artifact@v7
141+
with:
142+
name: k6-summary
143+
path: summary.json
144+
if-no-files-found: ignore
145+
146+
- name: Comment benchmark summary on PR
147+
if: github.event_name == 'pull_request' && always() && hashFiles('summary.md') != ''
148+
uses: marocchino/sticky-pull-request-comment@v3
149+
with:
150+
header: k6-benchmark
151+
path: summary.md
152+
153+
- name: Dump swoole logs on failure
154+
if: failure()
155+
run: docker compose logs swoole

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
/vendor/
22
/.idea/
3-
*.cache
3+
/.vscode/
4+
/composer.phar
5+
.phpunit.result.cache
6+
/.phpunit.cache/
7+
*.cache

Dockerfile.fpm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM composer:2.0 AS step0
1+
FROM composer:2.7 AS step0
22

33

44
ARG TESTING=true
@@ -38,7 +38,6 @@ COPY ./tests/docker/start /usr/local/bin/start
3838
COPY ./src /usr/share/nginx/html/src
3939
COPY ./tests /usr/share/nginx/html/tests
4040
COPY ./phpunit.xml /usr/share/nginx/html/phpunit.xml
41-
COPY ./phpbench.json /usr/share/nginx/html/phpbench.json
4241
COPY --from=step0 /usr/local/src/vendor /usr/share/nginx/html/vendor
4342

4443
# Supervisord Conf

Dockerfile.swoole

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM composer:2.0 AS step0
1+
FROM composer:2.7 AS step0
22

33

44
ARG TESTING=true
@@ -21,7 +21,6 @@ WORKDIR /usr/src/code
2121
COPY ./src /usr/src/code/src
2222
COPY ./tests /usr/src/code/tests
2323
COPY ./phpunit.xml /usr/src/code/phpunit.xml
24-
COPY ./phpbench.json /usr/src/code/phpbench.json
2524
COPY --from=step0 /usr/local/src/vendor /usr/src/code/vendor
2625

2726
EXPOSE 80

composer.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,35 @@
1515
"Utopia\\": "src/"
1616
}
1717
},
18-
"autoload-dev": {
18+
"autoload-dev": {
1919
"psr-4": {
20-
"Utopia\\Http\\Tests\\": "tests/",
21-
"Tests\\E2E\\": "tests/e2e"
22-
}
20+
"Utopia\\Http\\Tests\\": "tests/",
21+
"Tests\\E2E\\": "tests/e2e"
22+
}
2323
},
2424
"scripts": {
25-
"lint": "vendor/bin/pint --test",
2625
"format": "vendor/bin/pint",
27-
"check": "vendor/bin/phpstan analyse -c phpstan.neon --memory-limit 512M",
28-
"test": "vendor/bin/phpunit --configuration phpunit.xml",
29-
"bench": "vendor/bin/phpbench run --report=benchmark"
26+
"format:check": "vendor/bin/pint --test",
27+
"analyze": "vendor/bin/phpstan analyse -c phpstan.neon --memory-limit 512M",
28+
"test": "vendor/bin/phpunit --configuration phpunit.xml"
3029
},
3130
"require": {
3231
"php": ">=8.2",
33-
"ext-swoole": "*",
3432
"utopia-php/di": "0.3.*",
3533
"utopia-php/servers": "0.3.*",
3634
"utopia-php/compression": "0.1.*",
3735
"utopia-php/telemetry": "0.2.*",
3836
"utopia-php/validators": "0.2.*"
3937
},
38+
"suggest": {
39+
"ext-swoole": "Required to use the Swoole server adapter (\\Utopia\\Http\\Adapter\\Swoole\\Server)."
40+
},
4041
"config": {
42+
"platform": {
43+
"php": "8.2",
44+
"ext-opentelemetry": "1.0.0",
45+
"ext-protobuf": "4.26.1"
46+
},
4147
"allow-plugins": {
4248
"php-http/discovery": true,
4349
"tbachert/spi": true
@@ -46,7 +52,6 @@
4652
"require-dev": {
4753
"doctrine/instantiator": "^1.5",
4854
"laravel/pint": "1.*",
49-
"phpbench/phpbench": "^1.2",
5055
"phpstan/phpstan": "1.*",
5156
"phpunit/phpunit": "^9.5.25",
5257
"swoole/ide-helper": "4.8.3"

0 commit comments

Comments
 (0)