Skip to content

Commit 0884b0a

Browse files
authored
Merge branch 'main' into try/322-refresh
2 parents 6f17adf + 91c93ff commit 0884b0a

14 files changed

Lines changed: 352 additions & 19 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Check Branch Alias
2+
3+
on:
4+
release:
5+
types: [released]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
check-branch-alias:
14+
uses: wp-cli/.github/.github/workflows/reusable-check-branch-alias.yml@main
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "Copilot Setup Steps"
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- .github/workflows/copilot-setup-steps.yml
8+
pull_request:
9+
paths:
10+
- .github/workflows/copilot-setup-steps.yml
11+
12+
jobs:
13+
copilot-setup-steps:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v6
21+
22+
- name: Check existence of composer.json file
23+
id: check_composer_file
24+
uses: andstor/file-existence-action@v3
25+
with:
26+
files: "composer.json"
27+
28+
- name: Set up PHP environment
29+
if: steps.check_composer_file.outputs.files_exists == 'true'
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: 'latest'
33+
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
34+
coverage: 'none'
35+
tools: composer,cs2pr
36+
env:
37+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Install Composer dependencies & cache dependencies
40+
if: steps.check_composer_file.outputs.files_exists == 'true'
41+
uses: ramsey/composer-install@v3
42+
env:
43+
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
44+
with:
45+
# Bust the cache at least once a month - output format: YYYY-MM.
46+
custom-cache-suffix: $(date -u "+%Y-%m")

.github/workflows/issue-triage.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Issue and PR Triage
3+
4+
'on':
5+
issues:
6+
types: [opened]
7+
pull_request_target:
8+
types: [opened]
9+
workflow_dispatch:
10+
inputs:
11+
issue_number:
12+
description: 'Issue/PR number to triage (leave empty to process all)'
13+
required: false
14+
type: string
15+
16+
jobs:
17+
issue-triage:
18+
uses: wp-cli/.github/.github/workflows/reusable-issue-triage.yml@main
19+
with:
20+
issue_number: >-
21+
${{
22+
(github.event_name == 'workflow_dispatch' && inputs.issue_number) ||
23+
(github.event_name == 'pull_request_target' && github.event.pull_request.number) ||
24+
(github.event_name == 'issues' && github.event.issue.number) ||
25+
''
26+
}}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Manage Labels
3+
4+
'on':
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- main
9+
- master
10+
paths:
11+
- 'composer.json'
12+
13+
permissions:
14+
issues: write
15+
contents: read
16+
17+
jobs:
18+
manage-labels:
19+
uses: wp-cli/.github/.github/workflows/reusable-manage-labels.yml@main
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Welcome New Contributors
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
branches:
7+
- main
8+
- master
9+
10+
jobs:
11+
welcome:
12+
uses: wp-cli/.github/.github/workflows/reusable-welcome-new-contributors.yml@main

AGENTS.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Instructions
2+
3+
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.
4+
5+
## Best Practices for Code Contributions
6+
7+
When contributing to this package, please adhere to the following guidelines:
8+
9+
* **Follow Existing Conventions:** Before writing any code, analyze the existing codebase in this package to understand the coding style, naming conventions, and architectural patterns.
10+
* **Focus on the Package's Scope:** All changes should be relevant to the functionality of the package.
11+
* **Write Tests:** All new features and bug fixes must be accompanied by acceptance tests using Behat. You can find the existing tests in the `features/` directory. There may be PHPUnit unit tests as well in the `tests/` directory.
12+
* **Update Documentation:** If your changes affect the user-facing functionality, please update the relevant inline code documentation.
13+
14+
### Building and running
15+
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`.
17+
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.
19+
20+
### Useful Composer Commands
21+
22+
The project uses Composer to manage dependencies and run scripts. The following commands are available:
23+
24+
* `composer install`: Install dependencies.
25+
* `composer test`: Run the full test suite, including linting, code style checks, static analysis, and unit/behavior tests.
26+
* `composer lint`: Check for syntax errors.
27+
* `composer phpcs`: Check for code style violations.
28+
* `composer phpcbf`: Automatically fix code style violations.
29+
* `composer phpstan`: Run static analysis.
30+
* `composer phpunit`: Run unit tests.
31+
* `composer behat`: Run behavior-driven tests.
32+
33+
### Coding Style
34+
35+
The project follows the `WP_CLI_CS` coding standard, which is enforced by PHP_CodeSniffer. The configuration can be found in `phpcs.xml.dist`. Before submitting any code, please run `composer phpcs` to check for violations and `composer phpcbf` to automatically fix them.
36+
37+
## Documentation
38+
39+
The `README.md` file might be generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme)). In that case, changes need to be made against the corresponding part of the codebase.
40+
41+
### Inline Documentation
42+
43+
Only write high-value comments if at all. Avoid talking to the user through comments.
44+
45+
## Testing
46+
47+
The project has a comprehensive test suite that includes unit tests, behavior-driven tests, and static analysis.
48+
49+
* **Unit tests** are written with PHPUnit and can be found in the `tests/` directory. The configuration is in `phpunit.xml.dist`.
50+
* **Behavior-driven tests** are written with Behat and can be found in the `features/` directory. The configuration is in `behat.yml`.
51+
* **Static analysis** is performed with PHPStan.
52+
53+
All tests are run on GitHub Actions for every pull request.
54+
55+
When writing tests, aim to follow existing patterns. Key conventions include:
56+
57+
* When adding tests, first examine existing tests to understand and conform to established conventions.
58+
* For unit tests, extend the base `WP_CLI\Tests\TestCase` test class.
59+
* For Behat tests, only WP-CLI commands installed in `composer.json` can be run.
60+
61+
### Behat Steps
62+
63+
WP-CLI makes use of a Behat-based testing framework and provides a set of custom step definitions to write feature tests.
64+
65+
> **Note:** If you are expecting an error output in a test, you need to use `When I try ...` instead of `When I run ...` .
66+
67+
#### Given
68+
69+
* `Given an empty directory` - Creates an empty directory.
70+
* `Given /^an? (empty|non-existent) ([^\s]+) directory$/` - Creates or deletes a specific directory.
71+
* `Given an empty cache` - Clears the WP-CLI cache directory.
72+
* `Given /^an? ([^\s]+) (file|cache file):$/` - Creates a file with the given contents.
73+
* `Given /^"([^"]+)" replaced with "([^"]+)" in the ([^\s]+) file$/` - Search and replace a string in a file using regex.
74+
* `Given /^that HTTP requests to (.*?) will respond with:$/` - Mock HTTP requests to a given URL.
75+
* `Given WP files` - Download WordPress files without installing.
76+
* `Given wp-config.php` - Create a wp-config.php file using `wp config create`.
77+
* `Given a database` - Creates an empty database.
78+
* `Given a WP install(ation)` - Installs WordPress.
79+
* `Given a WP install(ation) in :subdir` - Installs WordPress in a given directory.
80+
* `Given a WP install(ation) with Composer` - Installs WordPress with Composer.
81+
* `Given a WP install(ation) with Composer and a custom vendor directory :vendor_directory` - Installs WordPress with Composer and a custom vendor directory.
82+
* `Given /^a WP multisite (subdirectory|subdomain)?\s?(install|installation)$/` - Installs WordPress Multisite.
83+
* `Given these installed and active plugins:` - Installs and activates one or more plugins.
84+
* `Given a custom wp-content directory` - Configure a custom `wp-content` directory.
85+
* `Given download:` - Download multiple files into the given destinations.
86+
* `Given /^save (STDOUT|STDERR) ([\'].+[^\'])?\s?as \{(\w+)\}$/` - Store STDOUT or STDERR contents in a variable.
87+
* `Given /^a new Phar with (?:the same version|version "([^"]+)")$/` - Build a new WP-CLI Phar file with a given version.
88+
* `Given /^a downloaded Phar with (?:the same version|version "([^"]+)")$/` - Download a specific WP-CLI Phar version from GitHub.
89+
* `Given /^save the (.+) file ([\'].+[^\'])? as \{(\w+)\}$/` - Stores the contents of the given file in a variable.
90+
* `Given a misconfigured WP_CONTENT_DIR constant directory` - Modify wp-config.php to set `WP_CONTENT_DIR` to an empty string.
91+
* `Given a dependency on current wp-cli` - Add `wp-cli/wp-cli` as a Composer dependency.
92+
* `Given a PHP built-in web server` - Start a PHP built-in web server in the current directory.
93+
* `Given a PHP built-in web server to serve :subdir` - Start a PHP built-in web server in the given subdirectory.
94+
95+
#### When
96+
97+
* ``When /^I launch in the background `([^`]+)`$/`` - Launch a given command in the background.
98+
* ``When /^I (run|try) `([^`]+)`$/`` - Run or try a given command.
99+
* ``When /^I (run|try) `([^`]+)` from '([^\s]+)'$/`` - Run or try a given command in a subdirectory.
100+
* `When /^I (run|try) the previous command again$/` - Run or try the previous command again.
101+
102+
#### Then
103+
104+
* `Then /^the return code should( not)? be (\d+)$/` - Expect a specific exit code of the previous command.
105+
* `Then /^(STDOUT|STDERR) should( strictly)? (be|contain|not contain):$/` - Check the contents of STDOUT or STDERR.
106+
* `Then /^(STDOUT|STDERR) should be a number$/` - Expect STDOUT or STDERR to be a numeric value.
107+
* `Then /^(STDOUT|STDERR) should not be a number$/` - Expect STDOUT or STDERR to not be a numeric value.
108+
* `Then /^STDOUT should be a table containing rows:$/` - Expect STDOUT to be a table containing the given rows.
109+
* `Then /^STDOUT should end with a table containing rows:$/` - Expect STDOUT to end with a table containing the given rows.
110+
* `Then /^STDOUT should be JSON containing:$/` - Expect valid JSON output in STDOUT.
111+
* `Then /^STDOUT should be a JSON array containing:$/` - Expect valid JSON array output in STDOUT.
112+
* `Then /^STDOUT should be CSV containing:$/` - Expect STDOUT to be CSV containing certain values.
113+
* `Then /^STDOUT should be YAML containing:$/` - Expect STDOUT to be YAML containing certain content.
114+
* `Then /^(STDOUT|STDERR) should be empty$/` - Expect STDOUT or STDERR to be empty.
115+
* `Then /^(STDOUT|STDERR) should not be empty$/` - Expect STDOUT or STDERR not to be empty.
116+
* `Then /^(STDOUT|STDERR) should be a version string (<|<=|>|>=|==|=|<>) ([+\w.{}-]+)$/` - Expect STDOUT or STDERR to be a version string comparing to the given version.
117+
* `Then /^the (.+) (file|directory) should( strictly)? (exist|not exist|be:|contain:|not contain):$/` - Expect a certain file or directory to (not) exist or (not) contain certain contents.
118+
* `Then /^the contents of the (.+) file should( not)? match (((\/.*\/)|(#.#))([a-z]+)?)$/` - Match file contents against a regex.
119+
* `Then /^(STDOUT|STDERR) should( not)? match (((\/.*\/)|(#.#))([a-z]+)?)$/` - Match STDOUT or STDERR against a regex.
120+
* `Then /^an email should (be sent|not be sent)$/` - Expect an email to be sent (or not).
121+
* `Then the HTTP status code should be :code` - Expect the HTTP status code for visiting `http://localhost:8080`.

features/install-wp-tests.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ Feature: Scaffold install-wp-tests.sh tests
383383
Leaving the existing database (wp_cli_test_scaffold) in place
384384
"""
385385
386-
@require-php-7.2 @require-mysql
386+
@require-php-7.4 @require-mysql
387387
Scenario: Install WordPress from trunk
388388
Given a WP install
389389
And a get-phpunit-phar-url.php file:

features/scaffold-block.feature

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ Feature: WordPress block code scaffolding
5959
"""
6060
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
6161
"""
62-
register_block_type( 'movies/the-green-mile', [
62+
register_block_type(
63+
"""
64+
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
65+
"""
66+
'movies/the-green-mile',
6367
"""
6468
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
6569
"""

features/scaffold-lint.feature

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Feature: Lint scaffolded code
2+
3+
Background:
4+
Given a WP install
5+
And I run `wp plugin path`
6+
And save STDOUT as {PLUGIN_DIR}
7+
8+
# Create a helper plugin to install phpcs once for all scenarios
9+
When I run `wp scaffold plugin phpcs-helper --skip-tests`
10+
Then the return code should be 0
11+
12+
# Install coding standards
13+
When I run `composer config --working-dir={PLUGIN_DIR}/phpcs-helper allow-plugins.dealerdirect/phpcodesniffer-composer-installer true`
14+
Then the return code should be 0
15+
16+
When I run `composer require --dev --working-dir={PLUGIN_DIR}/phpcs-helper dealerdirect/phpcodesniffer-composer-installer wp-coding-standards/wpcs --no-interaction --quiet`
17+
Then the return code should be 0
18+
19+
Scenario: Scaffold plugin and lint it
20+
When I run `wp scaffold plugin test-plugin`
21+
Then STDOUT should not be empty
22+
And the {PLUGIN_DIR}/test-plugin/test-plugin.php file should exist
23+
And the {PLUGIN_DIR}/test-plugin/.phpcs.xml.dist file should exist
24+
25+
When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {PLUGIN_DIR}/test-plugin/test-plugin.php`
26+
Then the return code should be 0
27+
28+
Scenario: Scaffold post-type and lint it
29+
When I run `wp theme install twentytwentyone --force --activate`
30+
And I run `wp eval 'echo STYLESHEETPATH;'`
31+
And save STDOUT as {STYLESHEETPATH}
32+
33+
And I run `wp scaffold post-type movie --theme`
34+
Then STDOUT should not be empty
35+
And the {STYLESHEETPATH}/post-types/movie.php file should exist
36+
37+
When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {STYLESHEETPATH}/post-types/movie.php`
38+
Then the return code should be 0
39+
40+
Scenario: Scaffold taxonomy and lint it
41+
When I run `wp theme install twentytwentyone --force --activate`
42+
And I run `wp eval 'echo STYLESHEETPATH;'`
43+
And save STDOUT as {STYLESHEETPATH}
44+
45+
And I run `wp scaffold taxonomy genre --theme`
46+
Then STDOUT should not be empty
47+
And the {STYLESHEETPATH}/taxonomies/genre.php file should exist
48+
49+
When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {STYLESHEETPATH}/taxonomies/genre.php`
50+
Then the return code should be 0
51+
52+
Scenario: Scaffold plugin tests and lint them
53+
When I run `wp scaffold plugin test-plugin`
54+
Then STDOUT should not be empty
55+
And the {PLUGIN_DIR}/test-plugin/tests directory should exist
56+
And the {PLUGIN_DIR}/test-plugin/tests/bootstrap.php file should exist
57+
And the {PLUGIN_DIR}/test-plugin/tests/test-sample.php file should exist
58+
59+
# Run phpcs on the test files
60+
When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {PLUGIN_DIR}/test-plugin/tests/bootstrap.php {PLUGIN_DIR}/test-plugin/tests/test-sample.php`
61+
Then the return code should be 0
62+
63+
Scenario: Scaffold child theme and lint it
64+
When I run `wp theme install twentytwentyone --force --activate`
65+
And I run `wp theme path`
66+
And save STDOUT as {THEME_DIR}
67+
68+
And I run `wp scaffold child-theme test-child --parent_theme=twentytwentyone`
69+
Then STDOUT should not be empty
70+
And the {THEME_DIR}/test-child/functions.php file should exist
71+
72+
When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {THEME_DIR}/test-child/functions.php`
73+
Then the return code should be 0
74+
75+
Scenario: Scaffold block and lint it
76+
When I run `wp scaffold plugin movies`
77+
And I run `wp plugin path movies --dir`
78+
And save STDOUT as {MOVIES_DIR}
79+
80+
And I run `wp scaffold block the-green-mile --plugin=movies`
81+
Then STDOUT should not be empty
82+
And the {MOVIES_DIR}/blocks/the-green-mile.php file should exist
83+
84+
When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {MOVIES_DIR}/blocks/the-green-mile.php`
85+
Then the return code should be 0

features/scaffold-plugin-tests.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Feature: Scaffold plugin unit tests
2121
"""
2222
And the {PLUGIN_DIR}/hello-world/tests/bootstrap.php file should contain:
2323
"""
24-
require dirname( dirname( __FILE__ ) ) . '/hello-world.php';
24+
require dirname( __DIR__ ) . '/hello-world.php';
2525
"""
2626
And the {PLUGIN_DIR}/hello-world/tests/bootstrap.php file should contain:
2727
"""
@@ -302,7 +302,7 @@ Feature: Scaffold plugin unit tests
302302
When I run `wp scaffold plugin-tests foo`
303303
Then the wp-content/plugins/foo/tests/bootstrap.php file should contain:
304304
"""
305-
require dirname( dirname( __FILE__ ) ) . '/bar.php';
305+
require dirname( __DIR__ ) . '/bar.php';
306306
"""
307307

308308
Scenario: Accept bitbucket as valid CI in plugin scaffold

0 commit comments

Comments
 (0)