ci: make release version bump idempotent#43
Merged
Conversation
updateComposerVersion() treated a no-op regex replace as fatal, so when composer.json already held the target version the release script aborted before tagging/publishing. This deadlocked the auto-release flow whenever the declared version drifted ahead of the latest git tag (e.g. a manual version bump merged inside a feature PR, as in #39). Count actual replacements instead: throw only when the version field is genuinely absent, and treat an already-correct value as success. This mirrors the existing behaviour of updateConstantVersion().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why the auto-release flow is stuck
The release workflow has failed on the last 3 PR merges (#39, #40, #42), all with the same fatal error at
scripts/release/bump_version.php:152:Two problems stacked together:
State drift (trigger). PR feat: [CHA-2956] connection pooling: getstream-php #39 included a manual version bump inside the feature branch (
composer.jsonv7.2.0 -> v7.3.0). So the declared version (7.3.0) is now ahead of the latest git tag (v7.2.0), and nov7.3.0tag/release exists. The script computes the next version from the latest tag, so everyfeat/fixmerge recomputesv7.2.0+ minor =7.3.0, which is exactly whatcomposer.jsonalready says.Code brittleness (why drift = permanent deadlock).
updateComposerVersion()treated a no-op regex replace ($updated === $raw) as fatal. When the file already holds the target version the replace changes nothing, so the script aborts before tagging/publishing. The siblingupdateConstantVersion()never had this flaw.The fix
Count actual replacements instead of comparing strings: throw only when the
versionfield is genuinely absent (count === 0), and treat an already-correct value as success (idempotent). MirrorsupdateConstantVersion().Verification (local, PHP 8.5)
featmerge exits 0 with correct outputs and leavescomposer.json/Constant.phpbyte-identical when already at target.versionfield still throws (count === 0).Recovery after merging this
This PR is titled
ci:on purpose so merging it does not auto-trigger a release (the stale tag would otherwise drive the version).After merge, reconcile the tag/composer drift and ship the pending
v7.3.0via the manual path (works becauseuse_current_version=trueskips the version bump entirely):That tags
v7.3.0at master, creates the GitHub release, and updates Packagist. From then on the flow is monotonic again (tagv7.3.0-> next feat7.4.0, fix7.3.1).Process note: avoid hand-editing the
versionfield incomposer.json/Constant.phpinside feature PRs; the release automation owns those fields.