Set app version from git info
This commit is contained in:
+10
-1
@@ -7,6 +7,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -91,6 +92,14 @@ func Init() {
|
|||||||
|
|
||||||
func readRevisionTime() (revision, vcsTime string) {
|
func readRevisionTime() (revision, vcsTime string) {
|
||||||
if info, ok := debug.ReadBuildInfo(); ok {
|
if info, ok := debug.ReadBuildInfo(); ok {
|
||||||
|
// Rewrite version from -buildvcs info if it is valid.
|
||||||
|
// Format for tagged version: v1.9.13
|
||||||
|
// Format for custom commit: v1.9.14-0.20251215184105-753d6617ab58
|
||||||
|
// Format for modified code: v1.9.14-0.20251215184105-753d6617ab58+dirty
|
||||||
|
if s, ok := strings.CutPrefix(info.Main.Version, "v"); ok {
|
||||||
|
Version = s
|
||||||
|
}
|
||||||
|
|
||||||
for _, setting := range info.Settings {
|
for _, setting := range info.Settings {
|
||||||
switch setting.Key {
|
switch setting.Key {
|
||||||
case "vcs.revision":
|
case "vcs.revision":
|
||||||
@@ -103,7 +112,7 @@ func readRevisionTime() (revision, vcsTime string) {
|
|||||||
vcsTime = setting.Value
|
vcsTime = setting.Value
|
||||||
case "vcs.modified":
|
case "vcs.modified":
|
||||||
if setting.Value == "true" {
|
if setting.Value == "true" {
|
||||||
revision = "mod." + revision
|
revision += "+dirty"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user