Skip to content

Commit 1c5d092

Browse files
authored
Merge branch 'main' into claude/wp-cli-pr-6365-landing-slkyfp
2 parents 8dbd3ab + 791f3c1 commit 1c5d092

29 files changed

Lines changed: 3449 additions & 131 deletions

‎.github/actionlint.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ paths:
1111
# catching genuine typos in permission names.
1212
# See https://docs.github.com/en/copilot/how-tos/copilot-cli/use-copilot-cli-in-actions
1313
- 'unknown permission scope "copilot-requests"'
14+
# Steps can run in parallel through the `background`, `wait`, `wait-all`,
15+
# `cancel` and `parallel` keywords, but actionlint does not know them yet:
16+
# it rejects `background` as an unexpected key, and a `wait-all` or
17+
# `parallel` step as one that has neither `run` nor `uses`. Drop these
18+
# entries once actionlint supports the keywords. Until then, a step that is
19+
# genuinely missing both `run` and `uses` is no longer reported.
20+
# See https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsparallel
21+
- 'unexpected key "background" for step'
22+
- 'step must run script with "run" section or run action with "uses" section'

‎.github/dependabot.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ updates:
99
- scope:distribution
1010
cooldown:
1111
default-days: 7
12+
# Packages from our own org are trusted, so they are updated immediately.
13+
exclude:
14+
- "wp-cli/*"
1215
# Only wp-cli-tests carries a package.json, holding the pinned version of the
1316
# Gherkin linter. This is a no-op in every other repository.
1417
- package-ecosystem: npm

‎.github/workflows/copilot-setup-steps.yml‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,30 @@ jobs:
3939
id: check_composer_file
4040
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
4141

42+
# Without a database the Behat runner silently falls back to SQLite, so the
43+
# agent's test runs are not the ones CI will do. Mirrors the setup in
44+
# reusable-functional.yml.
45+
- name: Check existence of behat.yml file
46+
id: check_behat_file
47+
run: echo "files_exists=$(test -f behat.yml && echo true || echo false)" >> "$GITHUB_OUTPUT"
48+
49+
# Downloading and starting the database server is the slowest part of the
50+
# setup and it is independent of PHP and Composer, so it runs in the
51+
# background and is waited for right before the test database is prepared.
52+
- name: Setup MySQL Server
53+
if: steps.check_behat_file.outputs.files_exists == 'true'
54+
background: true
55+
uses: shogo82148/actions-setup-mysql@13a38f2af408e58a0c80168fc620a63a15357339 # v1
56+
with:
57+
mysql-version: '8.0' # Standard MySQL version for these tests
58+
auto-start: true
59+
root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }}
60+
user: ${{ env.WP_CLI_TEST_DBUSER }}
61+
password: ${{ env.WP_CLI_TEST_DBPASS }}
62+
4263
- name: Set up PHP environment
4364
if: steps.check_composer_file.outputs.files_exists == 'true'
44-
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
65+
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
4566
with:
4667
php-version: 'latest'
4768
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -56,22 +77,8 @@ jobs:
5677
env:
5778
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
5879

59-
# Without a database the Behat runner silently falls back to SQLite, so the
60-
# agent's test runs are not the ones CI will do. Mirrors the setup in
61-
# reusable-functional.yml.
62-
- name: Check existence of behat.yml file
63-
id: check_behat_file
64-
run: echo "files_exists=$(test -f behat.yml && echo true || echo false)" >> "$GITHUB_OUTPUT"
65-
66-
- name: Setup MySQL Server
67-
if: steps.check_behat_file.outputs.files_exists == 'true'
68-
uses: shogo82148/actions-setup-mysql@62da9377d83991fce27b6ed2a397d3306121e41d # v1
69-
with:
70-
mysql-version: '8.0' # Standard MySQL version for these tests
71-
auto-start: true
72-
root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }}
73-
user: ${{ env.WP_CLI_TEST_DBUSER }}
74-
password: ${{ env.WP_CLI_TEST_DBPASS }}
80+
- name: Wait for the MySQL server
81+
wait-all:
7582

7683
- name: Remove system MySQL binary
7784
if: steps.check_behat_file.outputs.files_exists == 'true'

‎.readme-partials/USING.md‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,41 @@ composer behat -- --stop-on-failure
254254
composer behat-rerun
255255
```
256256
257+
### Running scenarios in parallel
258+
259+
Set `WP_CLI_TEST_PARALLEL` to a number of workers to spread the scenarios over that many Behat processes:
260+
```bash
261+
WP_CLI_TEST_PARALLEL=4 composer behat
262+
```
263+
264+
Every worker but the first gets its own temporary directory, and with it its own home directory, caches and run directories, as well as its own test database, named after the test database with a numeric suffix (`wp_cli_test_1`, `wp_cli_test_2`, ...). Run `composer prepare-tests` once to allow the test user to create these databases. Without that permission, the scenarios are run one after the other, as they are on Windows, when collecting code coverage, or when selecting scenarios by path or name.
265+
266+
Scenarios that rely on resources shared across the system, such as a fixed port or a fixed path in the system's temporary directory, are all run by the first worker, one after the other. `composer behat-rerun` re-runs exactly the scenarios that failed in the last parallel run.
267+
268+
Set `WP_CLI_TEST_DOCKER` to run the scenarios in throwaway Docker containers instead, every worker in its own:
269+
```bash
270+
WP_CLI_TEST_DOCKER=auto WP_CLI_TEST_PARALLEL=4 composer behat
271+
```
272+
273+
| `WP_CLI_TEST_DOCKER` | Effect |
274+
|-------------------------------------|--------------------------------------------------------------------------------------------------|
275+
| not set (default), `0`, `no`, `off` | The scenarios run without Docker. |
276+
| `auto` | The scenarios run in containers where possible, and without Docker otherwise, which is reported. |
277+
| `1`, `yes`, `on` | The scenarios run in containers, and the run fails where that is not possible. |
278+
279+
Docker is not used on Windows, when collecting code coverage, when Docker is not available, when the image cannot be built or when the database server cannot be identified.
280+
281+
Each worker gets its own network, temporary directory and database server, of the same type and version as the one configured through the `WP_CLI_TEST_DB*` variables (or set the image through `WP_CLI_TEST_DOCKER_DB`, e.g. `mysql:8.0`, so that the host needs neither a database server nor a client). Nothing is shared between workers, so they can run any scenario. The database servers keep their data in memory. Scenarios selected by path or name run in a single container.
282+
283+
The containers are removed when the run ends, also when it is stopped with Ctrl+C or a termination signal (with the `pcntl` extension). Containers of a run that was killed outright are removed by the next run on the same host, which only removes those whose run is no longer going.
284+
285+
The containers run the same PHP version as the host, unless `WP_CLI_TEST_DOCKER_PHP` sets another one:
286+
```bash
287+
WP_CLI_TEST_DOCKER=1 WP_CLI_TEST_DOCKER_PHP=7.4 WP_CLI_TEST_PARALLEL=4 composer behat
288+
```
289+
290+
The project's Composer dependencies are then installed for that PHP version in a separate directory, the way CI installs them without a lock file, and refreshed once a day. Dependencies that are linked to local checkouts, as in `wp-cli/wp-cli-dev`, come from their published versions in that case, which is reported.
291+
257292
### Linting the feature files
258293
259294
`composer lint-gherkin` checks `features/` with
@@ -350,6 +385,29 @@ they test.
350385
skipped when there is none, which is the case when the database server runs in a
351386
container and is only reachable over TCP. Set `WP_CLI_TEST_DBSOCKET` to point at the
352387
socket if it lives somewhere unusual.
388+
* `@require-bin-<name>` — the scenario runs a command that is not always installed, such as
389+
`@require-bin-svn` or `@require-bin-ex` for one using `ex` as its editor. It is skipped
390+
where the command is not available. `@require-composer` does the same for Composer.
391+
* `@require-extension-<name>` — the scenario needs a PHP extension, such as
392+
`@require-extension-imagick`. It is skipped where the extension is not loaded.
393+
* `@require-download` — the scenario downloads files from WordPress.org. It is skipped where
394+
WordPress.org cannot be reached.
395+
396+
Requirement tags the test framework does not know are reported with a warning, as they would
397+
not filter anything. When a command fails because a command it runs does not exist, the
398+
failure names the tag to add, and `composer lint-gherkin` lists the scenarios that run
399+
commands which are not always installed without declaring them.
400+
401+
Before the scenarios run, the scenarios that are left out are listed together with the reason,
402+
separating the ones the environment cannot run, such as those needing a PHP extension that is
403+
not loaded, from the ones that are not part of the configuration being tested, such as those
404+
for another database or WordPress version. On GitHub Actions, the list is also added to the
405+
job summary.
406+
407+
Set `WP_CLI_TEST_STRICT_REQUIREMENTS` where the environment is expected to provide everything
408+
the scenarios need, such as on CI. The run then stops before any scenario starts when some of
409+
them cannot run in the environment, or when the database cannot be reached, instead of leaving
410+
those scenarios out or falling back to SQLite.
353411
354412
#### WP-CLI Binary
355413

‎AGENTS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This package is part of WP-CLI, the official command line interface for WordPress. For a detailed explanation of the project structure and development workflow, please refer to the main @README.md file.
44

5+
If the repository contains an @AGENTS.local.md file, read it as well. It holds instructions specific to this repository and takes precedence over this file where the two disagree.
6+
57
## Best Practices for Code Contributions
68

79
When contributing to this package, please adhere to the following guidelines:

‎README.md‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,41 @@ composer behat -- --stop-on-failure
265265
composer behat-rerun
266266
```
267267
268+
### Running scenarios in parallel
269+
270+
Set `WP_CLI_TEST_PARALLEL` to a number of workers to spread the scenarios over that many Behat processes:
271+
```bash
272+
WP_CLI_TEST_PARALLEL=4 composer behat
273+
```
274+
275+
Every worker but the first gets its own temporary directory, and with it its own home directory, caches and run directories, as well as its own test database, named after the test database with a numeric suffix (`wp_cli_test_1`, `wp_cli_test_2`, ...). Run `composer prepare-tests` once to allow the test user to create these databases. Without that permission, the scenarios are run one after the other, as they are on Windows, when collecting code coverage, or when selecting scenarios by path or name.
276+
277+
Scenarios that rely on resources shared across the system, such as a fixed port or a fixed path in the system's temporary directory, are all run by the first worker, one after the other. `composer behat-rerun` re-runs exactly the scenarios that failed in the last parallel run.
278+
279+
Set `WP_CLI_TEST_DOCKER` to run the scenarios in throwaway Docker containers instead, every worker in its own:
280+
```bash
281+
WP_CLI_TEST_DOCKER=auto WP_CLI_TEST_PARALLEL=4 composer behat
282+
```
283+
284+
| `WP_CLI_TEST_DOCKER` | Effect |
285+
|-------------------------------------|--------------------------------------------------------------------------------------------------|
286+
| not set (default), `0`, `no`, `off` | The scenarios run without Docker. |
287+
| `auto` | The scenarios run in containers where possible, and without Docker otherwise, which is reported. |
288+
| `1`, `yes`, `on` | The scenarios run in containers, and the run fails where that is not possible. |
289+
290+
Docker is not used on Windows, when collecting code coverage, when Docker is not available, when the image cannot be built or when the database server cannot be identified.
291+
292+
Each worker gets its own network, temporary directory and database server, of the same type and version as the one configured through the `WP_CLI_TEST_DB*` variables (or set the image through `WP_CLI_TEST_DOCKER_DB`, e.g. `mysql:8.0`, so that the host needs neither a database server nor a client). Nothing is shared between workers, so they can run any scenario. The database servers keep their data in memory. Scenarios selected by path or name run in a single container.
293+
294+
The containers are removed when the run ends, also when it is stopped with Ctrl+C or a termination signal (with the `pcntl` extension). Containers of a run that was killed outright are removed by the next run on the same host, which only removes those whose run is no longer going.
295+
296+
The containers run the same PHP version as the host, unless `WP_CLI_TEST_DOCKER_PHP` sets another one:
297+
```bash
298+
WP_CLI_TEST_DOCKER=1 WP_CLI_TEST_DOCKER_PHP=7.4 WP_CLI_TEST_PARALLEL=4 composer behat
299+
```
300+
301+
The project's Composer dependencies are then installed for that PHP version in a separate directory, the way CI installs them without a lock file, and refreshed once a day. Dependencies that are linked to local checkouts, as in `wp-cli/wp-cli-dev`, come from their published versions in that case, which is reported.
302+
268303
### Linting the feature files
269304
270305
`composer lint-gherkin` checks `features/` with
@@ -361,6 +396,29 @@ they test.
361396
skipped when there is none, which is the case when the database server runs in a
362397
container and is only reachable over TCP. Set `WP_CLI_TEST_DBSOCKET` to point at the
363398
socket if it lives somewhere unusual.
399+
* `@require-bin-<name>` — the scenario runs a command that is not always installed, such as
400+
`@require-bin-svn` or `@require-bin-ex` for one using `ex` as its editor. It is skipped
401+
where the command is not available. `@require-composer` does the same for Composer.
402+
* `@require-extension-<name>` — the scenario needs a PHP extension, such as
403+
`@require-extension-imagick`. It is skipped where the extension is not loaded.
404+
* `@require-download` — the scenario downloads files from WordPress.org. It is skipped where
405+
WordPress.org cannot be reached.
406+
407+
Requirement tags the test framework does not know are reported with a warning, as they would
408+
not filter anything. When a command fails because a command it runs does not exist, the
409+
failure names the tag to add, and `composer lint-gherkin` lists the scenarios that run
410+
commands which are not always installed without declaring them.
411+
412+
Before the scenarios run, the scenarios that are left out are listed together with the reason,
413+
separating the ones the environment cannot run, such as those needing a PHP extension that is
414+
not loaded, from the ones that are not part of the configuration being tested, such as those
415+
for another database or WordPress version. On GitHub Actions, the list is also added to the
416+
job summary.
417+
418+
Set `WP_CLI_TEST_STRICT_REQUIREMENTS` where the environment is expected to provide everything
419+
the scenarios need, such as on CI. The run then stops before any scenario starts when some of
420+
them cannot run in the environment, or when the database cannot be reached, instead of leaving
421+
those scenarios out or falling back to SQLite.
364422
365423
#### WP-CLI Binary
366424

‎bin/install-package-tests‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ install_mysql_db_8_0_plus() {
150150
${CLIENT_BINARY} -e "CREATE USER IF NOT EXISTS \`${TEST_USER}\`@'%' IDENTIFIED WITH caching_sha2_password BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
151151
${CLIENT_BINARY} -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
152152
${CLIENT_BINARY} -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}_scaffold\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
153+
# The databases of parallel test workers, named after the test database with a numeric suffix.
154+
${CLIENT_BINARY} -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}\\_%\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
153155
{ set +ex; } 2> /dev/null # stop printing the commands
154156
}
155157

@@ -159,6 +161,8 @@ install_mysql_db_lower_than_8_0() {
159161
${CLIENT_BINARY} -e "CREATE DATABASE IF NOT EXISTS \`${TEST_DB}\`;" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
160162
${CLIENT_BINARY} -e "GRANT ALL ON \`${TEST_DB}\`.* TO '${TEST_USER}'@'%' IDENTIFIED BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
161163
${CLIENT_BINARY} -e "GRANT ALL ON \`${TEST_DB}_scaffold\`.* TO '${TEST_USER}'@'%' IDENTIFIED BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
164+
# The databases of parallel test workers, named after the test database with a numeric suffix.
165+
${CLIENT_BINARY} -e "GRANT ALL ON \`${TEST_DB}\\_%\`.* TO '${TEST_USER}'@'%' IDENTIFIED BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
162166
{ set +ex; } 2> /dev/null # stop printing the commands
163167
}
164168

@@ -169,6 +173,8 @@ install_mariadb() {
169173
${CLIENT_BINARY} -e "CREATE USER IF NOT EXISTS \`${TEST_USER}\`@'%' IDENTIFIED BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
170174
${CLIENT_BINARY} -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
171175
${CLIENT_BINARY} -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}_scaffold\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
176+
# The databases of parallel test workers, named after the test database with a numeric suffix.
177+
${CLIENT_BINARY} -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}\\_%\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
172178
}
173179

174180
if [ "${TYPE}" = "MariaDB" ]; then

0 commit comments

Comments
 (0)