mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-02 03:29:07 +02:00
Adds commit sha to development version for cobra command only
Leave dashboard unaffected
This commit is contained in:
@@ -12,7 +12,13 @@ var (
|
|||||||
Short: "Print the NetBird's client application version",
|
Short: "Print the NetBird's client application version",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmd.SetOut(cmd.OutOrStdout())
|
cmd.SetOut(cmd.OutOrStdout())
|
||||||
cmd.Println(version.NetbirdVersion())
|
out := version.NetbirdVersion()
|
||||||
|
if version.IsDevelopmentVersion(out) {
|
||||||
|
if commit := version.NetbirdCommit(); commit != "" {
|
||||||
|
out += "-" + commit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmd.Println(out)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package version
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
v "github.com/hashicorp/go-version"
|
v "github.com/hashicorp/go-version"
|
||||||
@@ -27,6 +28,41 @@ func NetbirdVersion() string {
|
|||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetbirdCommit returns the VCS revision (truncated to 12 chars) of the
|
||||||
|
// build, with a "-dirty" suffix when the working tree was modified.
|
||||||
|
// Returns an empty string when no build info is embedded (e.g. release
|
||||||
|
// builds compiled by goreleaser without -buildvcs).
|
||||||
|
func NetbirdCommit() string {
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var revision string
|
||||||
|
var modified bool
|
||||||
|
for _, s := range info.Settings {
|
||||||
|
switch s.Key {
|
||||||
|
case "vcs.revision":
|
||||||
|
revision = s.Value
|
||||||
|
case "vcs.modified":
|
||||||
|
modified = s.Value == "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if revision == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(revision) > 12 {
|
||||||
|
revision = revision[:12]
|
||||||
|
}
|
||||||
|
|
||||||
|
if modified {
|
||||||
|
revision += "-dirty"
|
||||||
|
}
|
||||||
|
return revision
|
||||||
|
}
|
||||||
|
|
||||||
// IsDevelopmentVersion reports whether the given version string identifies
|
// IsDevelopmentVersion reports whether the given version string identifies
|
||||||
// a non-release / development build. It is the single source of truth for
|
// a non-release / development build. It is the single source of truth for
|
||||||
// "is this a dev build" checks across the codebase; use it instead of
|
// "is this a dev build" checks across the codebase; use it instead of
|
||||||
|
|||||||
Reference in New Issue
Block a user