Skip to content

Commit

Permalink
chore: set version when built outside makefile
Browse files Browse the repository at this point in the history
close #103
  • Loading branch information
ncarlier committed Aug 11, 2024
1 parent 361770b commit 0c41f76
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package version
import (
"flag"
"fmt"
"runtime/debug"
"time"
)

// Version of the app
Expand All @@ -28,3 +30,26 @@ This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
`, Version, GitCommit, Built)
}

func init() {
if GitCommit != "snapshot" {
return
}
info, ok := debug.ReadBuildInfo()
if !ok {
return
}
Version = info.Main.Version
for _, kv := range info.Settings {
if kv.Value == "" {
continue
}
switch kv.Key {
case "vcs.revision":
GitCommit = kv.Value[:7]
case "vcs.time":
lastCommit, _ := time.Parse(time.RFC3339, kv.Value)
Built = lastCommit.Format(time.RFC1123)
}
}
}

0 comments on commit 0c41f76

Please sign in to comment.