-
Notifications
You must be signed in to change notification settings - Fork 6
440 lines (404 loc) · 13.9 KB
/
reusable-testing.yml
File metadata and controls
440 lines (404 loc) · 13.9 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
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
name: Testing
on:
workflow_call:
inputs:
minimum-php:
description: 'Minimum PHP version to test against.'
type: string
required: false
default: '7.2'
minimum-wp:
description: 'Minimum WP version to test against.'
type: string
required: false
default: '4.9'
# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
get-matrix:
name: Get base test matrix
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.base-matrix.outputs.matrix }}
steps:
- name: Set matrix
id: base-matrix
run: |
MATRIX=$(cat << EOF
{
"include": [
{
"php": "7.2",
"wp": "4.9",
"mysql": "mysql-5.6"
},
{
"php": "7.2",
"wp": "latest",
"mysql": "mysql-8.0"
},
{
"php": "7.2",
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "7.3",
"wp": "latest",
"mysql": "mysql-8.0"
},
{
"php": "7.3",
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "7.4",
"wp": "latest",
"mysql": "mysql-8.0"
},
{
"php": "7.4",
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "8.0",
"wp": "latest",
"mysql": "mysql-8.0"
},
{
"php": "8.0",
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "8.1",
"wp": "latest",
"mysql": "mysql-8.0"
},
{
"php": "8.1",
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "8.2",
"wp": "latest",
"mysql": "mysql-8.0"
},
{
"php": "8.2",
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "8.3",
"wp": "latest",
"mysql": "mysql-8.0",
"coverage": true
},
{
"php": "8.3",
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "8.3",
"wp": "latest",
"mysql": "mariadb-11.4",
"dbtype": "mariadb"
},
{
"php": "7.2",
"wp": "trunk",
"mysql": "mysql-8.0"
},
{
"php": "7.2",
"wp": "trunk",
"mysql": "mysql-5.7"
},
{
"php": "7.2",
"wp": "trunk",
"mysql": "mysql-5.6"
},
{
"php": "7.4",
"wp": "trunk",
"mysql": "mysql-8.0"
},
{
"php": "8.0",
"wp": "trunk",
"mysql": "mysql-8.0"
},
{
"php": "8.0",
"wp": "trunk",
"mysql": "mysql-5.7"
},
{
"php": "8.0",
"wp": "trunk",
"mysql": "mysql-5.6"
},
{
"php": "8.1",
"wp": "trunk",
"mysql": "mysql-8.0"
},
{
"php": "8.2",
"wp": "trunk",
"mysql": "mysql-8.0"
},
{
"php": "8.3",
"wp": "trunk",
"mysql": "mysql-8.0"
},
{
"php": "8.3",
"wp": "trunk",
"dbtype": "sqlite"
},
{
"php": "8.3",
"wp": "trunk",
"mysql": "mariadb-11.4",
"dbtype": "mariadb"
},
{
"php": "8.4",
"wp": "trunk",
"mysql": "mysql-8.0"
},
{
"php": "8.4",
"wp": "trunk",
"dbtype": "sqlite"
},
{
"php": "nightly",
"wp": "trunk",
"mysql": "mysql-8.0"
},
{
"php": "nightly",
"wp": "trunk",
"dbtype": "sqlite"
}
]
}
EOF
)
echo matrix=$MATRIX >> $GITHUB_OUTPUT
prepare-unit:
name: Prepare matrix for unit tests
needs: get-matrix
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Check existence of composer.json & phpunit.xml.dist files
id: check_files
uses: andstor/file-existence-action@v3
with:
files: "composer.json, phpunit.xml.dist"
- name: Set matrix
id: set-matrix
run: |
if [[ $FILE_EXISTS == 'true' ]]; then
echo "matrix=$(jq -c '.include |= map(with_entries(select(.key == "php", .key == "coverage"))) | .include |= map(select(.php >= "${{ inputs.minimum-php }}")) | .include |= unique_by(.php)' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
else
echo "matrix=" >> $GITHUB_OUTPUT
fi
env:
BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }}
FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }}
unit: #-----------------------------------------------------------------------
needs: prepare-unit
if: ${{ needs.prepare-unit.outputs.matrix != '' }}
name: Unit test / PHP ${{ matrix.php }}${{ matrix.coverage && ' (with coverage)' || '' }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-unit.outputs.matrix) }}
runs-on: ubuntu-22.04
continue-on-error: ${{ matrix.php == 'nightly' }}
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Set up PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
tools: composer,cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install Composer dependencies & cache dependencies
uses: "ramsey/composer-install@v3"
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: Grab PHPUnit version
id: phpunit_version
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
# PHPUnit 10 may fail a test run when the "old" configuration format is used.
# Luckily, there is a build-in migration tool since PHPUnit 9.3.
- name: Migrate PHPUnit configuration for PHPUnit 10+
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
continue-on-error: true
run: composer phpunit -- --migrate-configuration
- name: Setup problem matcher to provide annotations for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Run PHPUnit
run: |
if [[ ${{ matrix.coverage == true }} == true ]]; then
composer phpunit -- --coverage-clover build/logs/unit-coverage.xml
else
composer phpunit
fi
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@v5.4.3
with:
directory: build/logs
flags: unit
token: ${{ secrets.CODECOV_TOKEN }}
prepare-functional: #---------------------------------------------------------
name: Prepare matrix for functional tests
needs: get-matrix
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Check existence of composer.json & behat.yml files
id: check_files
uses: andstor/file-existence-action@v3
with:
files: "composer.json, behat.yml"
- name: Set matrix
id: set-matrix
run: |
if [[ $FILE_EXISTS == 'true' ]]; then
echo "matrix=$(jq -c '.include |= map(select(.wp == "4.9").wp |= "${{ inputs.minimum-wp }}") | .include |= map(select(.php >= "${{ inputs.minimum-php }}"))' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
else
echo "matrix=" >> $GITHUB_OUTPUT
fi
env:
BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }}
FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }}
functional: #-----------------------------------------------------------------
needs: prepare-functional
if: ${{ needs.prepare-functional.outputs.matrix != '' }}
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with ${{ matrix.dbtype != 'sqlite' && matrix.mysql || 'SQLite' }}${{ matrix.coverage && ' (with coverage)' || '' }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-functional.outputs.matrix) }}
runs-on: ubuntu-22.04
continue-on-error: ${{ matrix.dbtype == 'sqlite' || matrix.dbtype == 'mariadb' || matrix.php == 'nightly' }}
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Install Ghostscript
run: |
sudo apt-get update
sudo apt-get install ghostscript -y
- name: Set up PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
# Disable error reporting for Behat tests on PHP 8.4+, as long as Behat is not upgraded to a newer version.
ini-values: ${{ matrix.php != '8.4' && matrix.php != 'nightly' && 'zend.assertions=1, error_reporting=-1, display_errors=On' || '' }}
extensions: gd, imagick, mysql, zip
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
tools: composer
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Change ImageMagick policy to allow pdf->png conversion.
run: |
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
- name: Install Composer dependencies & cache dependencies
uses: "ramsey/composer-install@v3"
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: Setup MySQL Server
id: setup-mysql
if: ${{ matrix.dbtype != 'sqlite' }}
uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: ${{ matrix.mysql }}
auto-start: true
root-password: root
user: wp_cli_test
password: password1
my-cnf: |
default_authentication_plugin=mysql_native_password
- name: Configure DB environment
if: ${{ matrix.dbtype != 'sqlite' }}
run: |
echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
echo "MYSQL_TCP_PORT=3306" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBROOTPASS=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBNAME=wp_cli_test" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBHOST=127.0.0.1:3306" >> $GITHUB_ENV
- name: Prepare test database
if: ${{ matrix.dbtype != 'sqlite' }}
run: composer prepare-tests
- name: Check Behat environment
env:
WP_VERSION: '${{ matrix.wp }}'
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat
- name: Run Behat
env:
WP_VERSION: '${{ matrix.wp }}'
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
WP_CLI_TEST_COVERAGE: ${{ matrix.coverage }}
run: |
ARGS=()
if [[ $WP_CLI_TEST_COVERAGE == 'true' ]]; then
# The flag was only added in v3.17.0
if composer behat -- --help 2>/dev/null | grep xdebug; then
ARGS+=("--xdebug")
fi
fi
if [[ $RUNNER_DEBUG == '1' ]]; then
ARGS+=("--format=pretty")
fi
composer behat -- "${ARGS[@]}" || composer behat-rerun -- "${ARGS[@]}"
- name: Retrieve list of coverage files
id: coverage_files
if: ${{ matrix.coverage }}
run: |
FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -)
echo "files=$FILES" >> $GITHUB_OUTPUT
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@v5.4.3
with:
# Because somehow providing `directory: build/logs` doesn't work for these files
files: ${{ steps.coverage_files.outputs.files }}
flags: feature
token: ${{ secrets.CODECOV_TOKEN }}