Better semver compliance for version reporting

main
Neil Alexander 2020-10-14 12:51:06 +01:00
parent 7a1fd123de
commit 286dd408ae
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
1 changed files with 24 additions and 8 deletions

View File

@ -1,6 +1,12 @@
package internal package internal
import "fmt" import (
"fmt"
"strings"
)
// the final version string
var version string
// -ldflags "-X github.com/matrix-org/dendrite/internal.branch=master" // -ldflags "-X github.com/matrix-org/dendrite/internal.branch=master"
var branch string var branch string
@ -16,12 +22,22 @@ const (
) )
func VersionString() string { func VersionString() string {
version := fmt.Sprintf("%d.%d.%d%s", VersionMajor, VersionMinor, VersionPatch, VersionTag)
if branch != "" {
version += fmt.Sprintf("-%s", branch)
}
if build != "" {
version += fmt.Sprintf("+%s", build)
}
return version return version
} }
func init() {
version = fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
if VersionTag != "" {
version += "-" + VersionTag
}
parts := []string{}
if build != "" {
parts = append(parts, build)
}
if branch != "" {
parts = append(parts, branch)
}
if len(parts) > 0 {
version += "+" + strings.Join(parts, ".")
}
}