Skip to content

Honor WP_CLI_PHP and WP_CLI_PHP_ARGS in the Debian and RPM packages - #1079

Merged
schlessera merged 2 commits into
mainfrom
honor-wp-cli-php-in-packages
Jul 21, 2026
Merged

Honor WP_CLI_PHP and WP_CLI_PHP_ARGS in the Debian and RPM packages#1079
schlessera merged 2 commits into
mainfrom
honor-wp-cli-php-in-packages

Conversation

@schlessera

@schlessera schlessera commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary

The Debian and RPM packages install the Phar directly as /usr/bin/wp, so it launches through its own #!/usr/bin/env php shebang and always runs under whatever php is first on PATH. WP_CLI_PHP and WP_CLI_PHP_ARGS are only ever read by the bin/wp shell wrapper, which is not part of a Phar install, so a packaged wp-cli has never been able to select its PHP interpreter. This was reported downstream in wp-cli/wp-cli#5886, where it looked like a regression from wp-cli/wp-cli#5672; it is not. #5672 only made wp cli info report the interpreter that is genuinely running. The variable was ignored on packaged installs before and after that change.

What this does

  • Installs the Phar to /usr/share/wp-cli/wp-cli.phar.

  • Ships a small POSIX-sh launcher at /usr/bin/wp that:

    • selects the interpreter from WP_CLI_PHP, falling back to the php on PATH,
    • exports WP_CLI_PHP_USED,
    • passes WP_CLI_PHP_ARGS through before the Phar.

    This is the same logic as wp-cli's bin/wp. The launcher is generated inline (heredoc) in both build scripts because the deployment workflow downloads each script standalone, without a repo checkout.

  • Fixes the php.ini used mismatch from the report for free: the chosen interpreter loads its own configuration.

Compatibility

  • wp cli update keeps working. It resolves the Phar through argv[0], which via the launcher is /usr/share/wp-cli/wp-cli.phar, so it rewrites the Phar and leaves the launcher intact. On a root-owned install it errors "not writable" for non-root, same as today.
  • Upgrades are clean: /usr/bin/wp goes from a package-owned regular file (the Phar) to a package-owned regular file (the launcher), no file-type conflict.
  • The RPM now owns /usr/share/wp-cli (%dir) so it is removed on uninstall.

Testing

  • Launcher logic verified locally: default falls back to PATH php; WP_CLI_PHP selects the interpreter; WP_CLI_PHP_ARGS word-splits into multiple args placed before the Phar; WP_CLI_PHP_USED is exported; trailing user args are preserved.
  • Both build scripts pass bash -n; the launcher passes dash -n and ShellCheck (the single unquoted $WP_CLI_PHP_ARGS is intentional, matching bin/wp, and is annotated).
  • The deployment Verify steps now assert the package layout and, for the .deb, install it and prove the launcher actually honors WP_CLI_PHP (a deliberately broken WP_CLI_PHP=/bin/false must fail the run).

Notes for reviewers

  • The .deb behavioral smoke test does sudo dpkg -i and relies on php being present on the runner; it falls back to apt-get install -f -y for the declared dependencies. Worth confirming that stays reliable on ubuntu-latest.
  • The Phar is installed 0755 (it retains a shebang, so a non-executable mode trips script-not-executable / non-executable-script linters); it remains directly runnable, but the supported entry point is the launcher.

Fixes #1078
Refs wp-cli/wp-cli#5886

Summary by CodeRabbit

  • New Features

    • RPM and DEB packages now include a standard wp launcher and bundled WP-CLI Phar in their expected system locations.
    • Package launchers support selecting a custom PHP interpreter through WP_CLI_PHP.
    • WP_CLI_PHP_ARGS is now forwarded, and the selected interpreter is exposed through WP_CLI_PHP_USED.
  • Bug Fixes

    • Improved package handling of custom PHP configurations.
    • Added safeguards to detect incorrectly packaged or non-functional launchers.

The Debian and RPM packages shipped the Phar directly as /usr/bin/wp, so it
launched through its `#!/usr/bin/env php` shebang and never consulted
WP_CLI_PHP or WP_CLI_PHP_ARGS. Those variables are only read by the bin/wp
shell wrapper, which is not part of a Phar install, so a packaged wp-cli has
never been able to select its PHP interpreter. Reported in wp-cli/wp-cli#5886.

Install the Phar to /usr/share/wp-cli/wp-cli.phar and ship a small POSIX-sh
launcher at /usr/bin/wp that selects the interpreter from WP_CLI_PHP (falling
back to the php on PATH), exports WP_CLI_PHP_USED, and passes WP_CLI_PHP_ARGS
through, mirroring the semantics of wp-cli's bin/wp. The launcher is generated
inline because the deployment workflow downloads the build scripts standalone.

`wp cli update` keeps working: it resolves the Phar via argv[0], so it rewrites
/usr/share/wp-cli/wp-cli.phar and leaves the launcher untouched.

Also replace the ls-only package verification steps with smoke tests that
assert the package layout and that the launcher actually honors WP_CLI_PHP.

Fixes #1078
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0f3b5df1-570b-4ca2-a872-ac80ce012d13

📥 Commits

Reviewing files that changed from the base of the PR and between 83d3dc3 and d81e91e.

📒 Files selected for processing (1)
  • .github/workflows/deployment.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/deployment.yml

📝 Walkthrough

Walkthrough

Debian and RPM packages now install a shell launcher at /usr/bin/wp and the Phar at /usr/share/wp-cli/wp-cli.phar. The launchers honor PHP interpreter and argument overrides, while deployment workflows verify package contents and runtime behavior.

Changes

Package launcher and packaging

Layer / File(s) Summary
Debian launcher packaging
utils/wp-cli-updatedeb.sh
The Debian package stages the Phar in /usr/share/wp-cli, generates a /usr/bin/wp launcher, and uses the staged Phar for version and manpage generation.
RPM launcher and layout
utils/wp-cli-updaterpm.sh, utils/wp-cli-rpm.spec
The RPM build generates the launcher, installs the Phar and launcher at their separate paths, updates release metadata, and rewrites placeholder changelog versions.
Built package verification
.github/workflows/deployment.yml
RPM and DEB verification checks package contents, launcher scripts, Phar installation, PHP argument forwarding, and interpreter selection behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Launcher as /usr/bin/wp
  participant PHP
  participant Phar as /usr/share/wp-cli/wp-cli.phar
  User->>Launcher: Invoke wp with environment variables and CLI arguments
  Launcher->>PHP: Select WP_CLI_PHP and forward WP_CLI_PHP_ARGS
  PHP->>Phar: Execute bundled Phar
  Phar-->>User: Return command output
Loading

Possibly related issues

  • Issue 5886: The package launchers now honor WP_CLI_PHP and WP_CLI_PHP_ARGS as described.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: Debian/RPM packages now honor WP_CLI_PHP and WP_CLI_PHP_ARGS.
Linked Issues check ✅ Passed The launcher, package layout, and tests implement the requirements in #1078 for both Debian and RPM.
Out of Scope Changes check ✅ Passed The changes stay focused on packaging, launcher behavior, and verification; no unrelated code paths stand out.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch honor-wp-cli-php-in-packages

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
.github/workflows/deployment.yml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


Comment @coderabbitai help to get the list of available commands.

@schlessera schlessera added the scope:distribution Related to distribution label Jul 21, 2026
@schlessera schlessera added this to the 3.0.0 milestone Jul 21, 2026
@github-actions github-actions Bot added enhancement New feature or request scope:framework labels Jul 21, 2026
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@schlessera
schlessera marked this pull request as ready for review July 21, 2026 10:41
@schlessera
schlessera requested a review from a team as a code owner July 21, 2026 10:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/workflows/deployment.yml (1)

378-385: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Prove PHP arguments reach the selected interpreter.

The DEB command succeeds even if WP_CLI_PHP_ARGS is dropped, while the RPM check only greps text. Use a temporary PHP probe that asserts WP_CLI_PHP_USED, -d, and memory_limit=256M before delegating to real PHP.

  • .github/workflows/deployment.yml#L378-L385: run the installed DEB launcher through the probe instead of the normal PHP binary.
  • .github/workflows/deployment.yml#L302-L311: install the RPM in the isolated runner, then run the same probe against /usr/bin/wp.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/deployment.yml around lines 378 - 385, Update the DEB
check at .github/workflows/deployment.yml lines 378-385 and the RPM check at
lines 302-311 to create and use the same temporary PHP probe. Configure the
probe to assert WP_CLI_PHP_USED, -d, and memory_limit=256M, then delegate to the
real PHP interpreter; run the installed DEB launcher through it and install the
RPM in the isolated runner before invoking /usr/bin/wp through it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In @.github/workflows/deployment.yml:
- Around line 378-385: Update the DEB check at .github/workflows/deployment.yml
lines 378-385 and the RPM check at lines 302-311 to create and use the same
temporary PHP probe. Configure the probe to assert WP_CLI_PHP_USED, -d, and
memory_limit=256M, then delegate to the real PHP interpreter; run the installed
DEB launcher through it and install the RPM in the isolated runner before
invoking /usr/bin/wp through it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 481273f8-da96-41a8-b91d-602a7406b85d

📥 Commits

Reviewing files that changed from the base of the PR and between 4b00784 and 83d3dc3.

📒 Files selected for processing (4)
  • .github/workflows/deployment.yml
  • utils/wp-cli-rpm.spec
  • utils/wp-cli-updatedeb.sh
  • utils/wp-cli-updaterpm.sh

The DEB check passed even when the launcher silently dropped WP_CLI_PHP_ARGS,
because `wp cli version` prints the same output either way, and the RPM check
only grepped the launcher text. Replace both with a probe that stands in for
PHP and asserts it received `-d memory_limit=256M` and inherited
WP_CLI_PHP_USED before delegating, run through the installed DEB launcher and
the extracted RPM launcher.
@schlessera
schlessera merged commit 020de7a into main Jul 21, 2026
64 checks passed
@schlessera
schlessera deleted the honor-wp-cli-php-in-packages branch July 21, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request scope:distribution Related to distribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debian/RPM package launcher should honor WP_CLI_PHP and WP_CLI_PHP_ARGS

1 participant