mirror of
https://github.com/lukaszraczylo/semver-generator.git
synced 2026-06-08 23:03:44 +00:00
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:
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user