-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
49 lines (41 loc) · 906 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package sindri
import (
"runtime/debug"
"strings"
)
// VersionCore is the SemVer version core of sindri.
// Meant to be be overridden at build time, but kept
// up-to-date sometimes to best support `go install`.
var VersionCore = "2.0.0"
// SemVer returns the semantic version of forge as built
// from VersionCore and debug build info.
func SemVer() string {
semver := VersionCore
if buildInfo, ok := debug.ReadBuildInfo(); ok {
var (
revision string
modified bool
)
for _, setting := range buildInfo.Settings {
switch setting.Key {
case "vcs.revision":
revision = setting.Value
case "vcs.modified":
modified = setting.Value == "true"
}
}
if revision != "" {
i := len(revision)
if i > 7 {
i = 7
}
if !strings.Contains(semver, revision[:i]) {
semver += "+" + revision[:i]
}
}
if modified {
semver += "*"
}
}
return semver
}