From 4d7d59bf80826954e7b46c7eb348e712fd0f8ec0 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 2 Dec 2026 15:18:35 +0000 Subject: [PATCH 1/3] Replace unreleased RPM and DEB packages on every release build The RPM and DEB packages were copied into wp-cli/builds with `cp -n`, so a second push of a release branch rebuilt wp-cli-release.phar but kept the first build's packages, and then failed on "nothing to commit". The packages then carried a different Phar than the one being released, and php-wpcli_latest_all.deb could end up pointing at one of them. A package for a version without a published release on wp-cli/wp-cli is now replaced. A package for a published release is never replaced, as users may already have installed it. Unchanged packages no longer fail the commit step. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5nj9APjNTmERyYPSe6 --- .github/workflows/deployment.yml | 24 +++++++++++++-- utils/copy-release-package.sh | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100755 utils/copy-release-package.sh diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 7c87d40da..1eb9fbaf7 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -350,15 +350,25 @@ jobs: 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 + # Replaces the package of a version that is not released yet, so it + # always carries the Phar this push built; never touches a released one. - name: Copy RPM package into builds folder + env: + GH_TOKEN: ${{ github.token }} run: | - cp -n rpm-src/noarch/wp-cli-*.noarch.rpm rpm + bash bundle/utils/copy-release-package.sh rpm-src/noarch/wp-cli-*.noarch.rpm rpm - name: Commit files run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add rpm + + if git diff --staged --quiet; then + echo "The RPM package in wp-cli/builds is already up to date." + exit 0 + fi + git commit -m "rpm build: $GITHUB_REPOSITORY@$GITHUB_SHA" - name: Push changes @@ -450,15 +460,25 @@ jobs: exit 1 fi + # Replaces the package of a version that is not released yet, so it + # always carries the Phar this push built; never touches a released one. - name: Copy DEB package into builds folder + env: + GH_TOKEN: ${{ github.token }} run: | - cp -n php-wpcli*all.deb deb + bash bundle/utils/copy-release-package.sh php-wpcli*all.deb deb - name: Commit files run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add deb + + if git diff --staged --quiet; then + echo "The DEB package in wp-cli/builds is already up to date." + exit 0 + fi + git commit -m "deb build: $GITHUB_REPOSITORY@$GITHUB_SHA" - name: Push changes diff --git a/utils/copy-release-package.sh b/utils/copy-release-package.sh new file mode 100755 index 000000000..4ed78fb88 --- /dev/null +++ b/utils/copy-release-package.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# +# Copies a freshly built RPM or DEB package into the wp-cli/builds checkout. +# +# Usage: copy-release-package.sh +# +# Every push to a release-** branch rebuilds wp-cli-release.phar, so the +# package for that version has to be rebuilt along with it: the release +# automation in wp-cli/wp-cli refuses a package that carries a different Phar +# than the one being released. A package for a version that is not released +# yet is therefore replaced. +# +# A package for a published release is never replaced, as users may already +# have installed it. Published releases on wp-cli/wp-cli are what counts; +# drafts are not visible to the API without push access, so they do not. + +set -euo pipefail + +if [ "$#" -ne 2 ] || [ ! -f "$1" ] || [ ! -d "$2" ]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +PACKAGE="$1" +NAME="$(basename "$PACKAGE")" +DEST="$2/$NAME" + +if [[ "$NAME" =~ ^php-wpcli_(.+)_all\.deb$ ]] || [[ "$NAME" =~ ^wp-cli-(.+)-[0-9]+\.noarch\.rpm$ ]]; then + VERSION="${BASH_REMATCH[1]}" +else + echo "::error::Cannot tell the version of $NAME." >&2 + exit 1 +fi + +if [ -e "$DEST" ] && ! cmp -s "$PACKAGE" "$DEST"; then + ERROR_FILE="$(mktemp)" + + if gh api "repos/wp-cli/wp-cli/releases/tags/v${VERSION}" --silent 2> "$ERROR_FILE"; then + echo "::notice::v${VERSION} is already released. Keeping the published $DEST." + exit 0 + fi + + # Fails closed: anything but "no such release" could be a published one. + if ! grep -q 'HTTP 404' "$ERROR_FILE"; then + echo "::error::Could not check whether v${VERSION} is released:" >&2 + cat "$ERROR_FILE" >&2 + exit 1 + fi + + echo "::notice::Replacing $DEST, which was built from an earlier push of the release branch." +fi + +cp "$PACKAGE" "$DEST" From 589d228cd78a15d00f712247afb0774313624711 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 2 Dec 2026 16:30:17 +0000 Subject: [PATCH 2/3] Simplify the release lookup in copy-release-package.sh Capture the lookup error in a variable instead of a temporary file that was never removed, and return early when the package is already identical, which also covers a source that is already in place. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5nj9APjNTmERyYPSe6 --- utils/copy-release-package.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/utils/copy-release-package.sh b/utils/copy-release-package.sh index 4ed78fb88..5bbd8256c 100755 --- a/utils/copy-release-package.sh +++ b/utils/copy-release-package.sh @@ -32,18 +32,21 @@ else exit 1 fi -if [ -e "$DEST" ] && ! cmp -s "$PACKAGE" "$DEST"; then - ERROR_FILE="$(mktemp)" +if [ -e "$DEST" ]; then + if cmp -s "$PACKAGE" "$DEST"; then + echo "$DEST is already up to date." + exit 0 + fi - if gh api "repos/wp-cli/wp-cli/releases/tags/v${VERSION}" --silent 2> "$ERROR_FILE"; then + if ERROR="$(gh api "repos/wp-cli/wp-cli/releases/tags/v${VERSION}" --silent 2>&1)"; then echo "::notice::v${VERSION} is already released. Keeping the published $DEST." exit 0 fi # Fails closed: anything but "no such release" could be a published one. - if ! grep -q 'HTTP 404' "$ERROR_FILE"; then + if [[ "$ERROR" != *'HTTP 404'* ]]; then echo "::error::Could not check whether v${VERSION} is released:" >&2 - cat "$ERROR_FILE" >&2 + printf '%s\n' "$ERROR" >&2 exit 1 fi From b4505da5c08023167dbeba2f9ef12f5924093a6a Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 2 Dec 2026 16:31:01 +0000 Subject: [PATCH 3/3] Harden copy-release-package.sh and skip no-op pushes - Only accept a plain version in package names, so neither php-wpcli_latest_all.deb nor URL metacharacters reach the release lookup, and allow an RPM %{?dist} suffix. - Skip the push to wp-cli/builds when nothing was committed. - Correct the comment on draft releases. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5nj9APjNTmERyYPSe6 --- .github/workflows/deployment.yml | 10 ++++++++++ utils/copy-release-package.sh | 10 +++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 1eb9fbaf7..ded61d737 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -359,6 +359,7 @@ jobs: bash bundle/utils/copy-release-package.sh rpm-src/noarch/wp-cli-*.noarch.rpm rpm - name: Commit files + id: commit run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" @@ -370,8 +371,12 @@ jobs: fi git commit -m "rpm build: $GITHUB_REPOSITORY@$GITHUB_SHA" + echo "committed=true" >> "$GITHUB_OUTPUT" + # Nothing to push otherwise, and a no-op push can still fail when + # another build pushed to gh-pages in the meantime. - name: Push changes + if: ${{ steps.commit.outputs.committed == 'true' }} uses: ad-m/github-push-action@881a6320fdb16eb5318c5054f31c218aec2b324c # v1 with: github_token: ${{ secrets.ACTIONS_BOT }} @@ -469,6 +474,7 @@ jobs: bash bundle/utils/copy-release-package.sh php-wpcli*all.deb deb - name: Commit files + id: commit run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" @@ -480,8 +486,12 @@ jobs: fi git commit -m "deb build: $GITHUB_REPOSITORY@$GITHUB_SHA" + echo "committed=true" >> "$GITHUB_OUTPUT" + # Nothing to push otherwise, and a no-op push can still fail when + # another build pushed to gh-pages in the meantime. - name: Push changes + if: ${{ steps.commit.outputs.committed == 'true' }} uses: ad-m/github-push-action@881a6320fdb16eb5318c5054f31c218aec2b324c # v1 with: github_token: ${{ secrets.ACTIONS_BOT }} diff --git a/utils/copy-release-package.sh b/utils/copy-release-package.sh index 5bbd8256c..4bf74faf3 100755 --- a/utils/copy-release-package.sh +++ b/utils/copy-release-package.sh @@ -11,8 +11,8 @@ # yet is therefore replaced. # # A package for a published release is never replaced, as users may already -# have installed it. Published releases on wp-cli/wp-cli are what counts; -# drafts are not visible to the API without push access, so they do not. +# have installed it. Published releases on wp-cli/wp-cli are what counts: the +# release-by-tag endpoint never returns drafts, whatever the credentials. set -euo pipefail @@ -25,7 +25,11 @@ PACKAGE="$1" NAME="$(basename "$PACKAGE")" DEST="$2/$NAME" -if [[ "$NAME" =~ ^php-wpcli_(.+)_all\.deb$ ]] || [[ "$NAME" =~ ^wp-cli-(.+)-[0-9]+\.noarch\.rpm$ ]]; then +# Only a plain version is accepted: it ends up in the API path below, and +# php-wpcli_latest_all.deb must never match. The RPM release may carry a +# %{?dist} suffix (wp-cli-3.0.1-3.el9.noarch.rpm). +VERSION_PATTERN='[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.]+)?' +if [[ "$NAME" =~ ^php-wpcli_(${VERSION_PATTERN})_all\.deb$ ]] || [[ "$NAME" =~ ^wp-cli-(${VERSION_PATTERN})-[0-9]+(\.[^.]+)?\.noarch\.rpm$ ]]; then VERSION="${BASH_REMATCH[1]}" else echo "::error::Cannot tell the version of $NAME." >&2