Skip to content

Commit

Permalink
Fix version lookup (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo authored Nov 2, 2023
1 parent 7f726e8 commit 1b8e930
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
package version

import (
"runtime"
"runtime/debug"
)

var (
// Name is the name of the binary.
Name = "ratchet"

// Version is the main package version.
Version = "unknown"
Version = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
if v := info.Main.Version; v != "" {
return v // e.g. "v0.0.1-alpha6.0.20230815191505-8628f8201363"
}
}

return "source"
}()

// Commit is the git sha.
Commit = "unknown"
Commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}

return "HEAD"
}()

// OSArch returns the denormalized operating system and architecture.
OSArch = func() string {
return runtime.GOOS + "/" + runtime.GOARCH
}()

// HumanVersion is the compiled version.
HumanVersion = Name + " v" + Version + " (" + Commit + ")"
HumanVersion = Name + " " + Version + " (" + Commit + ", " + OSArch + ")"
)

0 comments on commit 1b8e930

Please sign in to comment.