Skip to content

Commit 871a549

Browse files
authored
Merge branch 'main' into copilot/fix-wp-config-mustache-file
2 parents 9708a3a + 020de7a commit 871a549

4 files changed

Lines changed: 138 additions & 12 deletions

File tree

.github/workflows/deployment.yml

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,34 @@ 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 '/usr/share/wp-cli/wp-cli.phar' rpm-verify/usr/bin/wp
309+
test -s rpm-verify/usr/share/wp-cli/wp-cli.phar
310+
# Run the extracted launcher through a probe standing in for PHP: it must
311+
# forward WP_CLI_PHP_ARGS before the Phar and export WP_CLI_PHP_USED. The
312+
# probe asserts and exits without needing the Phar at its installed path.
313+
printf '%s\n' \
314+
'#!/bin/sh' \
315+
'case " $* " in' \
316+
' *" -d memory_limit=256M "*) : ;;' \
317+
' *) echo "WP_CLI_PHP_ARGS not forwarded: $*" >&2; exit 3 ;;' \
318+
'esac' \
319+
'[ -n "$WP_CLI_PHP_USED" ] || { echo "WP_CLI_PHP_USED not exported" >&2; exit 4; }' \
320+
'exit 0' \
321+
> /tmp/wp-cli-php-probe
322+
chmod +x /tmp/wp-cli-php-probe
323+
WP_CLI_PHP=/tmp/wp-cli-php-probe WP_CLI_PHP_ARGS="-d memory_limit=256M" rpm-verify/usr/bin/wp cli version
297324
298325
- name: Copy RPM package into builds folder
299326
run: |
@@ -346,7 +373,40 @@ jobs:
346373
347374
- name: Verify built DEB package contents
348375
run: |
349-
ls .
376+
set -euxo pipefail
377+
deb_file="$(ls php-wpcli*all.deb)"
378+
# The package must ship a launcher in the bin dir and the Phar in the data dir.
379+
dpkg-deb -c "$deb_file" | tee /tmp/deb-files.txt
380+
grep -Eq ' \./usr/bin/wp$' /tmp/deb-files.txt
381+
grep -Eq ' \./usr/share/wp-cli/wp-cli.phar$' /tmp/deb-files.txt
382+
# Install the package and exercise the launcher (php ships on the runner).
383+
sudo dpkg -i "$deb_file" || sudo apt-get install -f -y
384+
test -x /usr/bin/wp
385+
head -n1 /usr/bin/wp | grep -q '^#!/bin/sh'
386+
test -s /usr/share/wp-cli/wp-cli.phar
387+
# Default interpreter works.
388+
wp --info
389+
wp cli version
390+
# A probe that stands in for PHP and asserts what the launcher forwarded:
391+
# it must receive WP_CLI_PHP_ARGS before the Phar and inherit WP_CLI_PHP_USED.
392+
printf '%s\n' \
393+
'#!/bin/sh' \
394+
'case " $* " in' \
395+
' *" -d memory_limit=256M "*) : ;;' \
396+
' *) echo "WP_CLI_PHP_ARGS not forwarded: $*" >&2; exit 3 ;;' \
397+
'esac' \
398+
'[ -n "$WP_CLI_PHP_USED" ] || { echo "WP_CLI_PHP_USED not exported" >&2; exit 4; }' \
399+
'exit 0' \
400+
> /tmp/wp-cli-php-probe
401+
chmod +x /tmp/wp-cli-php-probe
402+
# Proves WP_CLI_PHP selects the interpreter AND WP_CLI_PHP_ARGS reaches it.
403+
WP_CLI_PHP=/tmp/wp-cli-php-probe WP_CLI_PHP_ARGS="-d memory_limit=256M" wp cli version
404+
# A deliberately broken WP_CLI_PHP must actually be used: if it were ignored,
405+
# this would still succeed. This is the regression guard for the whole fix.
406+
if WP_CLI_PHP=/bin/false wp cli version 2>/dev/null; then
407+
echo "WP_CLI_PHP was ignored by the launcher" >&2
408+
exit 1
409+
fi
350410
351411
- name: Copy DEB package into builds folder
352412
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)