version: retain prerelease suffix in Semver comparisons - #35
Merged
Merged
Conversation
ParseSemver discarded everything after the first hyphen, so v1.2.3-rc1 and v1.2.3 parsed to the same value. Both the latest-release comparison and the exact-pin equality check in checkPinnedVersion therefore treated a prerelease and its matching release as interchangeable. Semver now carries the prerelease identifiers in a Pre field, build metadata is stripped before parsing, and Compare implements semantic version precedence: the numeric triple first, then the prerelease suffix, with a suffixed version sorting below the plain release. NewerThan delegates to Compare and String round-trips the suffix. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
M25 — Updater version pinning ignores prerelease suffix
ParseSemver(version.go:23) discarded everything after the first hyphen, sov1.2.3-rc1andv1.2.3parsed to the identicalSemver{1,2,3}. Two call sites depended on that value:updater.go:231—latest.NewerThan(current): withv1.2.3-rc1installed, the realv1.2.3release compared equal and was never installed.updater.go:265—current == pinnedincheckPinnedVersion: an exact pin tov1.2.3was satisfied by an installedv1.2.3-rc1, and vice versa..pilot-versionalready stores the raw tag (release.TagName), so the suffix was present on disk and only lost at parse time.Change
Semvergains aPrefield holding the prerelease identifiers after the first hyphen.+buildmetadata is stripped before parsing (it takes no part in precedence), sov1.2.3+build.7still equalsv1.2.3.Compareimplements semver precedence: numeric triple first, then the prerelease suffix, with a suffixed version sorting below the plain release. Identifiers are split on.; all-digit identifiers compare numerically and sort before alphanumeric ones.NewerThandelegates toCompare;Stringround-trips the suffix.No wire or on-disk format change — the version file contents and the GitHub API shapes are untouched.
Semvergrows a field, so the in-repo positional composite literals in the tests were updated.Tests
Table tests extended in
zz_test.go/zz_more_test.go:TestParseSemver—-dirty,-rc1,-beta.2,+build.7,-rc.1+build.7.TestSemverNewerThan— 13 new pairs covering1.2.3-rc1 < 1.2.3,rc1 < rc2,beta.9 < rc.1,rc.1 < rc.1.1, numeric-before-alphanumeric, and build-metadata equality.TestSemverPinEquality(new) — asserts an exact pin only matches the same suffix, mirroring thecheckPinnedVersionequality check.go build ./...,go vet ./...andgo test ./...all green.Base branch note
The task named
fix/gh-free-attestationas the base. That branch exists only locally — its commit is already squash-merged intomainas 5588eb0 — so this PR is rebased onto and targetsmainto avoid re-proposing merged work.🤖 Generated with Claude Code