Skip to content

Commit 6839d4b

Browse files
committed
Split functional & unit tests into reusable workflows
1 parent 8af7842 commit 6839d4b

File tree

3 files changed

+237
-171
lines changed

3 files changed

+237
-171
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
name: Functional testing
2+
on:
3+
workflow_call:
4+
inputs:
5+
php:
6+
type: string
7+
required: true
8+
wp:
9+
type: string
10+
required: true
11+
dbtype:
12+
type: string
13+
required: true
14+
mysql:
15+
type: string
16+
required: true
17+
object_cache:
18+
type: string
19+
required: false
20+
default: 'none'
21+
coverage:
22+
type: boolean
23+
required: false
24+
default: false
25+
os:
26+
type: string
27+
required: false
28+
default: 'ubuntu-22.04'
29+
30+
jobs:
31+
functional:
32+
name: PHP ${{ inputs.php }} | WP ${{ inputs.wp }} | ${{ inputs.dbtype == 'sqlite' && 'SQLite' || inputs.dbtype == 'mysql' && 'MySQL' || 'MariaDB' }}${{ inputs.object_cache == 'sqlite' && ' (Obj Cache)' || '' }}${{ inputs.coverage && ' (with coverage)' || '' }}${{ startsWith( inputs.os, 'windows' ) && ' (Windows)' || '' }}${{ startsWith( inputs.os, 'macos' ) && ' (macOS)' || '' }}
33+
runs-on: ${{ inputs.os || 'ubuntu-22.04' }}
34+
35+
continue-on-error: ${{ inputs.dbtype == 'sqlite' || inputs.dbtype == 'mariadb' || inputs.php == 'nightly' }}
36+
37+
env:
38+
MYSQL_HOST: 127.0.0.1
39+
MYSQL_TCP_PORT: 3306
40+
WP_CLI_TEST_DBROOTUSER: root
41+
WP_CLI_TEST_DBROOTPASS: root
42+
WP_CLI_TEST_DBNAME: wp_cli_test
43+
WP_CLI_TEST_DBUSER: wp_cli_test
44+
WP_CLI_TEST_DBPASS: password1
45+
WP_CLI_TEST_DBHOST: 127.0.0.1:3306
46+
WP_CLI_TEST_OBJECT_CACHE: ${{ inputs.object_cache }}
47+
48+
steps:
49+
- name: Check out source code
50+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
51+
52+
- name: Install Ghostscript
53+
if: ${{ inputs.os == 'ubuntu-22.04' || inputs.os == '' }}
54+
run: |
55+
sudo apt-get update
56+
sudo apt-get install ghostscript -y
57+
58+
- name: Set up PHP environment
59+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
60+
with:
61+
php-version: '${{ inputs.php }}'
62+
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
63+
extensions: gd, imagick, mysql, zip, pdo_sqlite
64+
coverage: ${{ inputs.coverage && 'xdebug' || 'none' }}
65+
tools: composer
66+
env:
67+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
69+
- name: Change ImageMagick policy to allow pdf->png conversion.
70+
if: ${{ inputs.os == 'ubuntu-22.04' || inputs.os == '' }}
71+
run: |
72+
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
73+
74+
- name: Install Composer dependencies & cache dependencies
75+
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v3
76+
env:
77+
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
78+
with:
79+
# Bust the cache at least once a month - output format: YYYY-MM.
80+
custom-cache-suffix: $(date -u "+%Y-%m")
81+
82+
# MySQL 8.4 requires explicit loading of mysql_native_password plugin
83+
- name: Determine MySQL authentication configuration
84+
id: mysql-config
85+
if: ${{ inputs.dbtype != 'sqlite' && inputs.mysql == 'mysql-8.4' }}
86+
run: |
87+
echo "auth-config<<EOF" >> $GITHUB_OUTPUT
88+
echo "mysql_native_password=ON" >> $GITHUB_OUTPUT
89+
echo "authentication_policy=mysql_native_password," >> $GITHUB_OUTPUT
90+
echo "EOF" >> $GITHUB_OUTPUT
91+
92+
- name: Setup MySQL Server
93+
id: setup-mysql
94+
if: ${{ inputs.dbtype != 'sqlite' }}
95+
uses: shogo82148/actions-setup-mysql@840178c12b07a58353c6312be784c23b63756eea # v1
96+
with:
97+
mysql-version: ${{ inputs.mysql }}
98+
auto-start: true
99+
root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }}
100+
user: ${{ env.WP_CLI_TEST_DBUSER}}
101+
password: ${{ env.WP_CLI_TEST_DBPASS}}
102+
# Fall back to legacy configuration for MySQL 5.6, 5.7, 8.0 and MariaDB.
103+
my-cnf: |
104+
${{ steps.mysql-config.outputs.auth-config || 'default_authentication_plugin=mysql_native_password' }}
105+
${{ inputs.dbtype == 'mariadb' && '[client]' || '' }}
106+
${{ inputs.dbtype == 'mariadb' && 'disable-ssl-verify-server-cert' || '' }}
107+
108+
- name: Prepare test database
109+
if: ${{ inputs.dbtype != 'sqlite' }}
110+
run: composer prepare-tests
111+
112+
- name: Check Behat environment
113+
env:
114+
WP_VERSION: '${{ inputs.wp }}'
115+
WP_CLI_TEST_DBTYPE: ${{ inputs.dbtype || 'mysql' }}
116+
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
117+
WP_CLI_TEST_DEBUG_BEHAT_ENV: 1
118+
run: composer behat
119+
120+
- name: Run Behat
121+
env:
122+
WP_VERSION: '${{ inputs.wp }}'
123+
WP_CLI_TEST_DBTYPE: ${{ inputs.dbtype || 'mysql' }}
124+
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
125+
WP_CLI_TEST_COVERAGE: ${{ inputs.coverage }}
126+
BEHAT_ARGS: ${{ format( '{0}', runner.debug && '--format=pretty' ) }}
127+
run: |
128+
composer behat -- $BEHAT_ARGS || composer behat-rerun -- $BEHAT_ARGS
129+
130+
- name: Retrieve list of coverage files
131+
id: coverage_files
132+
if: ${{ inputs.coverage }}
133+
run: |
134+
FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -)
135+
echo "files=$FILES" >> $GITHUB_OUTPUT
136+
137+
- name: Upload code coverage report
138+
if: ${{ inputs.coverage }}
139+
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5.5.3
140+
with:
141+
# Because somehow providing `directory: build/logs` doesn't work for these files
142+
files: ${{ steps.coverage_files.outputs.files }}
143+
flags: feature
144+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/reusable-testing.yml

Lines changed: 18 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -367,67 +367,16 @@ jobs:
367367
unit:
368368
needs: prepare-unit
369369
if: ${{ needs.prepare-unit.outputs.matrix != '' }}
370-
name: Unit test - PHP ${{ matrix.php }}${{ matrix.coverage && ' (with coverage)' || '' }} ${{ startsWith( matrix.os, 'windows' ) && '(Windows)' || '' }} ${{ startsWith( matrix.os, 'macos' ) && '(macOS)' || '' }}
370+
name: Unit
371371
strategy:
372372
fail-fast: false
373373
matrix: ${{ fromJson(needs.prepare-unit.outputs.matrix) }}
374-
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
375-
376-
continue-on-error: ${{ matrix.php == 'nightly' }}
377-
378-
steps:
379-
- name: Check out source code
380-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
381-
382-
- name: Set up PHP environment
383-
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
384-
with:
385-
php-version: '${{ matrix.php }}'
386-
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
387-
extensions: zip
388-
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
389-
tools: composer,cs2pr
390-
env:
391-
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
392-
393-
- name: Install Composer dependencies & cache dependencies
394-
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v3
395-
env:
396-
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
397-
with:
398-
# Bust the cache at least once a month - output format: YYYY-MM.
399-
custom-cache-suffix: $(date -u "+%Y-%m")
400-
401-
# PHPUnit 10+ may fail a test run when the "old" configuration format is used.
402-
# Luckily, there is a build-in migration tool since PHPUnit 9.3.
403-
- name: Migrate PHPUnit configuration for PHPUnit 10+
404-
if: ${{ matrix.php >= 8.2 || matrix.php == 'nightly' }}
405-
continue-on-error: true
406-
run: composer phpunit -- --migrate-configuration
407-
408-
- name: Setup problem matcher to provide annotations for PHPUnit
409-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
410-
411-
- name: Run PHPUnit with coverage
412-
if: ${{ matrix.coverage }}
413-
run: |
414-
composer phpunit -- --coverage-clover build/logs/unit-coverage.xml
415-
416-
- name: Run PHPUnit
417-
if: ${{ ! matrix.coverage }}
418-
# For example TestBehatTags.php in wp-cli-tests depends on the db type.
419-
env:
420-
WP_CLI_TEST_DBTYPE: 'sqlite'
421-
run: |
422-
composer phpunit
423-
424-
- name: Upload code coverage report
425-
if: ${{ matrix.coverage }}
426-
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5.5.3
427-
with:
428-
directory: build/logs
429-
flags: unit
430-
token: ${{ secrets.CODECOV_TOKEN }}
374+
uses: ./.github/workflows/reusable-unit.yml
375+
secrets: inherit
376+
with:
377+
php: ${{ matrix.php }}
378+
coverage: ${{ matrix.coverage }}
379+
os: ${{ matrix.os }}
431380

432381
prepare-functional:
433382
name: Prepare matrix for functional tests
@@ -486,119 +435,17 @@ jobs:
486435
functional:
487436
needs: prepare-functional
488437
if: ${{ needs.prepare-functional.outputs.matrix != '' }}
489-
name: PHP ${{ matrix.php }} - WP ${{ matrix.wp }} on ${{ matrix.dbtype != 'sqlite' && matrix.mysql || 'SQLite' }}${{ matrix.object_cache == 'sqlite' && ' (SQLite Object Cache)' || '' }}${{ matrix.coverage && ' (with coverage)' || '' }} ${{ startsWith( matrix.os, 'windows' ) && '(Windows)' || '' }} ${{ startsWith( matrix.os, 'macos' ) && '(macOS)' || '' }}
438+
name: Functional
490439
strategy:
491440
fail-fast: false
492441
matrix: ${{ fromJson(needs.prepare-functional.outputs.matrix) }}
493-
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
494-
495-
continue-on-error: ${{ matrix.dbtype == 'sqlite' || matrix.dbtype == 'mariadb' || matrix.php == 'nightly' }}
496-
497-
env:
498-
MYSQL_HOST: 127.0.0.1
499-
MYSQL_TCP_PORT: 3306
500-
WP_CLI_TEST_DBROOTUSER: root
501-
WP_CLI_TEST_DBROOTPASS: root
502-
WP_CLI_TEST_DBNAME: wp_cli_test
503-
WP_CLI_TEST_DBUSER: wp_cli_test
504-
WP_CLI_TEST_DBPASS: password1
505-
WP_CLI_TEST_DBHOST: 127.0.0.1:3306
506-
WP_CLI_TEST_OBJECT_CACHE: ${{ matrix.object_cache }}
507-
508-
steps:
509-
- name: Check out source code
510-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
511-
512-
- name: Install Ghostscript
513-
if: ${{ matrix.os == 'ubuntu-22.04' || matrix.os == '' }}
514-
run: |
515-
sudo apt-get update
516-
sudo apt-get install ghostscript -y
517-
518-
- name: Set up PHP environment
519-
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
520-
with:
521-
php-version: '${{ matrix.php }}'
522-
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
523-
extensions: gd, imagick, mysql, zip, pdo_sqlite
524-
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
525-
tools: composer
526-
env:
527-
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
528-
529-
- name: Change ImageMagick policy to allow pdf->png conversion.
530-
if: ${{ matrix.os == 'ubuntu-22.04' || matrix.os == '' }}
531-
run: |
532-
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
533-
534-
- name: Install Composer dependencies & cache dependencies
535-
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v3
536-
env:
537-
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
538-
with:
539-
# Bust the cache at least once a month - output format: YYYY-MM.
540-
custom-cache-suffix: $(date -u "+%Y-%m")
541-
542-
# MySQL 8.4 requires explicit loading of mysql_native_password plugin
543-
- name: Determine MySQL authentication configuration
544-
id: mysql-config
545-
if: ${{ matrix.dbtype != 'sqlite' && matrix.mysql == 'mysql-8.4' }}
546-
run: |
547-
echo "auth-config<<EOF" >> $GITHUB_OUTPUT
548-
echo "mysql_native_password=ON" >> $GITHUB_OUTPUT
549-
echo "authentication_policy=mysql_native_password," >> $GITHUB_OUTPUT
550-
echo "EOF" >> $GITHUB_OUTPUT
551-
552-
- name: Setup MySQL Server
553-
id: setup-mysql
554-
if: ${{ matrix.dbtype != 'sqlite' }}
555-
uses: shogo82148/actions-setup-mysql@840178c12b07a58353c6312be784c23b63756eea # v1
556-
with:
557-
mysql-version: ${{ matrix.mysql }}
558-
auto-start: true
559-
root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }}
560-
user: ${{ env.WP_CLI_TEST_DBUSER}}
561-
password: ${{ env.WP_CLI_TEST_DBPASS}}
562-
# Fall back to legacy configuration for MySQL 5.6, 5.7, 8.0 and MariaDB.
563-
my-cnf: |
564-
${{ steps.mysql-config.outputs.auth-config || 'default_authentication_plugin=mysql_native_password' }}
565-
${{ matrix.dbtype == 'mariadb' && '[client]' || '' }}
566-
${{ matrix.dbtype == 'mariadb' && 'disable-ssl-verify-server-cert' || '' }}
567-
568-
- name: Prepare test database
569-
if: ${{ matrix.dbtype != 'sqlite' }}
570-
run: composer prepare-tests
571-
572-
- name: Check Behat environment
573-
env:
574-
WP_VERSION: '${{ matrix.wp }}'
575-
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
576-
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
577-
WP_CLI_TEST_DEBUG_BEHAT_ENV: 1
578-
run: composer behat
579-
580-
- name: Run Behat
581-
env:
582-
WP_VERSION: '${{ matrix.wp }}'
583-
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
584-
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
585-
WP_CLI_TEST_COVERAGE: ${{ matrix.coverage }}
586-
BEHAT_ARGS: ${{ format( '{0}', runner.debug && '--format=pretty' ) }}
587-
run: |
588-
composer behat -- $BEHAT_ARGS || composer behat-rerun -- $BEHAT_ARGS
589-
590-
- name: Retrieve list of coverage files
591-
id: coverage_files
592-
if: ${{ matrix.coverage }}
593-
run: |
594-
FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -)
595-
echo "files=$FILES" >> $GITHUB_OUTPUT
596-
597-
- name: Upload code coverage report
598-
if: ${{ matrix.coverage }}
599-
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5.5.3
600-
with:
601-
# Because somehow providing `directory: build/logs` doesn't work for these files
602-
files: ${{ steps.coverage_files.outputs.files }}
603-
flags: feature
604-
token: ${{ secrets.CODECOV_TOKEN }}
442+
uses: ./.github/workflows/reusable-functional.yml
443+
secrets: inherit
444+
with:
445+
php: ${{ matrix.php }}
446+
wp: ${{ matrix.wp }}
447+
dbtype: ${{ matrix.dbtype }}
448+
mysql: ${{ matrix.mysql }}
449+
object_cache: ${{ matrix.object_cache }}
450+
coverage: ${{ matrix.coverage }}
451+
os: ${{ matrix.os }}

0 commit comments

Comments
 (0)