fix(version): don't add "v" prefix to non-semver VERSION strings
When VERSION is set to a non-tag value like "main" (from goreleaser or ldflags), the init() function unconditionally prepended "v", producing "vmain". Now only add the "v" prefix when doing so produces a valid semver string, leaving branch names and other non-semver values as-is.
This commit is contained in:
@@ -90,10 +90,13 @@ func init() {
|
||||
VERSION = "dev-snapshot"
|
||||
} else {
|
||||
if !strings.HasPrefix(VERSION, "v") {
|
||||
VERSION = "v" + VERSION
|
||||
vVersion := "v" + VERSION
|
||||
if semver.IsValid(vVersion) {
|
||||
VERSION = vVersion
|
||||
}
|
||||
}
|
||||
if !semver.IsValid(VERSION) {
|
||||
slog.Default().Warn("invalid version number", "version", VERSION)
|
||||
if !semver.IsValid(VERSION) && VERSION != "dev-snapshot" {
|
||||
slog.Default().Info("non-semver version", "version", VERSION)
|
||||
}
|
||||
}
|
||||
if bi, ok := debug.ReadBuildInfo(); ok {
|
||||
|
||||
Reference in New Issue
Block a user