-
-
Notifications
You must be signed in to change notification settings - Fork 76
382 lines (342 loc) · 14.5 KB
/
tests.yml
File metadata and controls
382 lines (342 loc) · 14.5 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
name: Unit & Integration Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
php-lint:
name: PHP Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup PHP
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
with:
php-version: '8.2'
tools: none
- name: Check PHP syntax
run: |
echo "Checking PHP syntax across the codebase..."
errors=0
while IFS= read -r file; do
if ! php -l "$file" 2>&1 | grep -q "No syntax errors"; then
php -l "$file"
errors=$((errors + 1))
fi
done < <(find inc/ -name '*.php' -type f)
if [ "$errors" -gt 0 ]; then
echo ""
echo "Found $errors file(s) with syntax errors."
exit 1
fi
echo "All PHP files passed syntax check."
php-tests:
name: PHP ${{ matrix.php-version }}
needs: php-lint
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.php-version == '8.5' }}
strategy:
fail-fast: false
matrix:
php-version: ["8.2", "8.3", "8.4", "8.5"]
services:
mysql:
image: mariadb:11.4
env:
MYSQL_ROOT_PASSWORD: root
ports: [3306]
options: >-
--health-cmd="healthcheck.sh --connect --innodb_initialized"
--health-interval=10s
--health-timeout=5s
--health-retries=5
container:
image: cimg/php:${{ matrix.php-version }}
options: --user root
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up Composer global bin path
run: |
mkdir -p "$HOME/.config/composer/vendor/bin"
echo "PATH=$HOME/.config/composer/vendor/bin:$PATH" >> $GITHUB_ENV
- name: Install System Dependencies
run: |
# Remove broken packagecloud git-lfs source that returns 403 in cimg/php:8.5
rm -f /etc/apt/sources.list.d/github_git-lfs.list 2>/dev/null || true
apt-get update && apt-get install -y subversion mariadb-client
- name: Install PHP Extensions
run: |
install-php-extensions mysqli gd bcmath || echo "Extensions may already be installed."
- name: Install Xdebug for Coverage
if: matrix.php-version == '8.3'
run: |
install-php-extensions xdebug || echo "Xdebug may already be installed."
- name: Self-update Composer
run: |
composer self-update || echo "Composer update skipped due to permission issue."
- name: Install PHP Dependencies
run: |
composer install --no-interaction --prefer-dist
- name: Wait for MySQL to be ready
run: |
for i in {1..30}; do
if mysqladmin ping -h mysql --silent; then
echo "MySQL is up"
break
fi
echo "Waiting for MySQL..."
sleep 2
done
- name: Prepare WordPress Tests
run: |
rm -rf /tmp/wordpress-tests-lib /tmp/wordpress/
bash bin/install-wp-tests.sh wordpress_test root root mysql latest
ln -s "$GITHUB_WORKSPACE" /tmp/wordpress/wp-content/plugins/ultimate-multisite
- name: Run PHPUnit Tests
if: matrix.php-version != '8.3'
run: vendor/bin/phpunit
- name: Run PHPUnit Tests with Coverage
if: matrix.php-version == '8.3'
run: |
php -d zend_extension=xdebug.so -d xdebug.mode=coverage \
vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-text \
| tee coverage-summary.txt
- name: Upload coverage to Codecov
if: matrix.php-version == '8.3'
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5
with:
file: ./coverage.xml
flags: unittests
name: php-${{ matrix.php-version }}
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
wp-performance:
name: WP Performance Metrics
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
continue-on-error: true
permissions:
contents: read
pull-requests: write
env:
PERF_ACTION_DIR: .wp-performance-action/env
WP_PERF_ARTIFACTS: ${{ github.workspace }}/.wp-performance-action/env/artifacts
steps:
# ── Checkout both branches ──────────────────────────────────────
- name: Checkout PR branch
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
path: current
- name: Checkout base branch (main)
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
ref: ${{ github.base_ref }}
path: baseline
# ── Environment setup ───────────────────────────────────────────
- name: Setup PHP
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
with:
php-version: "8.2"
- name: Install PHP dependencies (both branches)
run: |
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --working-dir=current
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --working-dir=baseline
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: lts/*
- name: Checkout wp-performance-action
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
repository: swissspidy/wp-performance-action
ref: 233d525186e4d41bc7574837a3baeb3b5698656f
path: .wp-performance-action
- name: Install performance action dependencies
run: npm ci
working-directory: .wp-performance-action/env
- name: Install Playwright browsers
run: npx playwright install --with-deps
working-directory: .wp-performance-action/env
- name: Prepare merged blueprint
run: |
BLUEPRINT=$(realpath "$GITHUB_WORKSPACE/current/.github/performance-blueprint.json")
jq -s 'map(to_entries)|flatten|group_by(.key)|map({(.[0].key):map(.value)|add})|add' \
./blueprints/setup.json "$BLUEPRINT" > ./blueprints/tmp-merged.json
echo "Merged blueprint:"
cat ./blueprints/tmp-merged.json | jq '.'
working-directory: .wp-performance-action/env
# ── Baseline run (main branch) ─────────────────────────────────
- name: Start server with baseline plugin
run: |
BASELINE_PATH=$(realpath "$GITHUB_WORKSPACE/baseline")
./node_modules/@wp-playground/cli/wp-playground.js server \
--mount="./wp-content/mu-plugins:/wordpress/wp-content/mu-plugins" \
--mount="$BASELINE_PATH:/wordpress/wp-content/plugins/ultimate-multisite" \
--blueprint="./blueprints/tmp-merged.json" \
--wp=6.8 \
--php=8.2 &
echo $! > /tmp/playground.pid
working-directory: .wp-performance-action/env
- name: Wait for baseline server
run: |
echo "Waiting for baseline server on port 9400..."
for i in $(seq 1 60); do
if curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then
echo "Server is ready after ${i}s"
exit 0
fi
echo " attempt $i/60..."
sleep 5
done
echo "ERROR: Server did not become ready within 300 seconds"
exit 1
- name: Run baseline performance tests
run: |
mkdir -p "$WP_PERF_ARTIFACTS"
for attempt in 1 2 3; do
echo "--- Baseline attempt $attempt/3 ---"
if ! curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then
echo "Server not responding — skipping"
continue
fi
if npm run test:performance; then
echo "Baseline tests passed on attempt $attempt"
# Save baseline results
cp "$WP_PERF_ARTIFACTS/performance-results.json" \
"$RUNNER_TEMP/baseline-results.json"
echo "baseline_ok=true" >> "$GITHUB_ENV"
exit 0
fi
echo "Baseline tests failed on attempt $attempt"
[ "$attempt" -lt 3 ] && sleep 10
done
echo "All baseline attempts failed — will run PR tests without comparison"
echo "baseline_ok=false" >> "$GITHUB_ENV"
working-directory: .wp-performance-action/env
env:
WP_BASE_URL: http://127.0.0.1:9400
WP_ARTIFACTS_PATH: ${{ github.workspace }}/.wp-performance-action/env/artifacts
BLOB_REPORT_PATH: ${{ github.workspace }}/.wp-performance-action/env/blob-report
SHARD: ""
URLS_TO_TEST: /
DEBUG: "true"
TEST_ITERATIONS: "20"
TEST_REPETITIONS: "2"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
- name: Stop baseline server
run: |
npm run stop-server 2>/dev/null || true
# Clean artifacts for the PR run
rm -rf "$WP_PERF_ARTIFACTS"
working-directory: .wp-performance-action/env
# ── PR branch run ───────────────────────────────────────────────
- name: Start server with PR branch plugin
run: |
CURRENT_PATH=$(realpath "$GITHUB_WORKSPACE/current")
./node_modules/@wp-playground/cli/wp-playground.js server \
--mount="./wp-content/mu-plugins:/wordpress/wp-content/mu-plugins" \
--mount="$CURRENT_PATH:/wordpress/wp-content/plugins/ultimate-multisite" \
--blueprint="./blueprints/tmp-merged.json" \
--wp=6.8 \
--php=8.2 &
working-directory: .wp-performance-action/env
- name: Wait for PR server
run: |
echo "Waiting for PR server on port 9400..."
for i in $(seq 1 60); do
if curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then
echo "Server is ready after ${i}s"
exit 0
fi
echo " attempt $i/60..."
sleep 5
done
echo "ERROR: Server did not become ready within 300 seconds"
exit 1
- name: Run PR branch performance tests
run: |
mkdir -p "$WP_PERF_ARTIFACTS"
for attempt in 1 2 3; do
echo "--- PR branch attempt $attempt/3 ---"
if ! curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then
echo "Server not responding — skipping"
continue
fi
if npm run test:performance; then
echo "PR tests passed on attempt $attempt"
exit 0
fi
echo "PR tests failed on attempt $attempt"
[ "$attempt" -lt 3 ] && sleep 10
done
echo "All 3 attempts failed"
exit 1
working-directory: .wp-performance-action/env
env:
WP_BASE_URL: http://127.0.0.1:9400
WP_ARTIFACTS_PATH: ${{ github.workspace }}/.wp-performance-action/env/artifacts
BLOB_REPORT_PATH: ${{ github.workspace }}/.wp-performance-action/env/blob-report
SHARD: ""
URLS_TO_TEST: /
DEBUG: "true"
TEST_ITERATIONS: "20"
TEST_REPETITIONS: "2"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
- name: Stop server
if: always()
run: npm run stop-server 2>/dev/null || true
working-directory: .wp-performance-action/env
# ── Generate comparison report ──────────────────────────────────
- name: Generate performance comparison report
id: prepare-results
if: always()
run: |
RESULTS_JSON="$WP_PERF_ARTIFACTS/performance-results.json"
if [ ! -f "$RESULTS_JSON" ]; then
echo "No PR results found — skipping report"
exit 0
fi
# Build the results.js arguments: after-file [before-file]
ARGS="$RESULTS_JSON"
if [ "$baseline_ok" = "true" ] && [ -f "$RUNNER_TEMP/baseline-results.json" ]; then
ARGS="$RESULTS_JSON $RUNNER_TEMP/baseline-results.json"
echo "Generating comparison report (PR vs main)..."
else
echo "Generating report (PR branch only, no baseline available)..."
fi
REPOSITORY_URL="${{ github.server_url }}/${{ github.repository }}" \
npm run test:performance:results $ARGS
working-directory: .wp-performance-action/env
- name: Add workflow summary
if: always()
run: |
if [ -f "$WP_PERF_ARTIFACTS/performance-results.md" ]; then
cat "$WP_PERF_ARTIFACTS/performance-results.md" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload performance results
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
with:
name: performance-results-${{ github.run_number }}
path: |
.wp-performance-action/env/artifacts/
${{ runner.temp }}/baseline-results.json
retention-days: 30
- name: Check if a comment was already made
id: find-comment
if: github.event.pull_request.head.repo.full_name == github.repository
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: Performance test results for
- name: Comment on PR with performance results
if: github.event.pull_request.head.repo.full_name == github.repository && hashFiles('.wp-performance-action/env/artifacts/performance-results.md') != ''
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body-path: .wp-performance-action/env/artifacts/performance-results.md
token: ${{ secrets.GITHUB_TOKEN }}