Set app version from git info

This commit is contained in:
Alex X
2025-12-18 19:02:10 +03:00
parent 753d6617ab
commit 079d404ed0
2 changed files with 11 additions and 1 deletions
+10 -1
View File
@@ -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"
} }
} }
} }
+1
View File
@@ -49,6 +49,7 @@ import (
) )
func main() { func main() {
// version will be set later from -buildvcs info, this used only as fallback
app.Version = "1.9.13" app.Version = "1.9.13"
type module struct { type module struct {