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
+28
View File
@@ -189,6 +189,34 @@ func TestParseExistingSemver(t *testing.T) {
})
}
}
func TestIsParseableSemverTag(t *testing.T) {
InitLogger(false)
tests := []struct {
name string
tag string
prefixes []string
want bool
}{
{name: "plain x.y.z", tag: "1.2.3", want: true},
{name: "v prefix", tag: "v1.16.5", want: true},
{name: "v prefix with rc", tag: "v2.0.0-rc.3", want: true},
{name: "configured app- prefix", tag: "app-1.2.3", prefixes: []string{"app-"}, want: true},
{name: "rolling v1 tag", tag: "v1", want: false},
{name: "rolling latest tag", tag: "latest", want: false},
{name: "two-component", tag: "1.2", want: false},
{name: "empty", tag: "", want: false},
{name: "non-numeric major", tag: "vX.Y.Z", want: false},
{name: "just text", tag: "release-day", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, IsParseableSemverTag(tt.tag, tt.prefixes))
})
}
}
func TestCheckMatches(t *testing.T) {
// Initialize logger for tests