Merge pull request #5869 from bacongobbler/ref-version

ref(version): catch some edge cases
pull/5874/head
Matthew Fisher 5 years ago committed by GitHub
commit f109b1ba5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1 @@
v3.0+unreleased

@ -1 +1 @@
version.BuildInfo{Version:"v3.0+unreleased", GitCommit:"", GitTreeState:"", GoVersion:"go1.12.5"}
version.BuildInfo{Version:"v3.0+unreleased", GitCommit:"", GitTreeState:"", GoVersion:""}

@ -80,7 +80,10 @@ func (o *versionOptions) run(out io.Writer) error {
func formatVersion(short bool) string {
v := version.Get()
if short {
return fmt.Sprintf("%s+g%s", v.Version, v.GitCommit[:7])
if len(v.GitCommit) >= 7 {
return fmt.Sprintf("%s+g%s", v.Version, v.GitCommit[:7])
}
return version.GetVersion()
}
return fmt.Sprintf("%#v", v)
}

@ -24,6 +24,10 @@ func TestVersion(t *testing.T) {
name: "default",
cmd: "version",
golden: "output/version.txt",
}, {
name: "short",
cmd: "version --short",
golden: "output/version-short.txt",
}, {
name: "template",
cmd: "version --template='Version: {{.Version}}'",

@ -17,6 +17,7 @@ limitations under the License.
package version // import "helm.sh/helm/internal/version"
import (
"flag"
"runtime"
hversion "helm.sh/helm/pkg/version"
@ -50,10 +51,16 @@ func GetVersion() string {
// Get returns build info
func Get() hversion.BuildInfo {
return hversion.BuildInfo{
v := hversion.BuildInfo{
Version: GetVersion(),
GitCommit: gitCommit,
GitTreeState: gitTreeState,
GoVersion: runtime.Version(),
}
// HACK(bacongobbler): strip out GoVersion during a test run for consistent test output
if flag.Lookup("test.v") != nil {
v.GoVersion = ""
}
return v
}

Loading…
Cancel
Save