fix(semver): skip non-semver tags when picking latest existing tag

Rolling tags like 'v1' (and any other tag that doesn't parse as x.y.z
after prefix stripping) used to enter the latest-tag candidate set in
CalculateSemver. When such a tag shared a commit with a real semver tag
(e.g. v1 and v1.16.3 both pointing at the same release commit), go-git's
alphabetical tag iteration made 'v1' win, ParseExistingSemver bailed out
because '1' has only one component, and the calculator silently reset
the baseline to 0.0.0 — producing nonsense like 0.0.5 on this branch.

ListExistingTags now filters tags through a new IsParseableSemverTag
helper before recording them, so non-semver tags never participate in
latest-tag selection. The behavior change is invisible for repos that
only use proper vX.Y.Z tags, and it's covered by a new test table.
This commit is contained in:
2026-05-22 00:39:59 +01:00
parent ab52de167e
commit dfeb03b8bb
5 changed files with 64 additions and 8 deletions
+23
View File
@@ -83,6 +83,29 @@ func StripTagPrefix(tagName string, prefixes []string) string {
return result
}
// IsParseableSemverTag reports whether tagName looks like a proper semver tag
// (X.Y.Z, optionally vX.Y.Z, optionally with -rc.N suffix) after configured
// prefixes are stripped. Rolling tags like "v1" or "latest" return false so the
// calculator can skip them when picking the latest existing tag — preventing a
// rolling tag tied to the same commit as a real semver tag from "winning" the
// alphabetical iteration in go-git and resetting the baseline to 0.0.0.
func IsParseableSemverTag(tagName string, prefixes []string) bool {
clean := StripTagPrefix(tagName, prefixes)
if idx := strings.Index(clean, "-rc."); idx != -1 {
clean = clean[:idx]
}
parts := strings.Split(clean, ".")
if len(parts) < 3 {
return false
}
for _, p := range parts[:3] {
if len(extractNumber.FindAllString(p, -1)) == 0 {
return false
}
}
return true
}
// ParseExistingSemver parses a semantic version from a tag name
func ParseExistingSemver(tagName string, currentSemver SemVer, prefixes []string) SemVer {
Debug("Parsing existing semver", map[string]interface{}{"tag": tagName})