Merge pull request #4023 from adamreese/dev-v3-build-info

ref(*): rebuild build version object
pull/4024/head
Adam Reese 7 years ago committed by GitHub
commit 259fd3622c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,10 +31,10 @@ endif
# Clear the "unreleased" string in BuildMetadata
ifneq ($(GIT_TAG),)
LDFLAGS += -X k8s.io/helm/pkg/version.BuildMetadata=
LDFLAGS += -X k8s.io/helm/pkg/version.metadata=
endif
LDFLAGS += -X k8s.io/helm/pkg/version.GitCommit=${GIT_COMMIT}
LDFLAGS += -X k8s.io/helm/pkg/version.GitTreeState=${GIT_DIRTY}
LDFLAGS += -X k8s.io/helm/pkg/version.gitCommit=${GIT_COMMIT}
LDFLAGS += -X k8s.io/helm/pkg/version.gitTreeState=${GIT_DIRTY}
.PHONY: all
all: build

@ -205,7 +205,7 @@ func (p *packageCmd) run() error {
}
func setVersion(ch *chart.Chart, ver string) error {
// Verify that version is a SemVer, and error out if it is not.
// Verify that version is a Version, and error out if it is not.
if _, err := semver.NewVersion(ver); err != nil {
return err
}

@ -191,7 +191,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
caps := &chartutil.Capabilities{
APIVersions: chartutil.DefaultVersionSet,
KubeVersion: chartutil.DefaultKubeVersion,
HelmVersion: tversion.GetVersionProto(),
HelmVersion: tversion.GetBuildInfo(),
}
// kubernetes version

@ -31,9 +31,9 @@ Show the version for Helm.
This will print a representation the version of Helm.
The output will look something like this:
Client: &version.Version{SemVer:"v2.0.0", GitCommit:"ff52399e51bb880526e9cd0ed8386f6433b74da1", GitTreeState:"clean"}
Client: &version.BuildInfo{Version:"v2.0.0", GitCommit:"ff52399e51bb880526e9cd0ed8386f6433b74da1", GitTreeState:"clean"}
- SemVer is the semantic version of the release.
- Version is the semantic version of the release.
- GitCommit is the SHA for the commit that this version was built from.
- GitTreeState is "clean" if there are no local code changes when this binary was
built, and "dirty" if the binary was built from locally modified code.
@ -67,7 +67,7 @@ func (v *versionCmd) run() error {
// Store map data for template rendering
data := map[string]interface{}{}
cv := version.GetVersionProto()
cv := version.GetBuildInfo()
if v.template != "" {
data["Client"] = cv
return tpl(v.template, data, v.out)
@ -76,9 +76,9 @@ func (v *versionCmd) run() error {
return nil
}
func formatVersion(v *version.Version, short bool) string {
func formatVersion(v *version.BuildInfo, short bool) string {
if short {
return fmt.Sprintf("%s+g%s", v.SemVer, v.GitCommit[:7])
return fmt.Sprintf("%s+g%s", v.Version, v.GitCommit[:7])
}
return fmt.Sprintf("%#v", v)
}

@ -24,8 +24,8 @@ import (
)
func TestVersion(t *testing.T) {
lver := regexp.QuoteMeta(version.GetVersionProto().SemVer)
clientVersion := fmt.Sprintf("Client: &version\\.Version{SemVer:\"%s\", GitCommit:\"\", GitTreeState:\"\"}\n", lver)
lver := regexp.QuoteMeta(version.GetVersion())
clientVersion := fmt.Sprintf("Client: &version\\.BuildInfo{Version:\"%s\", GitCommit:\"\", GitTreeState:\"\"}\n", lver)
tests := []releaseCase{
{
@ -35,7 +35,7 @@ func TestVersion(t *testing.T) {
},
{
name: "template",
cmd: "version --template='{{.Client.SemVer}}'",
cmd: "version --template='{{.Client.Version}}'",
matches: lver,
},
}

@ -47,8 +47,8 @@ type Capabilities struct {
KubeVersion *version.Info
// HelmVersion is the Helm version
//
// This always comes from pkg/version.GetVersionProto().
HelmVersion *tversion.Version
// This always comes from pkg/version.BuildInfo().
HelmVersion *tversion.BuildInfo
}
// VersionSet is a set of Kubernetes API versions.

@ -112,7 +112,7 @@ where:
caps := &Capabilities{
APIVersions: DefaultVersionSet,
HelmVersion: version.GetVersionProto(),
HelmVersion: version.GetBuildInfo(),
KubeVersion: &kversion.Info{Major: "1"},
}
@ -144,7 +144,7 @@ where:
if !res["Capabilities"].(*Capabilities).APIVersions.Has("v1") {
t.Error("Expected Capabilities to have v1 as an API")
}
if res["Capabilities"].(*Capabilities).HelmVersion.SemVer == "" {
if res["Capabilities"].(*Capabilities).HelmVersion.Version == "" {
t.Error("Expected Capabilities to have a Tiller version")
}
if res["Capabilities"].(*Capabilities).KubeVersion.Major != "1" {

@ -56,7 +56,7 @@ func Templates(linter *support.Linter, values []byte, namespace string, strict b
caps := &chartutil.Capabilities{
APIVersions: chartutil.DefaultVersionSet,
KubeVersion: chartutil.DefaultKubeVersion,
HelmVersion: tversion.GetVersionProto(),
HelmVersion: tversion.GetBuildInfo(),
}
cvals, err := chartutil.CoalesceValues(chart, values)
if err != nil {

@ -232,7 +232,7 @@ func capabilities(disc discovery.DiscoveryInterface) (*chartutil.Capabilities, e
return &chartutil.Capabilities{
APIVersions: vs,
KubeVersion: sv,
HelmVersion: version.GetVersionProto(),
HelmVersion: version.GetBuildInfo(),
}, nil
}

@ -17,43 +17,45 @@ limitations under the License.
package version // import "k8s.io/helm/pkg/version"
var (
// Version is the current version of the Helm.
// version is the current version of the Helm.
// Update this whenever making a new release.
// The version is of the format Major.Minor.Patch[-Prerelease][+BuildMetadata]
//
// Increment major number for new feature additions and behavioral changes.
// Increment minor number for bug fixes and performance enhancements.
// Increment patch number for critical fixes to existing releases.
version = "v2.8"
// BuildMetadata is extra build time data
BuildMetadata = "unreleased"
// GitCommit is the git sha1
GitCommit = ""
// GitTreeState is the state of the git tree
GitTreeState = ""
version = "v3.0"
// metadata is extra build time data
metadata = "unreleased"
// gitCommit is the git sha1
gitCommit = ""
// gitTreeState is the state of the git tree
gitTreeState = ""
)
// GetVersion returns the semver string of the version
func GetVersion() string {
if BuildMetadata == "" {
if metadata == "" {
return version
}
return version + "+" + BuildMetadata
return version + "+" + metadata
}
type Version struct {
// Sem ver string for the version
SemVer string `json:"sem_ver,omitempty"`
GitCommit string `json:"git_commit,omitempty"`
type BuildInfo struct {
// Version is the current semver.
Version string `json:"version,omitempty"`
// GitCommit is the git sha1
GitCommit string `json:"git_commit,omitempty"`
// GitTreeState is the state of the git tree
GitTreeState string `json:"git_tree_state,omitempty"`
}
// GetVersionProto returns protobuf representing the version
func GetVersionProto() *Version {
return &Version{
SemVer: GetVersion(),
GitCommit: GitCommit,
GitTreeState: GitTreeState,
// GetBuildInfo returns build info
func GetBuildInfo() *BuildInfo {
return &BuildInfo{
Version: GetVersion(),
GitCommit: gitCommit,
GitTreeState: gitTreeState,
}
}

@ -19,27 +19,27 @@ package version // import "k8s.io/helm/pkg/version"
import "testing"
func TestGetVersionProto(t *testing.T) {
func TestBuildInfo(t *testing.T) {
tests := []struct {
version string
buildMetadata string
gitCommit string
gitTreeState string
expected Version
expected BuildInfo
}{
{"", "", "", "", Version{SemVer: "", GitCommit: "", GitTreeState: ""}},
{"v1.0.0", "", "", "", Version{SemVer: "v1.0.0", GitCommit: "", GitTreeState: ""}},
{"v1.0.0", "79d5c5f7", "", "", Version{SemVer: "v1.0.0+79d5c5f7", GitCommit: "", GitTreeState: ""}},
{"v1.0.0", "79d5c5f7", "0d399baec2acda578a217d1aec8d7d707c71e44d", "", Version{SemVer: "v1.0.0+79d5c5f7", GitCommit: "0d399baec2acda578a217d1aec8d7d707c71e44d", GitTreeState: ""}},
{"v1.0.0", "79d5c5f7", "0d399baec2acda578a217d1aec8d7d707c71e44d", "clean", Version{SemVer: "v1.0.0+79d5c5f7", GitCommit: "0d399baec2acda578a217d1aec8d7d707c71e44d", GitTreeState: "clean"}},
{"", "", "", "", BuildInfo{Version: "", GitCommit: "", GitTreeState: ""}},
{"v1.0.0", "", "", "", BuildInfo{Version: "v1.0.0", GitCommit: "", GitTreeState: ""}},
{"v1.0.0", "79d5c5f7", "", "", BuildInfo{Version: "v1.0.0+79d5c5f7", GitCommit: "", GitTreeState: ""}},
{"v1.0.0", "79d5c5f7", "0d399baec2acda578a217d1aec8d7d707c71e44d", "", BuildInfo{Version: "v1.0.0+79d5c5f7", GitCommit: "0d399baec2acda578a217d1aec8d7d707c71e44d", GitTreeState: ""}},
{"v1.0.0", "79d5c5f7", "0d399baec2acda578a217d1aec8d7d707c71e44d", "clean", BuildInfo{Version: "v1.0.0+79d5c5f7", GitCommit: "0d399baec2acda578a217d1aec8d7d707c71e44d", GitTreeState: "clean"}},
}
for _, tt := range tests {
version = tt.version
BuildMetadata = tt.buildMetadata
GitCommit = tt.gitCommit
GitTreeState = tt.gitTreeState
if versionProto := GetVersionProto(); *versionProto != tt.expected {
t.Errorf("expected Semver(%s), GitCommit(%s) and GitTreeState(%s) to be %v", tt.expected, tt.gitCommit, tt.gitTreeState, *versionProto)
metadata = tt.buildMetadata
gitCommit = tt.gitCommit
gitTreeState = tt.gitTreeState
if versionProto := GetBuildInfo(); *versionProto != tt.expected {
t.Errorf("expected Version(%s), GitCommit(%s) and GitTreeState(%s) to be %v", tt.expected, tt.gitCommit, tt.gitTreeState, *versionProto)
}
}

Loading…
Cancel
Save