diff --git a/.editorconfig b/.editorconfig index 8ccb6af..84f918e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,9 @@ # editorconfig.org # WordPress Coding Standards -# http://make.wordpress.org/core/handbook/coding-standards/ +# https://make.wordpress.org/core/handbook/coding-standards/ + +# From https://github.com/WordPress/wordpress-develop/blob/trunk/.editorconfig with a couple of additions. root = true @@ -12,12 +14,13 @@ end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true indent_style = tab -indent_size = 4 -[*.{json,yml,feature}] +[{*.yml,*.feature,.jshintrc,*.json}] indent_style = space indent_size = 2 -[composer.json] -indent_style = space -indent_size = 4 +[*.md] +trim_trailing_whitespace = false + +[{*.txt,wp-config-sample.php}] +end_of_line = crlf diff --git a/.github/workflows/check-branch-alias.yml b/.github/workflows/check-branch-alias.yml new file mode 100644 index 0000000..78da637 --- /dev/null +++ b/.github/workflows/check-branch-alias.yml @@ -0,0 +1,14 @@ +name: Check Branch Alias + +on: + release: + types: [released] + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + check-branch-alias: + uses: wp-cli/.github/.github/workflows/reusable-check-branch-alias.yml@main diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 07e4fd1..27f9b00 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -6,7 +6,13 @@ on: branches: - main - master + schedule: + - cron: '17 2 * * *' # Run every day on a seemly random time. jobs: code-quality: uses: wp-cli/.github/.github/workflows/reusable-code-quality.yml@main + with: + parallel-lint-excludes: | + process + wordpress-core diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml new file mode 100644 index 0000000..d5e319e --- /dev/null +++ b/.github/workflows/copilot-setup-steps.yml @@ -0,0 +1,47 @@ +name: "Copilot Setup Steps" + +on: + workflow_dispatch: + push: + paths: + - .github/workflows/copilot-setup-steps.yml + pull_request: + paths: + - .github/workflows/copilot-setup-steps.yml + +permissions: + contents: read + +jobs: + copilot-setup-steps: + name: Setup environment + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + persist-credentials: false + + - name: Check existence of composer.json file + id: check_composer_file + run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT" + + - name: Set up PHP environment + if: steps.check_composer_file.outputs.files_exists == 'true' + uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # v2 + with: + php-version: 'latest' + ini-values: zend.assertions=1, error_reporting=-1, display_errors=On + coverage: 'none' + tools: composer,cs2pr + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install Composer dependencies & cache dependencies + if: steps.check_composer_file.outputs.files_exists == 'true' + uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0 + env: + COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }} diff --git a/.github/workflows/issue-triage.yml b/.github/workflows/issue-triage.yml new file mode 100644 index 0000000..6833470 --- /dev/null +++ b/.github/workflows/issue-triage.yml @@ -0,0 +1,33 @@ +--- +name: Issue and PR Triage + +'on': + issues: + types: [opened] + pull_request_target: + types: [opened] + workflow_dispatch: + inputs: + issue_number: + description: 'Issue/PR number to triage (leave empty to process all)' + required: false + type: string + +permissions: + issues: write + pull-requests: write + actions: write + contents: read + models: read + +jobs: + issue-triage: + uses: wp-cli/.github/.github/workflows/reusable-issue-triage.yml@main + with: + issue_number: >- + ${{ + (github.event_name == 'workflow_dispatch' && inputs.issue_number) || + (github.event_name == 'pull_request_target' && github.event.pull_request.number) || + (github.event_name == 'issues' && github.event.issue.number) || + '' + }} diff --git a/.github/workflows/manage-labels.yml b/.github/workflows/manage-labels.yml new file mode 100644 index 0000000..45711bd --- /dev/null +++ b/.github/workflows/manage-labels.yml @@ -0,0 +1,19 @@ +--- +name: Manage Labels + +'on': + workflow_dispatch: + push: + branches: + - main + - master + paths: + - 'composer.json' + +permissions: + issues: write + contents: read + +jobs: + manage-labels: + uses: wp-cli/.github/.github/workflows/reusable-manage-labels.yml@main diff --git a/.github/workflows/regenerate-readme.yml b/.github/workflows/regenerate-readme.yml new file mode 100644 index 0000000..6198d63 --- /dev/null +++ b/.github/workflows/regenerate-readme.yml @@ -0,0 +1,19 @@ +name: Regenerate README file + +on: + workflow_dispatch: + push: + branches: + - main + - master + paths-ignore: + - "features/**" + - "README.md" + +permissions: + contents: write + pull-requests: write + +jobs: + regenerate-readme: + uses: wp-cli/.github/.github/workflows/reusable-regenerate-readme.yml@main diff --git a/.github/workflows/welcome-new-contributors.yml b/.github/workflows/welcome-new-contributors.yml new file mode 100644 index 0000000..bc01490 --- /dev/null +++ b/.github/workflows/welcome-new-contributors.yml @@ -0,0 +1,15 @@ +name: Welcome New Contributors + +on: + pull_request_target: + types: [opened] + branches: + - main + - master + +permissions: + pull-requests: write + +jobs: + welcome: + uses: wp-cli/.github/.github/workflows/reusable-welcome-new-contributors.yml@main diff --git a/.gitignore b/.gitignore index 823aa74..11b884e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Exclude all subfolders... /*/ -# except for the _maintenance folder. +# except for the following. +!/.github/ !/.maintenance/ !/.readme-partials/ diff --git a/.maintenance/clone-all-repositories.php b/.maintenance/clone-all-repositories.php deleted file mode 100644 index ad74ea5..0000000 --- a/.maintenance/clone-all-repositories.php +++ /dev/null @@ -1,49 +0,0 @@ -message . "\n"; - echo "If you are running into a rate limiting issue during large events please set GITHUB_TOKEN environment variable.\n"; - exit( 1 ); -} - -$pwd = getcwd(); -$update_folders = []; - -foreach ( $repositories as $repository ) { - if ( in_array( $repository->name, $skip_list, true ) ) { - continue; - } - - if ( ! is_dir( $repository->name ) ) { - printf( "Fetching \033[32mwp-cli/{$repository->name}\033[0m...\n" ); - $clone_url = getenv( 'GITHUB_ACTION' ) ? $repository->clone_url : $repository->ssh_url; - system( "git clone {$clone_url}" ); - } - - $update_folders[] = $repository->name; -} - -$updates = implode( '\n', $update_folders ); -system( "echo '$updates' | xargs -n1 -P8 -I% php .maintenance/refresh-repository.php %" ); diff --git a/.maintenance/clone-all-repositories.sh b/.maintenance/clone-all-repositories.sh new file mode 100755 index 0000000..33bf6b7 --- /dev/null +++ b/.maintenance/clone-all-repositories.sh @@ -0,0 +1,110 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +if ! command -v jq &>/dev/null; then + echo "Required command 'jq' is not installed or not available in PATH." >&2 + exit 1 +fi + +SKIP_LIST=( + "autoload-splitter" + "composer-changelogs" + "dash-docset-generator" + "ideas" + "package-index" + "regenerate-readme" + "sample-plugin" + "wp-cli-dev" + "wp-cli-roadmap" +) + +# Detect number of CPU cores, defaulting to 4. +if command -v nproc &>/dev/null; then + DETECTED_CORES=$(nproc) +elif command -v sysctl &>/dev/null; then + DETECTED_CORES=$(sysctl -n hw.logicalcpu 2>/dev/null || echo 4) +else + DETECTED_CORES=4 +fi + +MAX_CORES=8 +CORES="${CLONE_JOBS:-${WPCLI_DEV_JOBS:-${DETECTED_CORES}}}" + +if ! [[ "${CORES}" =~ ^[1-9][0-9]*$ ]]; then + CORES=4 +elif [[ -z "${CLONE_JOBS:-}" && -z "${WPCLI_DEV_JOBS:-}" && "${CORES}" -gt "${MAX_CORES}" ]]; then + CORES=${MAX_CORES} +fi + +# Fetch repository list from the GitHub API. +CURL_OPTS=(-fsS) +if [[ -n "${GITHUB_TOKEN:-}" ]]; then + CURL_OPTS+=(--header "Authorization: Bearer ${GITHUB_TOKEN}") +fi + +if ! RESPONSE=$(curl "${CURL_OPTS[@]}" 'https://api.github.com/orgs/wp-cli/repos?per_page=100'); then + echo "Failed to fetch repository list from the GitHub API." >&2 + exit 1 +fi + +# Validate the response shape and detect API errors such as rate limiting. +if ! jq -e 'type == "array"' >/dev/null <<< "${RESPONSE}"; then + if jq -e '.message' >/dev/null <<< "${RESPONSE}"; then + MESSAGE=$(jq -r '.message' <<< "${RESPONSE}") + echo "GitHub responded with: ${MESSAGE}" >&2 + echo "If you are running into a rate limiting issue during large events please set GITHUB_TOKEN environment variable." >&2 + echo "See https://github.com/settings/tokens" >&2 + else + echo "GitHub API returned an unexpected response; expected a JSON array of repositories." >&2 + fi + exit 1 +fi + +is_skipped() { + local name="$1" + for skip in "${SKIP_LIST[@]}"; do + [[ "${skip}" == "${name}" ]] && return 0 + done + return 1 +} + +get_destination() { + local name="$1" + if [[ "${name}" == ".github" ]]; then + echo "dot-github" + else + echo "${name}" + fi +} + +CLONE_LIST=() +UPDATE_FOLDERS=() + +while IFS=$'\t' read -r name clone_url ssh_url; do + if is_skipped "${name}"; then + continue + fi + + destination=$(get_destination "${name}") + + if [[ ! -d "${destination}" ]]; then + if [[ -n "${GITHUB_ACTION:-}" ]]; then + CLONE_LIST+=("${destination}"$'\t'"${clone_url}") + else + CLONE_LIST+=("${destination}"$'\t'"${ssh_url}") + fi + fi + + UPDATE_FOLDERS+=("${destination}") +done < <(echo "${RESPONSE}" | jq -r '.[] | [.name, .clone_url, .ssh_url] | @tsv') + +if [[ ${#CLONE_LIST[@]} -gt 0 ]]; then + printf '%s\n' "${CLONE_LIST[@]}" | xargs -n2 -P"${CORES}" bash "${SCRIPT_DIR}/clone-repository.sh" +fi + +if [[ ${#UPDATE_FOLDERS[@]} -gt 0 ]]; then + printf '%s\n' "${UPDATE_FOLDERS[@]}" | xargs -P"${CORES}" -I% php "${SCRIPT_DIR}/refresh-repository.php" % +fi diff --git a/.maintenance/clone-repository.sh b/.maintenance/clone-repository.sh new file mode 100755 index 0000000..2b9567f --- /dev/null +++ b/.maintenance/clone-repository.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [[ $# -ne 2 ]]; then + echo "Usage: clone-repository.sh " >&2 + exit 1 +fi + +destination="$1" +clone_url="$2" + +printf "Fetching \033[32m%s\033[0m...\n" "${destination}" +git clone "${clone_url}" "${destination}" diff --git a/.maintenance/phpstorm.exclude-recursive-folders.php b/.maintenance/phpstorm.exclude-recursive-folders.php index 26e8ac3..1ef0441 100644 --- a/.maintenance/phpstorm.exclude-recursive-folders.php +++ b/.maintenance/phpstorm.exclude-recursive-folders.php @@ -55,11 +55,11 @@ protected static function has_project_iml() { if ( is_file( self::get_project_iml_path() ) ) { return; // already exists. } - $modules_xml_content = << - + diff --git a/.maintenance/refresh-repository.php b/.maintenance/refresh-repository.php index 5b0e5a9..fa3d2c1 100644 --- a/.maintenance/refresh-repository.php +++ b/.maintenance/refresh-repository.php @@ -10,7 +10,7 @@ printf( "--- Refreshing repository \033[32m{$repository}\033[0m ---\n" ); printf( "Switching to latest \033[33mdefault\033[0m branch...\n" ); -system( "git --git-dir={$path}/.git --work-tree={$path} checkout $(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)" ); +system( "git --git-dir={$path}/.git --work-tree={$path} checkout $(git --git-dir={$path}/.git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)" ); printf( "Pulling latest changes...\n" ); system( "git --git-dir={$path}/.git --work-tree={$path} pull" ); diff --git a/.maintenance/src/Contrib_List_Command.php b/.maintenance/src/Contrib_List_Command.php index f498b98..d62fb28 100644 --- a/.maintenance/src/Contrib_List_Command.php +++ b/.maintenance/src/Contrib_List_Command.php @@ -33,10 +33,12 @@ final class Contrib_List_Command { * @when before_wp_load */ public function __invoke( $args, $assoc_args ) { + $repos = null; + $use_bundle = false; - $repos = null; - $milestone_names = null; - $use_bundle = false; + $ignored_contributors = [ + 'github-actions[bot]', + ]; if ( count( $args ) > 0 ) { $repos = [ array_shift( $args ) ]; @@ -123,6 +125,9 @@ public function __invoke( $args, $assoc_args ) { $milestone = array_reduce( $milestones, function ( $tag, $milestone ) { + if ( ! $tag ) { + return $milestone->title; + } return version_compare( $milestone->title, $tag, '>' ) ? $milestone->title : $tag; } ); @@ -193,6 +198,8 @@ function ( $a, $b ) { } } + $contributors = array_diff( $contributors, $ignored_contributors ); + WP_CLI::log( 'Total contributors: ' . count( $contributors ) ); WP_CLI::log( 'Total pull requests: ' . $pull_request_count ); diff --git a/.maintenance/src/GitHub.php b/.maintenance/src/GitHub.php index 1fea60c..aaa879f 100644 --- a/.maintenance/src/GitHub.php +++ b/.maintenance/src/GitHub.php @@ -26,9 +26,28 @@ public static function get_project_milestones( $args['per_page'] = 100; - list( $body, $headers ) = self::request( $request_url, $args ); + $milestones = []; + do { + list( $body, $headers ) = self::request( $request_url, $args ); + foreach ( $body as $milestone ) { + $milestones[] = $milestone; + } + $args = array(); + $request_url = false; + // Set $request_url to 'rel="next" if present' + if ( ! empty( $headers['Link'] ) ) { + $bits = explode( ',', $headers['Link'] ); + foreach ( $bits as $bit ) { + if ( false !== stripos( $bit, 'rel="next"' ) ) { + $hrefandrel = explode( '; ', $bit ); + $request_url = trim( trim( $hrefandrel[0] ), '<>' ); + break; + } + } + } + } while ( $request_url ); - return $body; + return $milestones; } /** @@ -122,7 +141,13 @@ public static function get_release_by_tag( $args['per_page'] = 100; - list( $body, $headers ) = self::request( $request_url, $args ); + $result = self::request( $request_url, $args ); + + if ( ! $result ) { + return false; + } + + list( $body, $headers ) = $result; return $body; } @@ -283,14 +308,12 @@ public static function delete_label( * * @param string $project * @param integer $milestone_id - * @param bool $only_merged * * @return array */ public static function get_project_milestone_pull_requests( $project, - $milestone_id, - $only_merged = true + $milestone_id ) { $request_url = sprintf( self::API_ROOT . 'repos/%s/issues', diff --git a/.maintenance/src/Milestones_After_Command.php b/.maintenance/src/Milestones_After_Command.php index da640d0..df422c6 100644 --- a/.maintenance/src/Milestones_After_Command.php +++ b/.maintenance/src/Milestones_After_Command.php @@ -13,11 +13,11 @@ final class Milestones_After_Command { * : Name of the repository to fetch the milestones for. * * - * : Milestone to serve as treshold. + * : Milestone to serve as threshold. * * @when before_wp_load */ - public function __invoke( $args, $assoc_args ) { + public function __invoke( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed list( $repo, $milestone_name ) = $args; diff --git a/.maintenance/src/Milestones_Since_Command.php b/.maintenance/src/Milestones_Since_Command.php index cb4a2e0..beb3de6 100644 --- a/.maintenance/src/Milestones_Since_Command.php +++ b/.maintenance/src/Milestones_Since_Command.php @@ -7,7 +7,7 @@ final class Milestones_Since_Command { /** * Retrieves the milestones that were closed for a given repository after a - * specific date treshold. + * specific date threshold. * * ## OPTIONS * @@ -19,7 +19,7 @@ final class Milestones_Since_Command { * * @when before_wp_load */ - public function __invoke( $args, $assoc_args ) { + public function __invoke( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed list( $repo, $date ) = $args; diff --git a/.maintenance/src/Release_Date_Command.php b/.maintenance/src/Release_Date_Command.php index 5a5b156..543b412 100644 --- a/.maintenance/src/Release_Date_Command.php +++ b/.maintenance/src/Release_Date_Command.php @@ -18,7 +18,7 @@ final class Release_Date_Command { * * @when before_wp_load */ - public function __invoke( $args, $assoc_args ) { + public function __invoke( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed list( $repo, $milestone_name ) = $args; diff --git a/.maintenance/src/Release_Notes_Command.php b/.maintenance/src/Release_Notes_Command.php index cb27236..8565659 100644 --- a/.maintenance/src/Release_Notes_Command.php +++ b/.maintenance/src/Release_Notes_Command.php @@ -115,6 +115,9 @@ static function ( $latest, $milestone ) { $milestone = array_reduce( $milestones, function ( $tag, $milestone ) { + if ( ! $tag ) { + return $milestone->title; + } return version_compare( $milestone->title, $tag, '>' ) ? $milestone->title : $tag; } ); diff --git a/.readme-partials/DEVELOPMENT.md b/.readme-partials/DEVELOPMENT.md index e8d20ce..817d609 100644 --- a/.readme-partials/DEVELOPMENT.md +++ b/.readme-partials/DEVELOPMENT.md @@ -1,4 +1,10 @@ Every subfolder is a proper clone of the corresponding GitHub repository. This means that you can create new branches, make your changes, commit to the new branch and then submit as pull-request, all from within these folders. -As the folders are also symlinked into the Composer `vendor` folder, you will always have the latest changes available when running WP-CLI through the `vendor/bin/wp` executable. +Unless you have commit access to the repository, you'll need to fork the repository in order to push your feature branch. [GitHub's CLI](https://github.com/cli/cli) is pretty helpful for this: + +```bash +cd core-command +gh repo fork +``` +As the folders are also symlinked into the Composer `vendor` folder, you will always have the latest changes available when running WP-CLI through the `vendor/bin/wp` executable. diff --git a/.readme-partials/INSTALLATION.md b/.readme-partials/INSTALLATION.md index d66811a..b36d31c 100644 --- a/.readme-partials/INSTALLATION.md +++ b/.readme-partials/INSTALLATION.md @@ -1,13 +1,18 @@ -Clone this repository onto your hard drive and then use Composer to install all dependencies: +If you normally use WP-CLI on your web host or via Brew, you're most likely using the Phar executable (`wp-cli.phar`). This Phar executable file is the "built", singular version of WP-CLI. It is compiled from a couple dozen repositories in the WP-CLI GitHub organization. -``` -git clone https://github.com/wp-cli/wp-cli-dev -cd wp-cli-dev -composer install -``` - -This will: +In order to make code changes to WP-CLI, you'll need to set up this `wp-cli-dev` development environment on your local machine. The setup process will: 1. Clone all relevant packages from the `wp-cli` GitHub organization into the `wp-cli-dev` folder, and 2. Install all Composer dependencies for a complete `wp-cli-bundle` setup, while symlinking all of the previously cloned packages into the Composer `vendor` folder. 3. Symlink all folder in `vendor` into corresponding `vendor` folders in each repository, thus making the centralized functionality based on Composer available in each repository subfolder. + +Before you can proceed further, you'll need to make sure you have [Composer](https://getcomposer.org/), PHP, and a functioning MySQL or MariaDB server on your local machine. + +Once the prerequisites are met, clone the GitHub repository and run the installation process: + +```bash +git clone https://github.com/wp-cli/wp-cli-dev wp-cli-dev +cd wp-cli-dev +composer install +composer prepare-tests +``` diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000..46364c5 --- /dev/null +++ b/.typos.toml @@ -0,0 +1,23 @@ +[default] +extend-ignore-re = [ + "(?Rm)^.*(#|//)\\s*spellchecker:disable-line$", + "(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on", + "(#|//)\\s*spellchecker:ignore-next-line\\n.*" +] +[files] +extend-exclude = [ + "*-command/*", + ".git/*", + "builds/*", + "dashboard/*", + "handbook/*", + "mustache.php/*", + "process/*", + "restful/*", + "spyc/*", + "vendor/*", + "wordpress-core/*", + "wp-cli/*", + "wp-cli.github.com/*", + "wp-super-cache-cli/*" +] diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..1ff84f6 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,121 @@ +# Instructions + +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. + +## Best Practices for Code Contributions + +When contributing to this package, please adhere to the following guidelines: + +* **Follow Existing Conventions:** Before writing any code, analyze the existing codebase in this package to understand the coding style, naming conventions, and architectural patterns. +* **Focus on the Package's Scope:** All changes should be relevant to the functionality of the package. +* **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. +* **Update Documentation:** If your changes affect the user-facing functionality, please update the relevant inline code documentation. + +### Building and running + +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`. + +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. + +### Useful Composer Commands + +The project uses Composer to manage dependencies and run scripts. The following commands are available: + +* `composer install`: Install dependencies. +* `composer test`: Run the full test suite, including linting, code style checks, static analysis, and unit/behavior tests. +* `composer lint`: Check for syntax errors. +* `composer phpcs`: Check for code style violations. +* `composer phpcbf`: Automatically fix code style violations. +* `composer phpstan`: Run static analysis. +* `composer phpunit`: Run unit tests. +* `composer behat`: Run behavior-driven tests. + +### Coding Style + +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. + +## Documentation + +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. + +### Inline Documentation + +Only write high-value comments if at all. Avoid talking to the user through comments. + +## Testing + +The project has a comprehensive test suite that includes unit tests, behavior-driven tests, and static analysis. + +* **Unit tests** are written with PHPUnit and can be found in the `tests/` directory. The configuration is in `phpunit.xml.dist`. +* **Behavior-driven tests** are written with Behat and can be found in the `features/` directory. The configuration is in `behat.yml`. +* **Static analysis** is performed with PHPStan. + +All tests are run on GitHub Actions for every pull request. + +When writing tests, aim to follow existing patterns. Key conventions include: + +* When adding tests, first examine existing tests to understand and conform to established conventions. +* For unit tests, extend the base `WP_CLI\Tests\TestCase` test class. +* For Behat tests, only WP-CLI commands installed in `composer.json` can be run. + +### Behat Steps + +WP-CLI makes use of a Behat-based testing framework and provides a set of custom step definitions to write feature tests. + +> **Note:** If you are expecting an error output in a test, you need to use `When I try ...` instead of `When I run ...` . + +#### Given + +* `Given an empty directory` - Creates an empty directory. +* `Given /^an? (empty|non-existent) ([^\s]+) directory$/` - Creates or deletes a specific directory. +* `Given an empty cache` - Clears the WP-CLI cache directory. +* `Given /^an? ([^\s]+) (file|cache file):$/` - Creates a file with the given contents. +* `Given /^"([^"]+)" replaced with "([^"]+)" in the ([^\s]+) file$/` - Search and replace a string in a file using regex. +* `Given /^that HTTP requests to (.*?) will respond with:$/` - Mock HTTP requests to a given URL. +* `Given WP files` - Download WordPress files without installing. +* `Given wp-config.php` - Create a wp-config.php file using `wp config create`. +* `Given a database` - Creates an empty database. +* `Given a WP install(ation)` - Installs WordPress. +* `Given a WP install(ation) in :subdir` - Installs WordPress in a given directory. +* `Given a WP install(ation) with Composer` - Installs WordPress with Composer. +* `Given a WP install(ation) with Composer and a custom vendor directory :vendor_directory` - Installs WordPress with Composer and a custom vendor directory. +* `Given /^a WP multisite (subdirectory|subdomain)?\s?(install|installation)$/` - Installs WordPress Multisite. +* `Given these installed and active plugins:` - Installs and activates one or more plugins. +* `Given a custom wp-content directory` - Configure a custom `wp-content` directory. +* `Given download:` - Download multiple files into the given destinations. +* `Given /^save (STDOUT|STDERR) ([\'].+[^\'])?\s?as \{(\w+)\}$/` - Store STDOUT or STDERR contents in a variable. +* `Given /^a new Phar with (?:the same version|version "([^"]+)")$/` - Build a new WP-CLI Phar file with a given version. +* `Given /^a downloaded Phar with (?:the same version|version "([^"]+)")$/` - Download a specific WP-CLI Phar version from GitHub. +* `Given /^save the (.+) file ([\'].+[^\'])? as \{(\w+)\}$/` - Stores the contents of the given file in a variable. +* `Given a misconfigured WP_CONTENT_DIR constant directory` - Modify wp-config.php to set `WP_CONTENT_DIR` to an empty string. +* `Given a dependency on current wp-cli` - Add `wp-cli/wp-cli` as a Composer dependency. +* `Given a PHP built-in web server` - Start a PHP built-in web server in the current directory. +* `Given a PHP built-in web server to serve :subdir` - Start a PHP built-in web server in the given subdirectory. + +#### When + +* ``When /^I launch in the background `([^`]+)`$/`` - Launch a given command in the background. +* ``When /^I (run|try) `([^`]+)`$/`` - Run or try a given command. +* ``When /^I (run|try) `([^`]+)` from '([^\s]+)'$/`` - Run or try a given command in a subdirectory. +* `When /^I (run|try) the previous command again$/` - Run or try the previous command again. + +#### Then + +* `Then /^the return code should( not)? be (\d+)$/` - Expect a specific exit code of the previous command. +* `Then /^(STDOUT|STDERR) should( strictly)? (be|contain|not contain):$/` - Check the contents of STDOUT or STDERR. +* `Then /^(STDOUT|STDERR) should be a number$/` - Expect STDOUT or STDERR to be a numeric value. +* `Then /^(STDOUT|STDERR) should not be a number$/` - Expect STDOUT or STDERR to not be a numeric value. +* `Then /^STDOUT should be a table containing rows:$/` - Expect STDOUT to be a table containing the given rows. +* `Then /^STDOUT should end with a table containing rows:$/` - Expect STDOUT to end with a table containing the given rows. +* `Then /^STDOUT should be JSON containing:$/` - Expect valid JSON output in STDOUT. +* `Then /^STDOUT should be a JSON array containing:$/` - Expect valid JSON array output in STDOUT. +* `Then /^STDOUT should be CSV containing:$/` - Expect STDOUT to be CSV containing certain values. +* `Then /^STDOUT should be YAML containing:$/` - Expect STDOUT to be YAML containing certain content. +* `Then /^(STDOUT|STDERR) should be empty$/` - Expect STDOUT or STDERR to be empty. +* `Then /^(STDOUT|STDERR) should not be empty$/` - Expect STDOUT or STDERR not to be empty. +* `Then /^(STDOUT|STDERR) should be a version string (<|<=|>|>=|==|=|<>) ([+\w.{}-]+)$/` - Expect STDOUT or STDERR to be a version string comparing to the given version. +* `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. +* `Then /^the contents of the (.+) file should( not)? match (((\/.*\/)|(#.#))([a-z]+)?)$/` - Match file contents against a regex. +* `Then /^(STDOUT|STDERR) should( not)? match (((\/.*\/)|(#.#))([a-z]+)?)$/` - Match STDOUT or STDERR against a regex. +* `Then /^an email should (be sent|not be sent)$/` - Expect an email to be sent (or not). +* `Then the HTTP status code should be :code` - Expect the HTTP status code for visiting `http://localhost:8080`. diff --git a/README.md b/README.md index 47da595..1e88366 100644 --- a/README.md +++ b/README.md @@ -11,24 +11,36 @@ Quick links: [Installation](#installation) | [Development](#development) | [Usin ## Installation -Clone this repository onto your hard drive and then use Composer to install all dependencies: +If you normally use WP-CLI on your web host or via Brew, you're most likely using the Phar executable (`wp-cli.phar`). This Phar executable file is the "built", singular version of WP-CLI. It is compiled from a couple dozen repositories in the WP-CLI GitHub organization. -``` -git clone https://github.com/wp-cli/wp-cli-dev -cd wp-cli-dev -composer install -``` - -This will: +In order to make code changes to WP-CLI, you'll need to set up this `wp-cli-dev` development environment on your local machine. The setup process will: 1. Clone all relevant packages from the `wp-cli` GitHub organization into the `wp-cli-dev` folder, and 2. Install all Composer dependencies for a complete `wp-cli-bundle` setup, while symlinking all of the previously cloned packages into the Composer `vendor` folder. 3. Symlink all folder in `vendor` into corresponding `vendor` folders in each repository, thus making the centralized functionality based on Composer available in each repository subfolder. +Before you can proceed further, you'll need to make sure you have [Composer](https://getcomposer.org/), PHP, and a functioning MySQL or MariaDB server on your local machine. + +Once the prerequisites are met, clone the GitHub repository and run the installation process: + +```bash +git clone https://github.com/wp-cli/wp-cli-dev wp-cli-dev +cd wp-cli-dev +composer install +composer prepare-tests +``` + ## Development Every subfolder is a proper clone of the corresponding GitHub repository. This means that you can create new branches, make your changes, commit to the new branch and then submit as pull-request, all from within these folders. +Unless you have commit access to the repository, you'll need to fork the repository in order to push your feature branch. [GitHub's CLI](https://github.com/cli/cli) is pretty helpful for this: + +```bash +cd core-command +gh repo fork +``` + As the folders are also symlinked into the Composer `vendor` folder, you will always have the latest changes available when running WP-CLI through the `vendor/bin/wp` executable. ## Using @@ -52,13 +64,22 @@ wp maintenance Lists all contributors to this release. ~~~ -wp maintenance contrib-list [--format=] +wp maintenance contrib-list [] [...] [--format=] ~~~ Run within the main WP-CLI project repository. **OPTIONS** + [] + Name of the repository to fetch the release notes for. If no user/org + was provided, 'wp-cli' org is assumed. If no repo is passed, release + notes for the entire org state since the last bundle release are fetched. + + [...] + Name of one or more milestones to fetch the release notes for. If none + are passed, the current open one is assumed. + [--format=] Render output in a specific format. --- @@ -84,7 +105,7 @@ wp maintenance milestones-after Name of the repository to fetch the milestones for. - Milestone to serve as treshold. + Milestone to serve as threshold. @@ -96,7 +117,7 @@ Retrieves the milestones that were closed for a given repository after a wp maintenance milestones-since ~~~ -specific date treshold. +specific date threshold. **OPTIONS** @@ -144,7 +165,7 @@ wp maintenance release-notes [] [...] [--source=] [--fo [...] Name of one or more milestones to fetch the release notes for. If none - are passed, the currently open one is assumed. + are passed, the current open one is assumed. [--source=] Choose source from where to copy content. @@ -195,7 +216,7 @@ We appreciate you taking the initiative to contribute to this project. Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation. -For a more thorough introduction, [check out WP-CLI's guide to contributing](https://make.wordpress.org/cli/handbook/contributing/). This package follows those policies and guidelines. +For a more thorough introduction, [check out WP-CLI's guide to contributing](https://make.wordpress.org/cli/handbook/contributing/). This package follows those policy and guidelines. ### Reporting a bug @@ -211,8 +232,12 @@ Want to contribute a new feature? Please first [open a new issue](https://github Once you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request](https://make.wordpress.org/cli/handbook/pull-requests/) to make sure it's a pleasant experience. See "[Setting up](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up)" for details specific to working on this package locally. +### License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. + ## Support -Github issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support +GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support diff --git a/composer.json b/composer.json index 5e6784c..7ecf94e 100644 --- a/composer.json +++ b/composer.json @@ -180,6 +180,18 @@ "type": "path", "url": "i18n-command" }, + { + "type": "path", + "url": "ability-command" + }, + { + "type": "path", + "url": "ai-command" + }, + { + "type": "path", + "url": "block-command" + }, { "type": "path", "url": "wp-cli-tests" @@ -194,11 +206,16 @@ } ], "require": { - "php": ">=5.6.20", - "ext-json": "*", + "php": ">=7.2.24", "ext-dom": "*", + "ext-json": "*", + "johnpbloch/wordpress-core": "dev-master", + "johnpbloch/wordpress-core-installer": "^1.0 || ^2.0", + "wp-cli/ability-command": "^1.0@dev", + "wp-cli/ai-command": "^1.0@dev", "wp-cli/admin-command": "dev-main", "wp-cli/automated-tests": "dev-main", + "wp-cli/block-command": "^1.0@dev", "wp-cli/cache-command": "dev-main", "wp-cli/checksum-command": "dev-main", "wp-cli/config-command": "dev-main", @@ -221,7 +238,7 @@ "wp-cli/media-command": "dev-main", "wp-cli/mustangostang-spyc": "dev-master as 0.6.x-dev", "wp-cli/package-command": "dev-main", - "wp-cli/php-cli-tools": "dev-master as 0.11.x-dev", + "wp-cli/php-cli-tools": "dev-main as 0.12.x-dev", "wp-cli/profile-command": "dev-main", "wp-cli/restful": "dev-main", "wp-cli/rewrite-command": "dev-main", @@ -237,9 +254,7 @@ "wp-cli/wp-cli-bundle": "dev-main", "wp-cli/wp-cli-tests": "dev-main", "wp-cli/wp-config-transformer": "dev-main as 1.2.x-dev", - "wp-cli/wp-super-cache-cli": "dev-main", - "johnpbloch/wordpress-core-installer": "^1.0 || ^2.0", - "johnpbloch/wordpress-core": "dev-master" + "wp-cli/wp-super-cache-cli": "dev-main" }, "require-dev": { "roave/security-advisories": "dev-latest" @@ -249,15 +264,19 @@ }, "config": { "process-timeout": 7200, + "preferred-install": { + "wp-cli/*": "source" + }, "sort-packages": true, "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, "johnpbloch/wordpress-core-installer": true, - "dealerdirect/phpcodesniffer-composer-installer": true + "phpstan/extension-installer": true } }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-main": "2.0.x-dev" }, "commands": [ "maintenance", @@ -300,8 +319,8 @@ "minimum-stability": "dev", "prefer-stable": true, "scripts": { - "pre-install-cmd": "php .maintenance/clone-all-repositories.php", - "pre-update-cmd": "php .maintenance/clone-all-repositories.php", + "pre-install-cmd": "bash .maintenance/clone-all-repositories.sh", + "pre-update-cmd": "bash .maintenance/clone-all-repositories.sh", "post-install-cmd": [ "php .maintenance/symlink-vendor-folders.php", "php .maintenance/phpstorm.exclude-recursive-folders.php" @@ -314,11 +333,13 @@ "behat-rerun": "rerun-behat-tests", "lint": "run-linter-tests", "phpcs": "run-phpcs-tests", + "phpstan": "run-phpstan-tests", "phpunit": "run-php-unit-tests", "prepare-tests": "install-package-tests", "test": [ "@lint", "@phpcs", + "@phpstan", "@phpunit", "@behat" ] diff --git a/foreach-bundle b/foreach-bundle index 4c6d86a..8396bf4 100755 --- a/foreach-bundle +++ b/foreach-bundle @@ -6,7 +6,7 @@ get_bundle_dependencies() { echo "wp-cli/wp-cli-bundle" - curl --silent "https://raw.githubusercontent.com/wp-cli/wp-cli-bundle/master/composer.json" \ + curl --silent "https://raw.githubusercontent.com/wp-cli/wp-cli-bundle/main/composer.json" \ | jq --raw-output '."require" | keys[] | select(startswith("wp-cli/"))' } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 142a306..9edfc31 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -38,7 +38,7 @@ - +