build: set git metadata via `debug.BuildInfo`

Signed-off-by: Branch Vincent <branchevincent@gmail.com>
pull/13180/head
Branch Vincent 1 year ago
parent f09a9b92bd
commit 7af094d606
No known key found for this signature in database

@ -19,6 +19,7 @@ package version // import "helm.sh/helm/v3/internal/version"
import (
"flag"
"runtime"
"runtime/debug"
"strings"
)
@ -79,3 +80,22 @@ func Get() BuildInfo {
}
return v
}
func init() {
if gitCommit != "" || gitTreeState != "" {
return
}
info, ok := debug.ReadBuildInfo()
if !ok {
return
}
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" && setting.Value != "" {
gitCommit = setting.Value
} else if setting.Key == "vcs.modified" && setting.Value == "true" {
gitTreeState = "dirty"
} else if setting.Key == "vcs.modified" && setting.Value == "false" {
gitTreeState = "clean"
}
}
}

Loading…
Cancel
Save