Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,34 @@ jobs:

- name: Verify built RPM package contents
run: |
ls rpm-src/noarch
set -euxo pipefail
rpm_file="$(ls rpm-src/noarch/wp-cli-*.noarch.rpm)"
# The package must ship a launcher in the bin dir and the Phar in the data dir.
rpm -qlp "$rpm_file" | tee /tmp/rpm-files.txt
grep -qx '/usr/bin/wp' /tmp/rpm-files.txt
grep -qx '/usr/share/wp-cli/wp-cli.phar' /tmp/rpm-files.txt
# /usr/bin/wp must be the shell launcher that honors WP_CLI_PHP / WP_CLI_PHP_ARGS,
# not the Phar itself.
mkdir -p rpm-verify
( cd rpm-verify && rpm2cpio "../$rpm_file" | cpio -idm )
test -x rpm-verify/usr/bin/wp
head -n1 rpm-verify/usr/bin/wp | grep -q '^#!/bin/sh'
grep -q '/usr/share/wp-cli/wp-cli.phar' rpm-verify/usr/bin/wp
test -s rpm-verify/usr/share/wp-cli/wp-cli.phar
# Run the extracted launcher through a probe standing in for PHP: it must
# forward WP_CLI_PHP_ARGS before the Phar and export WP_CLI_PHP_USED. The
# probe asserts and exits without needing the Phar at its installed path.
printf '%s\n' \
'#!/bin/sh' \
'case " $* " in' \
' *" -d memory_limit=256M "*) : ;;' \
' *) echo "WP_CLI_PHP_ARGS not forwarded: $*" >&2; exit 3 ;;' \
'esac' \
'[ -n "$WP_CLI_PHP_USED" ] || { echo "WP_CLI_PHP_USED not exported" >&2; exit 4; }' \
'exit 0' \
> /tmp/wp-cli-php-probe
chmod +x /tmp/wp-cli-php-probe
WP_CLI_PHP=/tmp/wp-cli-php-probe WP_CLI_PHP_ARGS="-d memory_limit=256M" rpm-verify/usr/bin/wp cli version

- name: Copy RPM package into builds folder
run: |
Expand Down Expand Up @@ -346,7 +373,40 @@ jobs:

- name: Verify built DEB package contents
run: |
ls .
set -euxo pipefail
deb_file="$(ls php-wpcli*all.deb)"
# The package must ship a launcher in the bin dir and the Phar in the data dir.
dpkg-deb -c "$deb_file" | tee /tmp/deb-files.txt
grep -Eq ' \./usr/bin/wp$' /tmp/deb-files.txt
grep -Eq ' \./usr/share/wp-cli/wp-cli.phar$' /tmp/deb-files.txt
# Install the package and exercise the launcher (php ships on the runner).
sudo dpkg -i "$deb_file" || sudo apt-get install -f -y
test -x /usr/bin/wp
head -n1 /usr/bin/wp | grep -q '^#!/bin/sh'
test -s /usr/share/wp-cli/wp-cli.phar
# Default interpreter works.
wp --info
wp cli version
# A probe that stands in for PHP and asserts what the launcher forwarded:
# it must receive WP_CLI_PHP_ARGS before the Phar and inherit WP_CLI_PHP_USED.
printf '%s\n' \
'#!/bin/sh' \
'case " $* " in' \
' *" -d memory_limit=256M "*) : ;;' \
' *) echo "WP_CLI_PHP_ARGS not forwarded: $*" >&2; exit 3 ;;' \
'esac' \
'[ -n "$WP_CLI_PHP_USED" ] || { echo "WP_CLI_PHP_USED not exported" >&2; exit 4; }' \
'exit 0' \
> /tmp/wp-cli-php-probe
chmod +x /tmp/wp-cli-php-probe
# Proves WP_CLI_PHP selects the interpreter AND WP_CLI_PHP_ARGS reaches it.
WP_CLI_PHP=/tmp/wp-cli-php-probe WP_CLI_PHP_ARGS="-d memory_limit=256M" wp cli version
# A deliberately broken WP_CLI_PHP must actually be used: if it were ignored,
# this would still succeed. This is the regression guard for the whole fix.
if WP_CLI_PHP=/bin/false wp cli version 2>/dev/null; then
echo "WP_CLI_PHP was ignored by the launcher" >&2
exit 1
fi

- name: Copy DEB package into builds folder
run: |
Expand Down
17 changes: 13 additions & 4 deletions utils/wp-cli-rpm.spec
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Name: wp-cli
Version: 0.0.0
Release: 2%{?dist}
Release: 3%{?dist}
Summary: The command line interface for WordPress
License: MIT
URL: http://wp-cli.org/
Source0: wp-cli.phar
Source1: wp.1
Source2: wp
BuildArch: noarch

%post
Expand All @@ -29,16 +30,24 @@ chmod +x %{SOURCE0}
%build

%install
mkdir -p %{buildroot}%{_bindir}
install -p -m 0755 %{SOURCE0} %{buildroot}%{_bindir}/wp
mkdir -p %{buildroot}%{_mandir}/man1
install -d -m 0755 %{buildroot}%{_datadir}/wp-cli
install -p -m 0755 %{SOURCE0} %{buildroot}%{_datadir}/wp-cli/wp-cli.phar
install -d -m 0755 %{buildroot}%{_bindir}
install -p -m 0755 %{SOURCE2} %{buildroot}%{_bindir}/wp
install -d -m 0755 %{buildroot}%{_mandir}/man1
install -p -m 0644 %{SOURCE1} %{buildroot}%{_mandir}/man1/

%files
%attr(0755, root, root) %{_bindir}/wp
%dir %attr(0755, root, root) %{_datadir}/wp-cli
%attr(0755, root, root) %{_datadir}/wp-cli/wp-cli.phar
%attr(0644, root, root) %{_mandir}/man1/wp.1*

%changelog
* Tue Jul 21 2026 Alain Schlesser <alain.schlesser@gmail.com> - 0.0.0-3
- Install the Phar to %{_datadir}/wp-cli and ship a launcher at %{_bindir}/wp
so WP_CLI_PHP and WP_CLI_PHP_ARGS are honored.

* Tue Dec 12 2017 Murtaza Sarıaltun <murtaza.sarialtun@ozguryazzilim.com.tr> - 0.0.0-2
- Remove php requirements.
- Update creating man page steps.
Expand Down
41 changes: 36 additions & 5 deletions utils/wp-cli-updatedeb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ Description: wp-cli is a set of command-line tools for managing
EOF
}

dump_launcher() {
# Write the launcher script that selects the PHP interpreter (honoring
# WP_CLI_PHP and WP_CLI_PHP_ARGS) and runs the bundled Phar.
# Quoted heredoc delimiter keeps the variables literal.
cat > "$1" <<'LAUNCHER'
#!/bin/sh
#
# WP-CLI launcher for the Debian package.
# Selects the PHP interpreter, honoring the WP_CLI_PHP and WP_CLI_PHP_ARGS
# environment variables, then runs the bundled Phar.
# See https://github.com/wp-cli/wp-cli-bundle/issues/1078

if [ -n "$WP_CLI_PHP" ]; then
php="$WP_CLI_PHP"
else
php="$(command -v php)"
fi

export WP_CLI_PHP_USED="$php"

# WP_CLI_PHP_ARGS is intentionally unquoted so multiple arguments are split.
# shellcheck disable=SC2086
exec "$php" $WP_CLI_PHP_ARGS /usr/share/wp-cli/wp-cli.phar "$@"
LAUNCHER
}

set -e

# Download the binary if needed
Expand Down Expand Up @@ -76,13 +102,18 @@ fi

# content dirs
[ -d usr/bin ] || mkdir -p usr/bin
[ -d usr/share/wp-cli ] || mkdir -p usr/share/wp-cli

# move phar
mv ../wp-cli.phar usr/bin/wp
chmod +x usr/bin/wp
# install the Phar to a shared location and a launcher to the bin dir
mv ../wp-cli.phar usr/share/wp-cli/wp-cli.phar
chmod 0755 usr/share/wp-cli/wp-cli.phar
dump_launcher usr/bin/wp
chmod 0755 usr/bin/wp

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

Expand All @@ -94,7 +125,7 @@ if ! [ -r usr/share/man/man1/wp.1.gz ]; then
mkdir -p usr/share/man/man1 &> /dev/null
{
echo '.TH "WP" "1"'
usr/bin/wp --help
php usr/share/wp-cli/wp-cli.phar --help
} \
| sed 's/^\([A-Z ]\+\)$/.SH "\1"/' \
| sed 's/^ wp$/wp \\- A command line interface for WordPress/' \
Expand Down
28 changes: 27 additions & 1 deletion utils/wp-cli-updaterpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,40 @@ pushd "$SOURCE_DIR" > /dev/null
mv ../wp-cli.phar wp-cli.phar
cp ../wp-cli-rpm.spec wp-cli.spec

# Write the launcher script that selects the PHP interpreter (honoring
# WP_CLI_PHP and WP_CLI_PHP_ARGS) and runs the bundled Phar.
# Quoted heredoc delimiter keeps the variables literal.
cat > wp <<'LAUNCHER'
#!/bin/sh
#
# WP-CLI launcher for the RPM package.
# Selects the PHP interpreter, honoring the WP_CLI_PHP and WP_CLI_PHP_ARGS
# environment variables, then runs the bundled Phar.
# See https://github.com/wp-cli/wp-cli-bundle/issues/1078

if [ -n "$WP_CLI_PHP" ]; then
php="$WP_CLI_PHP"
else
php="$(command -v php)"
fi

export WP_CLI_PHP_USED="$php"

# WP_CLI_PHP_ARGS is intentionally unquoted so multiple arguments are split.
# shellcheck disable=SC2086
exec "$php" $WP_CLI_PHP_ARGS /usr/share/wp-cli/wp-cli.phar "$@"
LAUNCHER

# Replace version placeholder
WPCLI_VER="$(php wp-cli.phar cli version | cut -d " " -f 2)"
if [ -z "$WPCLI_VER" ]; then
die 3 "Cannot get WP_CLI version"
fi
echo "Current version: ${WPCLI_VER}"
sed -i -e "s/^Version: .*\$/Version: ${WPCLI_VER}/" wp-cli.spec || die 4 "Version update failed"
sed -i -e "s/^\(\* .*\) 0\.0\.0-1\$/\1 ${WPCLI_VER}-1/" wp-cli.spec || die 5 "Changleog update failed"
# Rewrite the placeholder version in every changelog entry (0.0.0-N -> ${WPCLI_VER}-N)
# so the top entry stays coherent with the package version for rpmlint.
sed -i -e "s/^\(\* .*\) 0\.0\.0-\([0-9]\+\)\$/\1 ${WPCLI_VER}-\2/" wp-cli.spec || die 5 "Changelog update failed"

# Create man page
{
Expand Down
Loading