-
Notifications
You must be signed in to change notification settings - Fork 5
500 lines (426 loc) · 19.9 KB
/
lint-and-test.yml
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
name: Lint and Test
on:
push:
branches:
- main
pull_request:
jobs:
lint-js:
name: JS Lints
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Lint JS
run: npm run lint
lint-php:
name: PHP Lints
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none
tools: composer, cs2pr
- name: Install PHP dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6
with:
composer-options: '--prefer-dist --no-scripts'
- name: Validate composer.json
run: composer validate --no-check-all --strict
# So PHPStan uses information from the latest version
- name: Update PHPUnit
run: |
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
- name: Lint PHP
run: composer lint
- name: PHPStan
run: composer phpstan
unit-php:
name: 'PHP ${{ matrix.php }} - WP ${{ matrix.wp }}'
runs-on: ubuntu-latest
services:
mysql:
image: mariadb:latest
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
MARIADB_DATABASE: wordpress_test
MARIADB_MYSQL_LOCALHOST_USER: 1
MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE
ports:
- 3306
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
php: ['8.2', '8.1', '8.0', '7.4', '7.3', '7.2', '7.1', '7.0']
wp: ['latest']
coverage: [false]
experimental: [false]
include:
- php: '8.0'
wp: 'latest'
coverage: true
experimental: false
- php: '7.4'
wp: 'trunk'
experimental: true
- php: '8.3'
wp: 'trunk'
experimental: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mysql
coverage: ${{ matrix.coverage == true && 'xdebug' || 'none' }}
tools: composer, cs2pr
- name: Install PHP dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6
with:
composer-options: '--prefer-dist --no-scripts'
- name: Shutdown default MySQL service
run: sudo service mysql stop
- name: Set up tests
run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true
# Installs a different PHPUnit version depending on the WP/PHP version combo we're testing against.
#
# | WP / PHP | PHPUnit |
# |-----------|---------|
# | * / 7.0 | 6 |
# | * / 7.1 | 7 |
# | * / 7.2 | 8 |
# | * / 7.4 | 9 |
# | * / 8 | 9 |
#
# See https://make.wordpress.org/core/handbook/references/phpunit-compatibility-and-wordpress-versions/
- name: Update PHPUnit
run: |
if [[ $PHP_VERSION == "7.4" || $PHP_VERSION == "8.0" || $PHP_VERSION == "8.1" || $PHP_VERSION == "8.2" || $PHP_VERSION == "8.3" ]]; then
echo "Installing latest version of PHPUnit"
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
fi
env:
WP_VERSION: ${{ matrix.wp }}
PHP_VERSION: ${{ matrix.php }}
- name: Run tests
run: composer test
if: ${{ ! matrix.coverage }}
- name: Run tests with coverage
run: composer test:coverage
if: ${{ matrix.coverage }}
- name: Upload code coverage report
uses: codecov/codecov-action@v3.1.4
with:
file: coverage.xml
flags: default
if: ${{ matrix.coverage }}
- name: Upload code coverage report
uses: codecov/codecov-action@v3.1.4
with:
file: coverage-integration.xml
flags: default
if: ${{ matrix.coverage }}
- name: Upload code coverage report
uses: codecov/codecov-action@v3.1.4
with:
file: coverage-integration-multisite.xml
flags: multisite
if: ${{ matrix.coverage }}
phpbench:
name: 'Benchmarks ${{ matrix.php }} - WP ${{ matrix.wp }} - OPCache ${{ matrix.opcache }}'
runs-on: ubuntu-latest
services:
mysql:
image: mariadb:latest
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
MARIADB_DATABASE: wordpress_test
MARIADB_MYSQL_LOCALHOST_USER: 1
MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE
ports:
- 3306
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
matrix:
php: ['8.2']
wp: ['latest']
opcache: [true, false]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.opcache == false && ':opcache' || 'opcache' }}
coverage: none
tools: composer
ini-values: opcache.enable_cli=1
- name: Install PHP dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6
with:
composer-options: '--prefer-dist --no-scripts'
- name: Shutdown default MySQL service
run: sudo service mysql stop
- name: Set up tests
run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true
- name: Run benchmarks
run: composer phpbench
e2e-tests:
name: 'E2E Tests (${{ matrix.wp }})'
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental == true }}
strategy:
fail-fast: false
matrix:
wp: ['latest']
experimental: [false]
include:
- wp: 'trunk'
experimental: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Configure WordPress version
run: |
if [[ $WP_VERSION == 'trunk' ]]; then
echo "Using WordPress trunk"
echo "{\"core\":\"WordPress/WordPress#master\"}" >> .wp-env.override.json
fi
env:
WP_VERSION: ${{ matrix.wp }}
- name: Install WordPress
run: |
chmod -R 767 ./ # TODO: Possibly integrate in wp-env
npm run wp-env start
# Ensure the wp-content/languages folder exists and is writable.
# See https://github.com/WordPress/gutenberg/issues/22515
# and https://github.com/WordPress/gutenberg/tree/trunk/packages/env#installing-a-plugin-or-theme-on-the-development-instance
- name: Install languages
run: |
WP_ENV_DIR=$(npm run wp-env install-path --silent 2>&1 | head -1)
cd $WP_ENV_DIR
mkdir -p tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
chmod -R 767 tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language core install de_DE es_ES fr_FR it_IT
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language plugin install de_DE es_ES fr_FR it_IT --all
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language plugin update --all
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language theme update --all
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language theme install de_DE es_ES fr_FR it_IT --all
cd -
- name: Run tests
run: npm run test:e2e
- name: Archive debug artifacts (screenshots, HTML snapshots)
uses: actions/upload-artifact@v3
if: always()
with:
name: failures-artifacts
path: artifacts
if-no-files-found: ignore
core-php:
name: 'WP core tests (${{ matrix.wp }})'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
wp: ['trunk', '6.3']
services:
mysql:
image: mariadb:latest
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
MARIADB_DATABASE: wordpress_test
MARIADB_MYSQL_LOCALHOST_USER: 1
MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE
ports:
- 3306
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: 'wordpress/wordpress-develop'
ref: ${{ matrix.wp }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mysql
coverage: none
tools: composer
- name: Install PHP dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6
with:
composer-options: '--prefer-dist'
dependency-versions: 'highest'
- name: Shutdown default MySQL service
run: sudo service mysql stop
- name: Set up tests config
run: |
cp wp-tests-config-sample.php wp-tests-config.php
sed -i.bak "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
sed -i.bak "s/yourusernamehere/$DB_USER/" wp-tests-config.php
sed -i.bak "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
sed -i.bak "s|localhost|${DB_HOST}|" wp-tests-config.php
cat wp-tests-config.php
env:
DB_NAME: wordpress_test
DB_USER: root
DB_PASSWORD: ''
DB_HOST: 127.0.0.1:${{ job.services.mysql.ports['3306'] }}
- name: Checkout Ginger MO
uses: actions/checkout@v4
with:
path: 'src/wp-content/plugins/performant-translations'
- name: Load Ginger MO for tests
run: |
echo "require dirname( __DIR__, 3 ) . '/src/wp-content/plugins/performant-translations/performant-translations.php';" >> tests/phpunit/includes/bootstrap.php
- name: Run tests (PHP format)
run: vendor/bin/phpunit --group=l10n,i18n,pomo
- name: Run tests (JSON format)
run: |
echo "add_filter( 'performant_translations_preferred_format', static function () { return 'json'; } );" >> tests/phpunit/includes/bootstrap.php
vendor/bin/phpunit --group=l10n,i18n,pomo
- name: Run tests (MO format)
run: |
echo "add_filter( 'performant_translations_preferred_format', static function () { return 'mo'; } );" >> tests/phpunit/includes/bootstrap.php
vendor/bin/phpunit --group=l10n,i18n,pomo
performance-tests:
name: 'Performance Tests (trunk)'
runs-on: ubuntu-latest
env:
WP_ARTIFACTS_PATH: ${{ github.workspace }}/artifacts
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Configure WordPress version
run: |
echo "{\"core\":\"WordPress/WordPress#master\"}" >> .wp-env.override.json
- name: Install WordPress
run: |
chmod -R 767 ./ # TODO: Possibly integrate in wp-env
npm run wp-env start
- name: Update permalink structure
run: |
npm run wp-env run tests-cli wp rewrite structure '/%postname%/' -- --hard
- name: Import mock data
run: |
npm run wp-env run tests-cli curl https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml -- --output /tmp/themeunittestdata.wordpress.xml
npm run wp-env run tests-cli wp import /tmp/themeunittestdata.wordpress.xml -- --authors=create
# Ensure the wp-content/languages folder exists and is writable.
# See https://github.com/WordPress/gutenberg/issues/22515
# and https://github.com/WordPress/gutenberg/tree/trunk/packages/env#installing-a-plugin-or-theme-on-the-development-instance
- name: Install languages
run: |
WP_ENV_DIR=$(npm run wp-env install-path --silent 2>&1 | head -1)
cd $WP_ENV_DIR
mkdir -p tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
chmod -R 767 tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language core install de_DE
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language plugin install de_DE --all
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language theme update --all
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language theme install de_DE --all
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language theme update --all
cd -
- name: Run tests
run: |
npm run test:performance
mv ${{ env.WP_ARTIFACTS_PATH }}/performance-results.json ${{ runner.temp }}/results_after.json
- name: Check out base commit
run: |
if [[ -z "$BASE_REF" ]]; then
git fetch -n origin $BASE_SHA
git reset --hard $BASE_SHA
else
git fetch -n origin $BASE_REF
git reset --hard $BASE_SHA
fi
env:
BASE_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || '' }}
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
# Run tests without causing job to fail if they don't pass (e.g. because of env issues).
- name: Run tests for base
run: |
npm run test:performance || true
if [ -f "{{ env.WP_ARTIFACTS_PATH }}/performance-results.json" ]; then
mv ${{ env.WP_ARTIFACTS_PATH }}/performance-results.json ${{ runner.temp }}/results_before.json
fi;
- name: Reset to original commit
run: |
git reset --hard $GITHUB_SHA
- name: Compare results with base
run: |
if [ -f "${{ runner.temp }}/results_before.json" ]; then
node tests/performance/cli/results.js ${{ runner.temp }}/results_after.json ${{ runner.temp }}/results_before.json
else
node tests/performance/cli/results.js ${{ runner.temp }}/results_after.json
fi;
- name: Check if a comment was already made
id: find-comment
uses: peter-evans/find-comment@a54c31d7fa095754bfef525c0c8e5e5674c4b4b1
if: >
github.event.pull_request.number &&
github.event.pull_request.head.repo.fork == false
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: swissspidy
body-includes: Performance test results for
- name: Comment on PR with test results
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa
if: >
github.event.pull_request.number &&
github.event.pull_request.head.repo.fork == false
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body-path: ${{ env.WP_ARTIFACTS_PATH }}/performance-results.md
token: ${{ secrets.WORKFLOW_TOKEN }}
- name: Add workflow summary
run: |
cat ${{ env.WP_ARTIFACTS_PATH }}/performance-results.md >> $GITHUB_STEP_SUMMARY
- name: Archive performance results
if: success()
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # v3.1.1
with:
name: performance-results
path: ${{ env.WP_ARTIFACTS_PATH }}/performance-results.json
- name: Archive debug artifacts (screenshots, HTML snapshots)
uses: actions/upload-artifact@v3
if: failure()
with:
name: failures-artifacts
path: artifacts
if-no-files-found: ignore