2020-09-02 10:18:08 -05:00
|
|
|
package internal
|
|
|
|
|
2020-10-14 06:51:06 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
2023-07-11 06:56:25 -05:00
|
|
|
"runtime/debug"
|
2020-10-14 06:51:06 -05:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// the final version string
|
|
|
|
var version string
|
2020-09-02 10:18:08 -05:00
|
|
|
|
|
|
|
// -ldflags "-X github.com/matrix-org/dendrite/internal.branch=master"
|
|
|
|
var branch string
|
|
|
|
|
|
|
|
// -ldflags "-X github.com/matrix-org/dendrite/internal.build=alpha"
|
|
|
|
var build string
|
|
|
|
|
|
|
|
const (
|
|
|
|
VersionMajor = 0
|
2023-06-30 01:49:37 -05:00
|
|
|
VersionMinor = 13
|
2023-08-23 09:24:16 -05:00
|
|
|
VersionPatch = 2
|
2022-05-09 11:31:14 -05:00
|
|
|
VersionTag = "" // example: "rc1"
|
2023-07-11 06:56:25 -05:00
|
|
|
|
|
|
|
gitRevLen = 7 // 7 matches the displayed characters on github.com
|
2020-09-02 10:18:08 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func VersionString() string {
|
2020-10-14 06:51:06 -05:00
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
version = fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
|
|
|
|
if VersionTag != "" {
|
|
|
|
version += "-" + VersionTag
|
2020-09-02 10:18:08 -05:00
|
|
|
}
|
2020-10-14 06:51:06 -05:00
|
|
|
parts := []string{}
|
2020-09-02 10:18:08 -05:00
|
|
|
if build != "" {
|
2020-10-14 06:51:06 -05:00
|
|
|
parts = append(parts, build)
|
|
|
|
}
|
|
|
|
if branch != "" {
|
|
|
|
parts = append(parts, branch)
|
|
|
|
}
|
2023-07-11 06:56:25 -05:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if len(parts) > 0 {
|
|
|
|
version += "+" + strings.Join(parts, ".")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Try to get the revision Dendrite was build from.
|
|
|
|
// If we can't, e.g. Dendrite wasn't built (go run) or no VCS version is present,
|
|
|
|
// we just use the provided version above.
|
|
|
|
info, ok := debug.ReadBuildInfo()
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, setting := range info.Settings {
|
|
|
|
if setting.Key == "vcs.revision" {
|
|
|
|
revLen := len(setting.Value)
|
|
|
|
if revLen >= gitRevLen {
|
|
|
|
parts = append(parts, setting.Value[:gitRevLen])
|
|
|
|
} else {
|
|
|
|
parts = append(parts, setting.Value[:revLen])
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
2020-09-02 10:18:08 -05:00
|
|
|
}
|
|
|
|
}
|