Skip to content

Commit b67ad2b

Browse files
committed
try running on other operating systems
1 parent 29f6e93 commit b67ad2b

File tree

1 file changed

+345
-2
lines changed

1 file changed

+345
-2
lines changed

.github/workflows/testing.yml

Lines changed: 345 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,349 @@ on:
1010
schedule:
1111
- cron: '17 1 * * *' # Run every day on a seemly random time.
1212

13+
# Cancels all previous workflow runs for the same branch that have not yet completed.
14+
concurrency:
15+
# The concurrency group contains the workflow name and the branch name.
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
1319
jobs:
14-
test:
15-
uses: wp-cli/.github/.github/workflows/reusable-testing.yml@main
20+
get-matrix:
21+
name: Get base test matrix
22+
runs-on: ubuntu-22.04
23+
outputs:
24+
matrix: ${{ steps.base-matrix.outputs.matrix }}
25+
steps:
26+
- name: Set matrix
27+
id: base-matrix
28+
run: |
29+
MATRIX=$(cat << EOF
30+
{
31+
"include": [
32+
{
33+
"php": "8.4",
34+
"wp": "latest",
35+
"mysql": "mysql-8.0"
36+
},
37+
{
38+
"php": "8.4",
39+
"wp": "latest",
40+
"dbtype": "sqlite"
41+
},
42+
{
43+
"php": "8.4",
44+
"wp": "latest",
45+
"mysql": "mysql-8.0",
46+
"os": "macos-15"
47+
},
48+
{
49+
"php": "8.4",
50+
"wp": "latest",
51+
"dbtype": "sqlite",
52+
"os": "macos-15"
53+
},
54+
{
55+
"php": "8.4",
56+
"wp": "latest",
57+
"mysql": "mysql-8.0",
58+
"os": "windows-2025"
59+
},
60+
{
61+
"php": "8.4",
62+
"wp": "latest",
63+
"dbtype": "sqlite",
64+
"os": "windows-2025"
65+
},
66+
]
67+
}
68+
EOF
69+
)
70+
echo matrix=$MATRIX >> $GITHUB_OUTPUT
71+
72+
prepare-unit:
73+
name: Prepare matrix for unit tests
74+
needs: get-matrix
75+
runs-on: ubuntu-22.04
76+
outputs:
77+
matrix: ${{ steps.set-matrix.outputs.matrix }}
78+
steps:
79+
- name: Check out source code
80+
uses: actions/checkout@v5
81+
82+
- name: Check existence of composer.json & phpunit.xml.dist files
83+
id: check_files
84+
uses: andstor/file-existence-action@v3
85+
with:
86+
files: "composer.json, phpunit.xml.dist"
87+
88+
- name: Set matrix
89+
id: set-matrix
90+
run: |
91+
if [[ $FILE_EXISTS == 'true' ]]; then
92+
echo "matrix=$(jq -c \
93+
--argjson with_coverage_flag "${{ inputs.with-coverage }}" \
94+
--arg minimum_php "${{ inputs.minimum-php }}" \
95+
--arg minimum_wp "${{ inputs.minimum-wp }}" \
96+
'
97+
.include |= (
98+
map(
99+
# First, select only the versions that meet all minimum requirements
100+
select(
101+
(.php >= $minimum_php) and
102+
(.wp == "latest" or .wp >= $minimum_wp)
103+
) |
104+
105+
# Next, update the coverage flag on the remaining items
106+
if $with_coverage_flag == false and .coverage == true then
107+
.coverage = false
108+
else
109+
.
110+
end
111+
) |
112+
113+
# Finally, get the unique entries
114+
unique_by(.php)
115+
)
116+
' <<< "$BASE_MATRIX")" >> $GITHUB_OUTPUT
117+
else
118+
echo "matrix=" >> $GITHUB_OUTPUT
119+
fi
120+
env:
121+
BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }}
122+
FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }}
123+
124+
unit: #-----------------------------------------------------------------------
125+
needs: prepare-unit
126+
if: ${{ needs.prepare-unit.outputs.matrix != '' }}
127+
name: Unit test / PHP ${{ matrix.php }}${{ matrix.coverage && ' (with coverage)' || '' }}
128+
strategy:
129+
fail-fast: false
130+
matrix: ${{ fromJson(needs.prepare-unit.outputs.matrix) }}
131+
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
132+
133+
continue-on-error: ${{ matrix.php == 'nightly' }}
134+
135+
steps:
136+
- name: Check out source code
137+
uses: actions/checkout@v5
138+
139+
- name: Set up PHP environment
140+
uses: shivammathur/setup-php@v2
141+
with:
142+
php-version: '${{ matrix.php }}'
143+
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
144+
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
145+
tools: composer,cs2pr
146+
env:
147+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148+
149+
- name: Install Composer dependencies & cache dependencies
150+
uses: "ramsey/composer-install@v3"
151+
env:
152+
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
153+
with:
154+
# Bust the cache at least once a month - output format: YYYY-MM.
155+
custom-cache-suffix: $(date -u "+%Y-%m")
156+
157+
- name: Grab PHPUnit version
158+
id: phpunit_version
159+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
160+
161+
# PHPUnit 10+ may fail a test run when the "old" configuration format is used.
162+
# Luckily, there is a build-in migration tool since PHPUnit 9.3.
163+
- name: Migrate PHPUnit configuration for PHPUnit 10+
164+
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '1' ) }}
165+
continue-on-error: true
166+
run: composer phpunit -- --migrate-configuration
167+
168+
- name: Setup problem matcher to provide annotations for PHPUnit
169+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
170+
171+
- name: Run PHPUnit
172+
run: |
173+
if [[ ${{ matrix.coverage == true }} == true ]]; then
174+
composer phpunit -- --coverage-clover build/logs/unit-coverage.xml
175+
else
176+
composer phpunit
177+
fi
178+
179+
- name: Upload code coverage report
180+
if: ${{ matrix.coverage }}
181+
uses: codecov/[email protected]
182+
with:
183+
directory: build/logs
184+
flags: unit
185+
token: ${{ secrets.CODECOV_TOKEN }}
186+
187+
prepare-functional: #---------------------------------------------------------
188+
name: Prepare matrix for functional tests
189+
needs: get-matrix
190+
runs-on: ubuntu-22.04
191+
outputs:
192+
matrix: ${{ steps.set-matrix.outputs.matrix }}
193+
steps:
194+
- name: Check out source code
195+
uses: actions/checkout@v5
196+
197+
- name: Check existence of composer.json & behat.yml files
198+
id: check_files
199+
uses: andstor/file-existence-action@v3
200+
with:
201+
files: "composer.json, behat.yml"
202+
203+
- name: Set matrix
204+
id: set-matrix
205+
run: |
206+
if [[ $FILE_EXISTS == 'true' ]]; then
207+
echo "matrix=$(jq -c \
208+
--argjson with_coverage_flag "${{ inputs.with-coverage }}" \
209+
--arg minimum_php "${{ inputs.minimum-php }}" \
210+
--arg minimum_wp "${{ inputs.minimum-wp }}" \
211+
'
212+
# First, select only the versions that meet all minimum requirements
213+
.include |= (
214+
map(
215+
select(
216+
.php >= $minimum_php
217+
) |
218+
# Next, update the coverage flag on the remaining items
219+
if $with_coverage_flag == false and .coverage == true then
220+
.coverage = false
221+
else
222+
.
223+
end
224+
)
225+
) |
226+
227+
# Reassign WP4.9 to minimum_wp
228+
.include |= (
229+
map(
230+
select(
231+
.wp == "4.9"
232+
).wp |= $minimum_wp
233+
)
234+
)
235+
' <<< "$BASE_MATRIX" )" >> $GITHUB_OUTPUT
236+
else
237+
echo "matrix=" >> $GITHUB_OUTPUT
238+
fi
239+
env:
240+
BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }}
241+
FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }}
242+
243+
functional: #-----------------------------------------------------------------
244+
needs: prepare-functional
245+
if: ${{ needs.prepare-functional.outputs.matrix != '' }}
246+
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with ${{ matrix.dbtype != 'sqlite' && matrix.mysql || 'SQLite' }}${{ matrix.coverage && ' (with coverage)' || '' }}
247+
strategy:
248+
fail-fast: false
249+
matrix: ${{ fromJson(needs.prepare-functional.outputs.matrix) }}
250+
runs-on: ubuntu-22.04
251+
252+
continue-on-error: ${{ matrix.dbtype == 'sqlite' || matrix.dbtype == 'mariadb' || matrix.php == 'nightly' }}
253+
254+
steps:
255+
- name: Check out source code
256+
uses: actions/checkout@v5
257+
258+
- name: Install Ghostscript
259+
run: |
260+
sudo apt-get update
261+
sudo apt-get install ghostscript -y
262+
263+
- name: Set up PHP environment
264+
uses: shivammathur/setup-php@v2
265+
with:
266+
php-version: '${{ matrix.php }}'
267+
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
268+
extensions: gd, imagick, mysql, zip
269+
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
270+
tools: composer
271+
env:
272+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
273+
274+
- name: Change ImageMagick policy to allow pdf->png conversion.
275+
run: |
276+
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
277+
278+
- name: Install Composer dependencies & cache dependencies
279+
uses: "ramsey/composer-install@v3"
280+
env:
281+
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
282+
with:
283+
# Bust the cache at least once a month - output format: YYYY-MM.
284+
custom-cache-suffix: $(date -u "+%Y-%m")
285+
286+
- name: Setup MySQL Server
287+
id: setup-mysql
288+
if: ${{ matrix.dbtype != 'sqlite' }}
289+
uses: shogo82148/actions-setup-mysql@v1
290+
with:
291+
mysql-version: ${{ matrix.mysql }}
292+
auto-start: true
293+
root-password: root
294+
user: wp_cli_test
295+
password: password1
296+
my-cnf: |
297+
default_authentication_plugin=mysql_native_password
298+
299+
- name: Configure DB environment
300+
if: ${{ matrix.dbtype != 'sqlite' }}
301+
run: |
302+
echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
303+
echo "MYSQL_TCP_PORT=3306" >> $GITHUB_ENV
304+
echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV
305+
echo "WP_CLI_TEST_DBROOTPASS=root" >> $GITHUB_ENV
306+
echo "WP_CLI_TEST_DBNAME=wp_cli_test" >> $GITHUB_ENV
307+
echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV
308+
echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV
309+
echo "WP_CLI_TEST_DBHOST=127.0.0.1:3306" >> $GITHUB_ENV
310+
311+
- name: Prepare test database
312+
if: ${{ matrix.dbtype != 'sqlite' }}
313+
run: composer prepare-tests
314+
315+
- name: Check Behat environment
316+
env:
317+
WP_VERSION: '${{ matrix.wp }}'
318+
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
319+
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
320+
run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat
321+
322+
- name: Run Behat
323+
env:
324+
WP_VERSION: '${{ matrix.wp }}'
325+
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
326+
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
327+
WP_CLI_TEST_COVERAGE: ${{ matrix.coverage }}
328+
run: |
329+
ARGS=()
330+
331+
if [[ $WP_CLI_TEST_COVERAGE == 'true' ]]; then
332+
# The flag was only added in v3.17.0
333+
if composer behat -- --help 2>/dev/null | grep xdebug; then
334+
ARGS+=("--xdebug")
335+
fi
336+
fi
337+
338+
if [[ $RUNNER_DEBUG == '1' ]]; then
339+
ARGS+=("--format=pretty")
340+
fi
341+
342+
composer behat -- "${ARGS[@]}" || composer behat-rerun -- "${ARGS[@]}"
343+
344+
- name: Retrieve list of coverage files
345+
id: coverage_files
346+
if: ${{ matrix.coverage }}
347+
run: |
348+
FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -)
349+
echo "files=$FILES" >> $GITHUB_OUTPUT
350+
351+
- name: Upload code coverage report
352+
if: ${{ matrix.coverage }}
353+
uses: codecov/[email protected]
354+
with:
355+
# Because somehow providing `directory: build/logs` doesn't work for these files
356+
files: ${{ steps.coverage_files.outputs.files }}
357+
flags: feature
358+
token: ${{ secrets.CODECOV_TOKEN }}

0 commit comments

Comments
 (0)