Skip to content

Compare plugin versions when deciding whether to deploy - #2620

Open
westonruter wants to merge 1 commit into
trunkfrom
fix/deploy-version-compare
Open

Compare plugin versions when deciding whether to deploy#2620
westonruter wants to merge 1 commit into
trunkfrom
fix/deploy-version-compare

Conversation

@westonruter

@westonruter westonruter commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

This is something I noticed while working on #2619. I wasn't comfortable using the regular workflow for deployments of all plugins when a tag was created because the "Check if deployment is needed" step only halts when the version on WordPress.org is string-equal to the version being built:

if [ "$PLUGIN_VERSION_WPORG" = "$PLUGIN_VERSION" ]; then

So if the version on WordPress.org is newer than the one in the branch, the versions are unequal, the check passes, and the deployment proceeds — overwriting a newer release with an older one. Being a string comparison, it is also blind to ordering generally: 1.10.0 and 1.9.0 are simply "not equal".

Relevant technical choices

Swapped the equality test for version_compare(), halting whenever the WordPress.org version is >= the version being deployed:

if php -r 'exit( version_compare( $argv[1], $argv[2], ">=" ) ? 0 : 1 );' "$PLUGIN_VERSION_WPORG" "$PLUGIN_VERSION"; then

Verified against the cases that matter:

WordPress.org Being deployed Result
1.2.0 1.2.0 halt
1.3.0 1.2.0 halt (previously deployed)
1.10.0 1.9.0 halt (previously deployed)
1.2.0 1.3.0 deploy
1.2.0-beta1 1.2.0 deploy

The ::notice:: now names both versions, so the job log says why it stopped rather than just asserting the plugin is up to date.

Also added a setup-php step, pinned to the same SHA already used by php-lint.yml, plugin-check.yml, and copilot-setup-steps.yml. PHP is preinstalled on the ubuntu-latest image, so php -r would work without it — but relying on that fails open: a missing php binary exits non-zero, the if reads as "versions differ", and the deployment proceeds. Setting PHP up explicitly turns that into a failed job instead. I used php-version: latest (as in php-lint.yml) since version_compare() behavior is stable across versions; happy to pin it to '8.3' to match plugin-check.yml if preferred.

Testing instructions

The changed step can be exercised standalone:

for pair in "1.2.0 1.2.0" "1.3.0 1.2.0" "1.2.0 1.3.0" "1.10.0 1.9.0" "1.2.0-beta1 1.2.0"; do
  set -- $pair
  if php -r 'exit( version_compare( $argv[1], $argv[2], ">=" ) ? 0 : 1 );' "$1" "$2"; then
    echo "wporg=$1 build=$2 -> HALT"
  else
    echo "wporg=$1 build=$2 -> DEPLOY"
  fi
done

Note that the workflow itself only runs on release, so this path is not exercised by CI on this PR.

Use of AI Tools

Claude Code wrote the change and this description, at my direction, after I spotted the faulty comparison and specified the version_compare() fix and the setup-php addition. I reviewed both the diff and the verification output.

🤖 Generated with Claude Code

The "Check if deployment is needed" step only halted when the version on
WordPress.org was string-equal to the version being built. If the version
on WordPress.org was *newer* than the one in the branch, the check passed
and the deployment proceeded, overwriting a newer release with an older
one.

Replace the equality test with `version_compare()` so the deployment
halts whenever the WordPress.org version is greater than or equal to the
version being deployed. This also fixes the string comparison itself,
which would have treated 1.10.0 and 1.9.0 as unequal without regard for
which is actually newer.

The notice now names both versions so the reason for halting is visible
in the job log.

Add a `setup-php` step, pinned to the same SHA already used by
`php-lint.yml`, `plugin-check.yml`, and `copilot-setup-steps.yml`. PHP is
preinstalled on the `ubuntu-latest` image, but relying on that would fail
open: a missing `php` binary exits non-zero, the check would read as
"versions differ", and the deployment would proceed. Setting PHP up
explicitly makes that case fail the job instead.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <westonruter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter westonruter added [Type] Bug An existing feature is broken Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release skip changelog PRs that should not be mentioned in changelogs labels Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release skip changelog PRs that should not be mentioned in changelogs [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant