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

View File

@@ -7,6 +7,7 @@ import (
"os/exec"
"runtime"
"runtime/debug"
"strings"
)
var (
@@ -91,6 +92,14 @@ func Init() {
func readRevisionTime() (revision, vcsTime string) {
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 {
switch setting.Key {
case "vcs.revision":
@@ -103,7 +112,7 @@ func readRevisionTime() (revision, vcsTime string) {
vcsTime = setting.Value
case "vcs.modified":
if setting.Value == "true" {
revision = "mod." + revision
revision += "+dirty"
}
}
}

View File

@@ -49,6 +49,7 @@ import (
)
func main() {
// version will be set later from -buildvcs info, this used only as fallback
app.Version = "1.9.13"
type module struct {