Skip to content

Commit 82da1af

Browse files
swissspidyclaude
andcommitted
Merge branch 'main' into feature/composer-phar-backend
Drop the touch() workaround from main: it guarded Composer's JsonFile atomic write, which this branch replaced with file_put_contents(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pLgrx5zJn6U8rsynH
2 parents b6e49ab + 17f799f commit 82da1af

8 files changed

Lines changed: 188 additions & 34 deletions

File tree

‎.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: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,40 +39,44 @@ jobs:
3939
id: check_composer_file
4040
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
4141

42-
- name: Set up PHP environment
43-
if: steps.check_composer_file.outputs.files_exists == 'true'
44-
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
45-
with:
46-
php-version: 'latest'
47-
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
48-
coverage: 'none'
49-
tools: composer,cs2pr
50-
env:
51-
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52-
53-
- name: Install Composer dependencies & cache dependencies
54-
if: steps.check_composer_file.outputs.files_exists == 'true'
55-
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
56-
env:
57-
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
58-
5942
# Without a database the Behat runner silently falls back to SQLite, so the
6043
# agent's test runs are not the ones CI will do. Mirrors the setup in
6144
# reusable-functional.yml.
6245
- name: Check existence of behat.yml file
6346
id: check_behat_file
6447
run: echo "files_exists=$(test -f behat.yml && echo true || echo false)" >> "$GITHUB_OUTPUT"
6548

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.
6653
- name: Setup MySQL Server
6754
if: steps.check_behat_file.outputs.files_exists == 'true'
68-
uses: shogo82148/actions-setup-mysql@62da9377d83991fce27b6ed2a397d3306121e41d # v1
55+
uses: shogo82148/actions-setup-mysql@13a38f2af408e58a0c80168fc620a63a15357339 # v1
6956
with:
7057
mysql-version: '8.0' # Standard MySQL version for these tests
7158
auto-start: true
7259
root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }}
7360
user: ${{ env.WP_CLI_TEST_DBUSER }}
7461
password: ${{ env.WP_CLI_TEST_DBPASS }}
7562

63+
- name: Set up PHP environment
64+
if: steps.check_composer_file.outputs.files_exists == 'true'
65+
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
66+
with:
67+
php-version: 'latest'
68+
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
69+
coverage: 'none'
70+
tools: composer,cs2pr
71+
env:
72+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Install Composer dependencies & cache dependencies
75+
if: steps.check_composer_file.outputs.files_exists == 'true'
76+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
77+
env:
78+
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
79+
7680
- name: Remove system MySQL binary
7781
if: steps.check_behat_file.outputs.files_exists == 'true'
7882
run: sudo rm -f /usr/bin/mysql /usr/bin/mysqldump
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: 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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,17 @@ wp package install <name|git|path|zip> [--insecure] [--interaction]
200200
Packages are required to be a valid Composer package, and can be
201201
specified as:
202202

203-
* Package name from WP-CLI's package index.
203+
* Package name, such as `wp-cli/server-command`.
204204
* Git URL accessible by the current shell user.
205205
* Path to a directory on the local machine.
206206
* Local or remote .zip file.
207207

208+
A package name is looked up in WP-CLI's package index, which is deprecated,
209+
and then on Packagist. If neither has it, WP-CLI tries
210+
`https://github.com/<package-name>.git` and then
211+
`https://gitlab.com/<package-name>.git`. Set the `GITHUB_TOKEN` or
212+
`GITLAB_TOKEN` environment variable to avoid rate limiting on that check.
213+
208214
Packages are installed to `~/.wp-cli/packages/` by default. Use the
209215
`WP_CLI_PACKAGES_DIR` environment variable to provide a custom path.
210216

‎features/package-install.feature‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,114 @@ Feature: Install WP-CLI packages
10171017
wp-cli/google-sitemap-generator-cli
10181018
"""
10191019
1020+
Scenario: Install a package from a remote zip URL
1021+
Given an empty directory
1022+
And a remote-zip-test-command/composer.json file:
1023+
"""
1024+
{
1025+
"name": "wp-cli-test/remote-zip-test-command",
1026+
"description": "Dummy package served over HTTP as a ZIP archive for acceptance tests.",
1027+
"type": "wp-cli-package"
1028+
}
1029+
"""
1030+
And a create-zip.php file:
1031+
"""
1032+
<?php
1033+
$zip = new ZipArchive();
1034+
$zip->open( 'remote-zip-test-command.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE );
1035+
$zip->addFromString( 'remote-zip-test-command/composer.json', file_get_contents( 'remote-zip-test-command/composer.json' ) );
1036+
$zip->close();
1037+
"""
1038+
And I run `php create-zip.php`
1039+
And a PHP built-in web server
1040+
1041+
When I run `wp package install http://localhost:8080/remote-zip-test-command.zip`
1042+
Then STDOUT should contain:
1043+
"""
1044+
Installing package wp-cli-test/remote-zip-test-command
1045+
"""
1046+
And STDOUT should contain:
1047+
"""
1048+
Success: Package installed.
1049+
"""
1050+
1051+
When I run `wp package is-installed wp-cli-test/remote-zip-test-command`
1052+
Then the return code should be 0
1053+
And STDERR should be empty
1054+
And STDOUT should be empty
1055+
1056+
Scenario: Install a package from a remote zip URL with files at archive root
1057+
Given an empty directory
1058+
And a composer-flat.json file:
1059+
"""
1060+
{
1061+
"name": "wp-cli-test/remote-zip-flat-command",
1062+
"description": "Dummy flat-layout ZIP package for acceptance tests.",
1063+
"type": "wp-cli-package"
1064+
}
1065+
"""
1066+
And a create-zip.php file:
1067+
"""
1068+
<?php
1069+
$zip = new ZipArchive();
1070+
$zip->open( 'remote-zip-flat-command.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE );
1071+
$zip->addFromString( 'composer.json', file_get_contents( 'composer-flat.json' ) );
1072+
$zip->close();
1073+
"""
1074+
And I run `php create-zip.php`
1075+
And a PHP built-in web server
1076+
1077+
When I run `wp package install http://localhost:8080/remote-zip-flat-command.zip`
1078+
Then STDOUT should contain:
1079+
"""
1080+
Installing package wp-cli-test/remote-zip-flat-command
1081+
"""
1082+
And STDOUT should contain:
1083+
"""
1084+
Success: Package installed.
1085+
"""
1086+
1087+
When I run `wp package is-installed wp-cli-test/remote-zip-flat-command`
1088+
Then the return code should be 0
1089+
And STDERR should be empty
1090+
And STDOUT should be empty
1091+
1092+
Scenario: Install from a remote zip URL with invalid zip contents
1093+
Given an empty directory
1094+
And an invalid.zip file:
1095+
"""
1096+
this is not a zip archive
1097+
"""
1098+
And a PHP built-in web server
1099+
1100+
When I try `wp package install http://localhost:8080/invalid.zip`
1101+
Then the return code should be 1
1102+
And STDERR should contain:
1103+
"""
1104+
ZipArchive failed to unzip
1105+
"""
1106+
1107+
Scenario: Install from a remote zip URL that returns 404
1108+
Given an empty directory
1109+
And a PHP built-in web server
1110+
1111+
When I try `wp package install http://localhost:8080/missing.zip`
1112+
Then the return code should be 1
1113+
And STDERR should contain:
1114+
"""
1115+
Couldn't download package from 'http://localhost:8080/missing.zip' (HTTP code 404).
1116+
"""
1117+
1118+
Scenario: Install from a remote zip URL that cannot be reached
1119+
Given an empty directory
1120+
1121+
When I try `wp package install http://localhost:1/unreachable.zip`
1122+
Then the return code should be 1
1123+
And STDERR should contain:
1124+
"""
1125+
Error: Failed to get url 'http://localhost:1/unreachable.zip'
1126+
"""
1127+
10201128
@github-api
10211129
Scenario: Install a package from Git using a shortened mixed-case package identifier but lowercase composer.json name
10221130
Given an empty directory

‎src/Package_Command.php‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,17 @@ public function browse( $_, $assoc_args ) {
156156
* Packages are required to be a valid Composer package, and can be
157157
* specified as:
158158
*
159-
* * Package name from WP-CLI's package index.
159+
* * Package name, such as `wp-cli/server-command`.
160160
* * Git URL accessible by the current shell user.
161161
* * Path to a directory on the local machine.
162162
* * Local or remote .zip file.
163163
*
164+
* A package name is looked up in WP-CLI's package index, which is deprecated,
165+
* and then on Packagist. If neither has it, WP-CLI tries
166+
* `https://github.com/<package-name>.git` and then
167+
* `https://gitlab.com/<package-name>.git`. Set the `GITHUB_TOKEN` or
168+
* `GITLAB_TOKEN` environment variable to avoid rate limiting on that check.
169+
*
164170
* Packages are installed to `~/.wp-cli/packages/` by default. Use the
165171
* `WP_CLI_PACKAGES_DIR` environment variable to provide a custom path.
166172
*
@@ -263,22 +269,28 @@ public function install( $args, $assoc_args ) {
263269
// Download the remote ZIP file to a temp directory
264270
$temp = false;
265271
if ( false !== strpos( $package_name, '://' ) ) {
266-
$temp = Utils\get_temp_dir() . uniqid( 'wp-cli-package_', true /*more_entropy*/ ) . '.zip';
272+
$temp = Utils\make_temp_file( 'wp-cli-package_', '.zip' );
267273
$options = [
268-
'timeout' => 600,
269-
'filename' => $temp,
270-
'insecure' => $insecure,
274+
'timeout' => 600,
275+
'filename' => $temp,
276+
'insecure' => $insecure,
277+
'halt_on_error' => false, // Handle failures here so the temp file is cleaned up.
271278
];
272279
$gitlab_token = getenv( 'GITLAB_TOKEN' ); // Use GITLAB_TOKEN if available to avoid authorization failures or rate-limiting.
273280
$headers = $gitlab_token && 'gitlab.com' === strtolower( (string) Utils\parse_url( $package_name, PHP_URL_HOST ) ) ? [ 'PRIVATE-TOKEN' => $gitlab_token ] : [];
274-
$response = Utils\http_request( 'GET', $package_name, null, $headers, $options );
281+
try {
282+
$response = Utils\http_request( 'GET', $package_name, null, $headers, $options );
283+
} catch ( Exception $e ) {
284+
@unlink( $temp ); // @codingStandardsIgnoreLine
285+
WP_CLI::error( $e->getMessage() );
286+
}
275287
if ( 20 !== (int) substr( (string) $response->status_code, 0, 2 ) ) {
276288
@unlink( $temp ); // @codingStandardsIgnoreLine
277289
WP_CLI::error( sprintf( "Couldn't download package from '%s' (HTTP code %d).", $package_name, $response->status_code ) );
278290
}
279291
$package_name = $temp;
280292
}
281-
$dir_package = Utils\get_temp_dir() . uniqid( 'wp-cli-package_', true /*more_entropy*/ );
293+
$dir_package = Utils\make_temp_dir( 'wp-cli-package_' );
282294
try {
283295
// Extract the package to get the package name
284296
Extractor::extract( $package_name, $dir_package );
@@ -1539,12 +1551,6 @@ private function register_revert_shutdown_function( $json_path, $composer_backup
15391551
$revert_fail_msg = "Failed to revert composer.json.\n";
15401552
$memory_msg = "WP-CLI ran out of memory. Please see https://bit.ly/wpclimem for further help.\n";
15411553
$memory_string = 'Allowed memory size of';
1542-
$error_array = [
1543-
'type' => 42,
1544-
'message' => 'Some random dummy string to take up memory',
1545-
'file' => 'Another random string, which would be a filename this time',
1546-
'line' => 314,
1547-
];
15481554

15491555
register_shutdown_function(
15501556
static function () use (
@@ -1554,8 +1560,7 @@ static function () use (
15541560
$revert_msg,
15551561
$revert_fail_msg,
15561562
$memory_msg,
1557-
$memory_string,
1558-
$error_array
1563+
$memory_string
15591564
) {
15601565
if ( $revert ) {
15611566
if ( false !== file_put_contents( $json_path, $composer_backup ) ) {

0 commit comments

Comments
 (0)