mirror of
https://github.com/passbolt/go-passbolt-cli.git
synced 2025-09-13 06:59:07 +00:00
Use goreleaser version if available, otherwise buildinfo
This commit is contained in:
parent
b269e8538d
commit
b48f3274e6
3 changed files with 48 additions and 6 deletions
41
version.go
Normal file
41
version.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "unknown"
|
||||
commit = "unknown"
|
||||
date = "unknown"
|
||||
dirty = false
|
||||
)
|
||||
|
||||
func init() {
|
||||
// if not set by goreleaser, use buildinfo instead
|
||||
if version == "unknown" {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if info.Main.Version != "" {
|
||||
version = info.Main.Version
|
||||
}
|
||||
|
||||
for _, kv := range info.Settings {
|
||||
if kv.Value == "" {
|
||||
continue
|
||||
}
|
||||
switch kv.Key {
|
||||
case "vcs.revision":
|
||||
commit = kv.Value
|
||||
case "vcs.time":
|
||||
d, _ := time.Parse(time.RFC3339, kv.Value)
|
||||
date = d.String()
|
||||
case "vcs.modified":
|
||||
dirty = kv.Value == "true"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue