Skip to content

Commit 8d31feb

Browse files
committed
Merge remote-tracking branch 'origin/main' into contrib/cache-command-125
2 parents 3e514ea + 8794558 commit 8d31feb

15 files changed

Lines changed: 246 additions & 110 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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
version: 2
22
updates:
33
- package-ecosystem: composer
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
labels:
9+
- scope:distribution
10+
cooldown:
11+
default-days: 7
12+
# Packages from our own org are trusted, so they are updated immediately.
13+
exclude:
14+
- "wp-cli/*"
15+
# Only wp-cli-tests carries a package.json, holding the pinned version of the
16+
# Gherkin linter. This is a no-op in every other repository.
17+
- package-ecosystem: npm
418
directory: "/"
519
schedule:
620
interval: daily

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ jobs:
1919
permissions:
2020
contents: read
2121

22+
env:
23+
MYSQL_HOST: 127.0.0.1
24+
MYSQL_TCP_PORT: 3306
25+
WP_CLI_TEST_DBROOTUSER: root
26+
WP_CLI_TEST_DBROOTPASS: root
27+
WP_CLI_TEST_DBNAME: wp_cli_test
28+
WP_CLI_TEST_DBUSER: wp_cli_test
29+
WP_CLI_TEST_DBPASS: password1
30+
WP_CLI_TEST_DBHOST: 127.0.0.1:3306
31+
2232
steps:
2333
- name: Checkout code
2434
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -29,9 +39,30 @@ jobs:
2939
id: check_composer_file
3040
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
3141

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+
# Not run in the background: Copilot code review builds its workflow from
50+
# these steps and failed validation while they used `background` and
51+
# `wait-all`. Also, the action unpacks its binaries with the system `tar`,
52+
# which fails to load libpcre2 while setup-php upgrades it with apt.
53+
- name: Setup MySQL Server
54+
if: steps.check_behat_file.outputs.files_exists == '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+
3263
- name: Set up PHP environment
3364
if: steps.check_composer_file.outputs.files_exists == 'true'
34-
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
65+
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
3566
with:
3667
php-version: 'latest'
3768
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -45,3 +76,11 @@ jobs:
4576
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
4677
env:
4778
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
79+
80+
- name: Remove system MySQL binary
81+
if: steps.check_behat_file.outputs.files_exists == 'true'
82+
run: sudo rm -f /usr/bin/mysql /usr/bin/mysqldump
83+
84+
- name: Prepare test database
85+
if: steps.check_behat_file.outputs.files_exists == 'true'
86+
run: composer prepare-tests
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Milestone Merged Pull Requests
3+
4+
'on':
5+
pull_request_target:
6+
types: [closed]
7+
branches:
8+
- main
9+
- master
10+
11+
permissions:
12+
issues: write
13+
pull-requests: write
14+
15+
jobs:
16+
milestone:
17+
uses: wp-cli/.github/.github/workflows/reusable-milestone-merged-prs.yml@main

‎AGENTS.md‎

Lines changed: 23 additions & 2 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:
@@ -13,9 +15,27 @@ When contributing to this package, please adhere to the following guidelines:
1315

1416
### Building and running
1517

16-
Before submitting any changes, it is crucial to validate them by running the full suite of static code analysis and tests. To run the full suite of checks, execute the following command: `composer test`.
18+
Run the narrowest check that covers your change:
19+
20+
| You changed | Run |
21+
| --- | --- |
22+
| Any PHP file | `composer phpcs -- <file>` and `composer phpstan` |
23+
| Logic with unit test coverage | `composer phpunit -- --filter <TestName>` |
24+
| One feature file | `composer behat -- features/<name>.feature` |
25+
| One scenario | `composer behat -- features/<name>.feature:<line>` |
26+
27+
After a failure, `composer behat-rerun` re-runs only the scenarios that failed, and `composer behat -- --stop-on-failure` bails out at the first one instead of working through the rest.
28+
29+
`composer test` runs every suite, the whole Behat suite included. In most packages that means installing WordPress from scratch once per scenario, which takes tens of minutes and needs `jq`, a MySQL or MariaDB client with a prepared test database, and network access to WordPress.org. Run it before opening a pull request when you have touched something cross-cutting. Do not run it to check a two-line change.
30+
31+
Set these first, so the tools report problems compactly instead of drawing progress bars and ANSI color into output you are going to read back:
32+
33+
```bash
34+
export NO_COLOR=1
35+
export WP_CLI_TEST_QUIET=1
36+
```
1737

18-
This single command ensures that your changes meet all the quality gates of the project. While you can run the individual steps separately, it is highly recommended to use this single command to ensure a comprehensive validation.
38+
Note that a green `composer test` is not the same as a green CI. `actionlint` and `typos` also run on every pull request and are not part of it.
1939

2040
### Useful Composer Commands
2141

@@ -24,6 +44,7 @@ The project uses Composer to manage dependencies and run scripts. The following
2444
* `composer install`: Install dependencies.
2545
* `composer test`: Run the full test suite, including linting, code style checks, static analysis, and unit/behavior tests.
2646
* `composer lint`: Check for syntax errors.
47+
* `composer lint-gherkin`: Check the Behat feature files for style violations.
2748
* `composer phpcs`: Check for code style violations.
2849
* `composer phpcbf`: Automatically fix code style violations.
2950
* `composer phpstan`: Run static analysis.

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ network|site cache, please see docs for `wp transient`.
521521

522522
[--network]
523523
Delete the value of a network|site transient. On single site, this is
524-
is a specially-named cache key. On multisite, this is a global cache
524+
a specially-named cache key. On multisite, this is a global cache
525525
(instead of local to the site).
526526

527527
[--all]
@@ -586,7 +586,7 @@ network|site cache, please see docs for `wp transient`.
586586

587587
[--network]
588588
Get the value of a network|site transient. On single site, this is
589-
is a specially-named cache key. On multisite, this is a global cache
589+
a specially-named cache key. On multisite, this is a global cache
590590
(instead of local to the site).
591591

592592
**EXAMPLES**
@@ -773,7 +773,7 @@ network|site cache, please see docs for `wp transient`.
773773

774774
[--network]
775775
Set the value of a network|site transient. On single site, this is
776-
is a specially-named cache key. On multisite, this is a global cache
776+
a specially-named cache key. On multisite, this is a global cache
777777
(instead of local to the site).
778778

779779
**EXAMPLES**

‎composer.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"require-dev": {
1818
"wp-cli/entity-command": "^1.3 || ^2 || ^3",
19-
"wp-cli/wp-cli-tests": "^5"
19+
"wp-cli/wp-cli-tests": "^5.4.0"
2020
},
2121
"config": {
2222
"process-timeout": 7200,
@@ -77,13 +77,15 @@
7777
"behat": "run-behat-tests",
7878
"behat-rerun": "rerun-behat-tests",
7979
"lint": "run-linter-tests",
80+
"lint-gherkin": "run-gherkin-lint-tests",
8081
"phpcs": "run-phpcs-tests",
8182
"phpstan": "run-phpstan-tests",
8283
"phpcbf": "run-phpcbf-cleanup",
8384
"phpunit": "run-php-unit-tests",
8485
"prepare-tests": "install-package-tests",
8586
"test": [
8687
"@lint",
88+
"@lint-gherkin",
8789
"@phpcs",
8890
"@phpstan",
8991
"@phpunit",

‎features/cache-patch.feature‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ Feature: Patch command available for the object cache
55
And a wp-content/mu-plugins/test-harness.php file:
66
"""php
77
<?php
8-
$set_foo = function(){
9-
wp_cache_set( 'my_key', ['foo' => 'bar'] );
10-
wp_cache_set( 'other_key', ['fuz' => 'biz'] );
11-
wp_cache_set( 'my_key_in_group', ['fuz' => 'biz'], 'my_group' );
12-
13-
$complex_key = (object) [
14-
'foo' => (object) [
15-
'bar' => (object) [
16-
'baz' => 2,
17-
],
18-
],
19-
];
20-
wp_cache_set( 'complex_key', $complex_key );
8+
$set_foo = function () {
9+
wp_cache_set( 'my_key', [ 'foo' => 'bar' ] );
10+
wp_cache_set( 'other_key', [ 'fuz' => 'biz' ] );
11+
wp_cache_set( 'my_key_in_group', [ 'fuz' => 'biz' ], 'my_group' );
12+
13+
$complex_key = (object) [
14+
'foo' => (object) [
15+
'bar' => (object) [
16+
'baz' => 2,
17+
],
18+
],
19+
];
20+
wp_cache_set( 'complex_key', $complex_key );
2121
};
2222
2323
WP_CLI::add_hook( 'before_invoke:cache patch', $set_foo );

‎features/cache-pluck.feature‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Feature: Pluck command available for the object cache
55
And a wp-content/mu-plugins/test-harness.php file:
66
"""php
77
<?php
8-
$set_foo = function(){
9-
wp_cache_set( 'my_key', ['foo' => 'bar'] );
10-
wp_cache_set( 'my_key_2', ['foo' => ['bar' => 'baz']] );
11-
wp_cache_set( 'my_key_3', ['foo' => 'bar_custom'], 'my_custom_group' );
8+
$set_foo = function () {
9+
wp_cache_set( 'my_key', [ 'foo' => 'bar' ] );
10+
wp_cache_set( 'my_key_2', [ 'foo' => [ 'bar' => 'baz' ] ] );
11+
wp_cache_set( 'my_key_3', [ 'foo' => 'bar_custom' ], 'my_custom_group' );
1212
};
1313
1414
WP_CLI::add_hook( 'before_invoke:cache pluck', $set_foo );

‎features/cache.feature‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Feature: Managed the WordPress object cache
44
Scenario: Default group is 'default'
55
Given a WP install
66
And a wp-content/mu-plugins/test-harness.php file:
7-
"""
7+
"""php
88
<?php
9-
$set_foo = function(){
10-
wp_cache_set( 'foo', 'bar' );
9+
$set_foo = function () {
10+
wp_cache_set( 'foo', 'bar' );
1111
};
12-
$set_foo_value = function() {
13-
wp_cache_set( 'foo', 2 );
12+
$set_foo_value = function () {
13+
wp_cache_set( 'foo', 2 );
1414
};
15-
$log_foo_value = function() {
16-
WP_CLI::log( var_export( wp_cache_get( 'foo' ), true ) );
15+
$log_foo_value = function () {
16+
WP_CLI::log( var_export( wp_cache_get( 'foo' ), true ) );
1717
};
1818
WP_CLI::add_hook( 'before_invoke:cache get', $set_foo );
1919
WP_CLI::add_hook( 'before_invoke:cache delete', $set_foo );
@@ -150,12 +150,12 @@ Feature: Managed the WordPress object cache
150150
"""php
151151
<?php
152152
class Dummy_Object_Cache extends WP_Object_Cache {
153-
public function flush_group( $group ) {
154-
if ( $group === 'permanent_root_cache' ) {
155-
return false;
153+
public function flush_group( $group ) {
154+
if ( $group === 'permanent_root_cache' ) {
155+
return false;
156+
}
157+
return parent::flush_group( $group );
156158
}
157-
return parent::flush_group( $group );
158-
}
159159
}
160160
$GLOBALS['wp_object_cache'] = new Dummy_Object_Cache();
161161
"""
@@ -172,12 +172,12 @@ Feature: Managed the WordPress object cache
172172
"""php
173173
<?php
174174
class Dummy_Object_Cache extends WP_Object_Cache {
175-
public function flush_group( $group ) {
176-
if ( $group === 'permanent_root_cache' ) {
177-
return false;
175+
public function flush_group( $group ) {
176+
if ( $group === 'permanent_root_cache' ) {
177+
return false;
178+
}
179+
return parent::flush_group( $group );
178180
}
179-
return parent::flush_group( $group );
180-
}
181181
}
182182
$GLOBALS['wp_object_cache'] = new Dummy_Object_Cache();
183183
"""

0 commit comments

Comments
 (0)