Skip to content

Commit 83d3dc3

Browse files
committed
Honor WP_CLI_PHP and WP_CLI_PHP_ARGS in the Debian and RPM packages
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
1 parent 4b00784 commit 83d3dc3

4 files changed

Lines changed: 114 additions & 12 deletions

File tree

‎.github/workflows/deployment.yml‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,22 @@ jobs:
293293
294294
- name: Verify built RPM package contents
295295
run: |
296-
ls rpm-src/noarch
296+
set -euxo pipefail
297+
rpm_file="$(ls rpm-src/noarch/wp-cli-*.noarch.rpm)"
298+
# The package must ship a launcher in the bin dir and the Phar in the data dir.
299+
rpm -qlp "$rpm_file" | tee /tmp/rpm-files.txt
300+
grep -qx '/usr/bin/wp' /tmp/rpm-files.txt
301+
grep -qx '/usr/share/wp-cli/wp-cli.phar' /tmp/rpm-files.txt
302+
# /usr/bin/wp must be the shell launcher that honors WP_CLI_PHP / WP_CLI_PHP_ARGS,
303+
# not the Phar itself.
304+
mkdir -p rpm-verify
305+
( cd rpm-verify && rpm2cpio "../$rpm_file" | cpio -idm )
306+
test -x rpm-verify/usr/bin/wp
307+
head -n1 rpm-verify/usr/bin/wp | grep -q '^#!/bin/sh'
308+
grep -q 'WP_CLI_PHP' rpm-verify/usr/bin/wp
309+
grep -q 'WP_CLI_PHP_ARGS' rpm-verify/usr/bin/wp
310+
grep -q '/usr/share/wp-cli/wp-cli.phar' rpm-verify/usr/bin/wp
311+
test -s rpm-verify/usr/share/wp-cli/wp-cli.phar
297312
298313
- name: Copy RPM package into builds folder
299314
run: |
@@ -346,7 +361,28 @@ jobs:
346361
347362
- name: Verify built DEB package contents
348363
run: |
349-
ls .
364+
set -euxo pipefail
365+
deb_file="$(ls php-wpcli*all.deb)"
366+
# The package must ship a launcher in the bin dir and the Phar in the data dir.
367+
dpkg-deb -c "$deb_file" | tee /tmp/deb-files.txt
368+
grep -Eq ' \./usr/bin/wp$' /tmp/deb-files.txt
369+
grep -Eq ' \./usr/share/wp-cli/wp-cli.phar$' /tmp/deb-files.txt
370+
# Install the package and exercise the launcher (php ships on the runner).
371+
sudo dpkg -i "$deb_file" || sudo apt-get install -f -y
372+
test -x /usr/bin/wp
373+
head -n1 /usr/bin/wp | grep -q '^#!/bin/sh'
374+
test -s /usr/share/wp-cli/wp-cli.phar
375+
# Default interpreter works.
376+
wp --info
377+
wp cli version
378+
# WP_CLI_PHP selects the interpreter and WP_CLI_PHP_ARGS is passed through.
379+
WP_CLI_PHP="$(command -v php)" WP_CLI_PHP_ARGS="-d memory_limit=256M" wp cli version
380+
# A deliberately broken WP_CLI_PHP must actually be used: if it were ignored,
381+
# this would still succeed. This is the regression guard for the whole fix.
382+
if WP_CLI_PHP=/bin/false wp cli version 2>/dev/null; then
383+
echo "WP_CLI_PHP was ignored by the launcher" >&2
384+
exit 1
385+
fi
350386
351387
- name: Copy DEB package into builds folder
352388
run: |

‎utils/wp-cli-rpm.spec‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
Name: wp-cli
22
Version: 0.0.0
3-
Release: 2%{?dist}
3+
Release: 3%{?dist}
44
Summary: The command line interface for WordPress
55
License: MIT
66
URL: http://wp-cli.org/
77
Source0: wp-cli.phar
88
Source1: wp.1
9+
Source2: wp
910
BuildArch: noarch
1011

1112
%post
@@ -29,16 +30,24 @@ chmod +x %{SOURCE0}
2930
%build
3031

3132
%install
32-
mkdir -p %{buildroot}%{_bindir}
33-
install -p -m 0755 %{SOURCE0} %{buildroot}%{_bindir}/wp
34-
mkdir -p %{buildroot}%{_mandir}/man1
33+
install -d -m 0755 %{buildroot}%{_datadir}/wp-cli
34+
install -p -m 0755 %{SOURCE0} %{buildroot}%{_datadir}/wp-cli/wp-cli.phar
35+
install -d -m 0755 %{buildroot}%{_bindir}
36+
install -p -m 0755 %{SOURCE2} %{buildroot}%{_bindir}/wp
37+
install -d -m 0755 %{buildroot}%{_mandir}/man1
3538
install -p -m 0644 %{SOURCE1} %{buildroot}%{_mandir}/man1/
3639

3740
%files
3841
%attr(0755, root, root) %{_bindir}/wp
42+
%dir %attr(0755, root, root) %{_datadir}/wp-cli
43+
%attr(0755, root, root) %{_datadir}/wp-cli/wp-cli.phar
3944
%attr(0644, root, root) %{_mandir}/man1/wp.1*
4045

4146
%changelog
47+
* Tue Jul 21 2026 Alain Schlesser <alain.schlesser@gmail.com> - 0.0.0-3
48+
- Install the Phar to %{_datadir}/wp-cli and ship a launcher at %{_bindir}/wp
49+
so WP_CLI_PHP and WP_CLI_PHP_ARGS are honored.
50+
4251
* Tue Dec 12 2017 Murtaza Sarıaltun <murtaza.sarialtun@ozguryazzilim.com.tr> - 0.0.0-2
4352
- Remove php requirements.
4453
- Update creating man page steps.

‎utils/wp-cli-updatedeb.sh‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@ Description: wp-cli is a set of command-line tools for managing
4040
EOF
4141
}
4242

43+
dump_launcher() {
44+
# Write the launcher script that selects the PHP interpreter (honoring
45+
# WP_CLI_PHP and WP_CLI_PHP_ARGS) and runs the bundled Phar.
46+
# Quoted heredoc delimiter keeps the variables literal.
47+
cat > "$1" <<'LAUNCHER'
48+
#!/bin/sh
49+
#
50+
# WP-CLI launcher for the Debian package.
51+
# Selects the PHP interpreter, honoring the WP_CLI_PHP and WP_CLI_PHP_ARGS
52+
# environment variables, then runs the bundled Phar.
53+
# See https://github.com/wp-cli/wp-cli-bundle/issues/1078
54+
55+
if [ -n "$WP_CLI_PHP" ]; then
56+
php="$WP_CLI_PHP"
57+
else
58+
php="$(command -v php)"
59+
fi
60+
61+
export WP_CLI_PHP_USED="$php"
62+
63+
# WP_CLI_PHP_ARGS is intentionally unquoted so multiple arguments are split.
64+
# shellcheck disable=SC2086
65+
exec "$php" $WP_CLI_PHP_ARGS /usr/share/wp-cli/wp-cli.phar "$@"
66+
LAUNCHER
67+
}
68+
4369
set -e
4470

4571
# Download the binary if needed
@@ -76,13 +102,18 @@ fi
76102

77103
# content dirs
78104
[ -d usr/bin ] || mkdir -p usr/bin
105+
[ -d usr/share/wp-cli ] || mkdir -p usr/share/wp-cli
79106

80-
# move phar
81-
mv ../wp-cli.phar usr/bin/wp
82-
chmod +x usr/bin/wp
107+
# install the Phar to a shared location and a launcher to the bin dir
108+
mv ../wp-cli.phar usr/share/wp-cli/wp-cli.phar
109+
chmod 0755 usr/share/wp-cli/wp-cli.phar
110+
dump_launcher usr/bin/wp
111+
chmod 0755 usr/bin/wp
83112

84113
# get version
85-
WPCLI_VER="$(usr/bin/wp cli version | cut -d " " -f 2)"
114+
# The launcher hard-codes the installed /usr/share path, which does not exist
115+
# inside the staging dir yet, so invoke PHP against the staged Phar directly.
116+
WPCLI_VER="$(php usr/share/wp-cli/wp-cli.phar cli version | cut -d " " -f 2)"
86117
[ -z "$WPCLI_VER" ] && die 5 "Cannot get wp-cli version"
87118
echo "Current version: ${WPCLI_VER}"
88119

@@ -94,7 +125,7 @@ if ! [ -r usr/share/man/man1/wp.1.gz ]; then
94125
mkdir -p usr/share/man/man1 &> /dev/null
95126
{
96127
echo '.TH "WP" "1"'
97-
usr/bin/wp --help
128+
php usr/share/wp-cli/wp-cli.phar --help
98129
} \
99130
| sed 's/^\([A-Z ]\+\)$/.SH "\1"/' \
100131
| sed 's/^ wp$/wp \\- A command line interface for WordPress/' \

‎utils/wp-cli-updaterpm.sh‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,40 @@ pushd "$SOURCE_DIR" > /dev/null
4545
mv ../wp-cli.phar wp-cli.phar
4646
cp ../wp-cli-rpm.spec wp-cli.spec
4747

48+
# Write the launcher script that selects the PHP interpreter (honoring
49+
# WP_CLI_PHP and WP_CLI_PHP_ARGS) and runs the bundled Phar.
50+
# Quoted heredoc delimiter keeps the variables literal.
51+
cat > wp <<'LAUNCHER'
52+
#!/bin/sh
53+
#
54+
# WP-CLI launcher for the RPM package.
55+
# Selects the PHP interpreter, honoring the WP_CLI_PHP and WP_CLI_PHP_ARGS
56+
# environment variables, then runs the bundled Phar.
57+
# See https://github.com/wp-cli/wp-cli-bundle/issues/1078
58+
59+
if [ -n "$WP_CLI_PHP" ]; then
60+
php="$WP_CLI_PHP"
61+
else
62+
php="$(command -v php)"
63+
fi
64+
65+
export WP_CLI_PHP_USED="$php"
66+
67+
# WP_CLI_PHP_ARGS is intentionally unquoted so multiple arguments are split.
68+
# shellcheck disable=SC2086
69+
exec "$php" $WP_CLI_PHP_ARGS /usr/share/wp-cli/wp-cli.phar "$@"
70+
LAUNCHER
71+
4872
# Replace version placeholder
4973
WPCLI_VER="$(php wp-cli.phar cli version | cut -d " " -f 2)"
5074
if [ -z "$WPCLI_VER" ]; then
5175
die 3 "Cannot get WP_CLI version"
5276
fi
5377
echo "Current version: ${WPCLI_VER}"
5478
sed -i -e "s/^Version: .*\$/Version: ${WPCLI_VER}/" wp-cli.spec || die 4 "Version update failed"
55-
sed -i -e "s/^\(\* .*\) 0\.0\.0-1\$/\1 ${WPCLI_VER}-1/" wp-cli.spec || die 5 "Changleog update failed"
79+
# Rewrite the placeholder version in every changelog entry (0.0.0-N -> ${WPCLI_VER}-N)
80+
# so the top entry stays coherent with the package version for rpmlint.
81+
sed -i -e "s/^\(\* .*\) 0\.0\.0-\([0-9]\+\)\$/\1 ${WPCLI_VER}-\2/" wp-cli.spec || die 5 "Changelog update failed"
5682

5783
# Create man page
5884
{

0 commit comments

Comments
 (0)