Skip to content

Commit 362a95d

Browse files
authored
Merge pull request #157 from wp-cli/try/test-suite
2 parents ba514d3 + acb503c commit 362a95d

1 file changed

Lines changed: 45 additions & 47 deletions

File tree

.github/workflows/reusable-testing.yml

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ on:
1818
type: boolean
1919
required: false
2020
default: true
21+
matrix:
22+
description: 'Additional matrix entries to include or exclude.'
23+
type: string
24+
required: false
25+
default: '{ "include": [], "exclude": [] }'
2126

2227
# Cancels all previous workflow runs for the same branch that have not yet completed.
2328
concurrency:
@@ -34,6 +39,8 @@ jobs:
3439
steps:
3540
- name: Set matrix
3641
id: base-matrix
42+
env:
43+
ADDITIONAL_MATRIX: ${{ inputs.matrix }}
3744
run: |
3845
MATRIX=$(cat << EOF
3946
{
@@ -205,7 +212,8 @@ jobs:
205212
}
206213
EOF
207214
)
208-
echo matrix=$MATRIX >> $GITHUB_OUTPUT
215+
MERGED_MATRIX=$(echo "$MATRIX" "$ADDITIONAL_MATRIX" | jq -s '{include: (.[0].include + .[1].include | unique), exclude: (.[0].exclude + .[1].exclude | unique)}')
216+
echo matrix=$MERGED_MATRIX >> $GITHUB_OUTPUT
209217
210218
prepare-unit:
211219
name: Prepare matrix for unit tests
@@ -249,7 +257,7 @@ jobs:
249257
) |
250258
251259
# Finally, get the unique entries
252-
unique_by(.php)
260+
unique_by([.php, .os])
253261
)
254262
' <<< "$BASE_MATRIX")" >> $GITHUB_OUTPUT
255263
else
@@ -262,11 +270,11 @@ jobs:
262270
unit: #-----------------------------------------------------------------------
263271
needs: prepare-unit
264272
if: ${{ needs.prepare-unit.outputs.matrix != '' }}
265-
name: Unit test / PHP ${{ matrix.php }}${{ matrix.coverage && ' (with coverage)' || '' }}
273+
name: Unit test / PHP ${{ matrix.php }}${{ matrix.coverage && ' (with coverage)' || '' }} ${{ startsWith( matrix.os, 'windows' ) && '(Windows)' || '' }} ${{ startsWith( matrix.os, 'macos' ) && '(macOS)' || '' }}
266274
strategy:
267275
fail-fast: false
268276
matrix: ${{ fromJson(needs.prepare-unit.outputs.matrix) }}
269-
runs-on: ubuntu-22.04
277+
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
270278

271279
continue-on-error: ${{ matrix.php == 'nightly' }}
272280

@@ -292,27 +300,28 @@ jobs:
292300
# Bust the cache at least once a month - output format: YYYY-MM.
293301
custom-cache-suffix: $(date -u "+%Y-%m")
294302

295-
- name: Grab PHPUnit version
296-
id: phpunit_version
297-
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
298-
299303
# PHPUnit 10+ may fail a test run when the "old" configuration format is used.
300304
# Luckily, there is a build-in migration tool since PHPUnit 9.3.
301305
- name: Migrate PHPUnit configuration for PHPUnit 10+
302-
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '1' ) }}
306+
if: ${{ matrix.php >= 8.2 || matrix.php == 'nightly' }}
303307
continue-on-error: true
304308
run: composer phpunit -- --migrate-configuration
305309

306310
- name: Setup problem matcher to provide annotations for PHPUnit
307311
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
308312

313+
- name: Run PHPUnit with coverage
314+
if: ${{ matrix.coverage }}
315+
run: |
316+
composer phpunit -- --coverage-clover build/logs/unit-coverage.xml
317+
309318
- name: Run PHPUnit
319+
if: ${{ ! matrix.coverage }}
320+
# For example TestBehatTags.php in wp-cli-tests depends on the db type.
321+
env:
322+
WP_CLI_TEST_DBTYPE: 'sqlite'
310323
run: |
311-
if [[ ${{ matrix.coverage == true }} == true ]]; then
312-
composer phpunit -- --coverage-clover build/logs/unit-coverage.xml
313-
else
314-
composer phpunit
315-
fi
324+
composer phpunit
316325
317326
- name: Upload code coverage report
318327
if: ${{ matrix.coverage }}
@@ -381,19 +390,30 @@ jobs:
381390
functional: #-----------------------------------------------------------------
382391
needs: prepare-functional
383392
if: ${{ needs.prepare-functional.outputs.matrix != '' }}
384-
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with ${{ matrix.dbtype != 'sqlite' && matrix.mysql || 'SQLite' }}${{ matrix.coverage && ' (with coverage)' || '' }}
393+
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with ${{ matrix.dbtype != 'sqlite' && matrix.mysql || 'SQLite' }}${{ matrix.coverage && ' (with coverage)' || '' }} ${{ startsWith( matrix.os, 'windows' ) && '(Windows)' || '' }} ${{ startsWith( matrix.os, 'macos' ) && '(macOS)' || '' }}
385394
strategy:
386395
fail-fast: false
387396
matrix: ${{ fromJson(needs.prepare-functional.outputs.matrix) }}
388-
runs-on: ubuntu-22.04
397+
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
389398

390399
continue-on-error: ${{ matrix.dbtype == 'sqlite' || matrix.dbtype == 'mariadb' || matrix.php == 'nightly' }}
391400

401+
env:
402+
MYSQL_HOST: 127.0.0.1
403+
MYSQL_TCP_PORT: 3306
404+
WP_CLI_TEST_DBROOTUSER: root
405+
WP_CLI_TEST_DBROOTPASS: root
406+
WP_CLI_TEST_DBNAME: wp_cli_test
407+
WP_CLI_TEST_DBUSER: wp_cli_test
408+
WP_CLI_TEST_DBPASS: password1
409+
WP_CLI_TEST_DBHOST: 127.0.0.1:3306
410+
392411
steps:
393412
- name: Check out source code
394413
uses: actions/checkout@v5
395414

396415
- name: Install Ghostscript
416+
if: ${{ matrix.os == 'ubuntu-22.04' || matrix.os == '' }}
397417
run: |
398418
sudo apt-get update
399419
sudo apt-get install ghostscript -y
@@ -403,13 +423,14 @@ jobs:
403423
with:
404424
php-version: '${{ matrix.php }}'
405425
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
406-
extensions: gd, imagick, mysql, zip
426+
extensions: gd, imagick, mysql, zip, pdo_sqlite
407427
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
408428
tools: composer
409429
env:
410430
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
411431

412432
- name: Change ImageMagick policy to allow pdf->png conversion.
433+
if: ${{ matrix.os == 'ubuntu-22.04' || matrix.os == '' }}
413434
run: |
414435
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
415436
@@ -428,24 +449,12 @@ jobs:
428449
with:
429450
mysql-version: ${{ matrix.mysql }}
430451
auto-start: true
431-
root-password: root
432-
user: wp_cli_test
433-
password: password1
452+
root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }}
453+
user: ${{ env.WP_CLI_TEST_DBUSER}}
454+
password: ${{ env.WP_CLI_TEST_DBPASS}}
434455
my-cnf: |
435456
default_authentication_plugin=mysql_native_password
436457
437-
- name: Configure DB environment
438-
if: ${{ matrix.dbtype != 'sqlite' }}
439-
run: |
440-
echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
441-
echo "MYSQL_TCP_PORT=3306" >> $GITHUB_ENV
442-
echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV
443-
echo "WP_CLI_TEST_DBROOTPASS=root" >> $GITHUB_ENV
444-
echo "WP_CLI_TEST_DBNAME=wp_cli_test" >> $GITHUB_ENV
445-
echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV
446-
echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV
447-
echo "WP_CLI_TEST_DBHOST=127.0.0.1:3306" >> $GITHUB_ENV
448-
449458
- name: Prepare test database
450459
if: ${{ matrix.dbtype != 'sqlite' }}
451460
run: composer prepare-tests
@@ -455,29 +464,18 @@ jobs:
455464
WP_VERSION: '${{ matrix.wp }}'
456465
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
457466
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
458-
run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat
467+
WP_CLI_TEST_DEBUG_BEHAT_ENV: 1
468+
run: composer behat
459469

460470
- name: Run Behat
461471
env:
462472
WP_VERSION: '${{ matrix.wp }}'
463473
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
464474
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
465475
WP_CLI_TEST_COVERAGE: ${{ matrix.coverage }}
476+
BEHAT_ARGS: ${{ format( '{0} {1}', matrix.coverage && '--xdebug', runner.debug && '--format-pretty' ) }}
466477
run: |
467-
ARGS=()
468-
469-
if [[ $WP_CLI_TEST_COVERAGE == 'true' ]]; then
470-
# The flag was only added in v3.17.0
471-
if composer behat -- --help 2>/dev/null | grep xdebug; then
472-
ARGS+=("--xdebug")
473-
fi
474-
fi
475-
476-
if [[ $RUNNER_DEBUG == '1' ]]; then
477-
ARGS+=("--format=pretty")
478-
fi
479-
480-
composer behat -- "${ARGS[@]}" || composer behat-rerun -- "${ARGS[@]}"
478+
composer behat -- $BEHAT_ARGS || composer behat-rerun -- $BEHAT_ARGS
481479
482480
- name: Retrieve list of coverage files
483481
id: coverage_files

0 commit comments

Comments
 (0)