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

Better semver compliance for version reporting