From 264c6b10e1ebdcaed8e83f86cd85c20589961839 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 14 Sep 2016 18:06:21 -0700 Subject: [PATCH] feat(*): add git tree state to binaries * clean up version output --- cmd/helm/version.go | 4 ++-- cmd/tiller/release_server.go | 2 +- pkg/helm/client.go | 2 +- pkg/version/version.go | 44 +++++++++++++++++++----------------- versioning.mk | 4 +++- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/cmd/helm/version.go b/cmd/helm/version.go index 9c66cea00..e22d0a800 100644 --- a/cmd/helm/version.go +++ b/cmd/helm/version.go @@ -52,12 +52,12 @@ func (v *versionCmd) run() error { // Regardless of whether we can talk to server or not, just print the client // version. cv := version.GetVersionProto() - fmt.Fprintf(v.out, "Client: {SemVer: %s GitCommit: %s}\n", cv.SemVer, cv.GitCommit) + fmt.Fprintf(v.out, "Client: %#v\n", cv) resp, err := v.client.GetVersion() if err != nil { return err } - fmt.Fprintf(v.out, "Server: {SemVer: %s GitCommit: %s}\n", resp.Version.SemVer, resp.Version.GitCommit) + fmt.Fprintf(v.out, "Server: %#v\n", resp.Version) return nil } diff --git a/cmd/tiller/release_server.go b/cmd/tiller/release_server.go index 678570841..3d8267715 100644 --- a/cmd/tiller/release_server.go +++ b/cmd/tiller/release_server.go @@ -178,7 +178,7 @@ func filterReleases(filter string, rels []*release.Release) ([]*release.Release, func (s *releaseServer) GetVersion(c ctx.Context, req *services.GetVersionRequest) (*services.GetVersionResponse, error) { v := version.GetVersionProto() - return &services.GetVersionResponse{Version: &v}, nil + return &services.GetVersionResponse{Version: v}, nil } func (s *releaseServer) GetReleaseStatus(c ctx.Context, req *services.GetReleaseStatusRequest) (*services.GetReleaseStatusResponse, error) { diff --git a/pkg/helm/client.go b/pkg/helm/client.go index ce08bd6b1..bf55562a0 100644 --- a/pkg/helm/client.go +++ b/pkg/helm/client.go @@ -120,7 +120,7 @@ func (h *Client) UpdateRelease(rlsName string, chStr string, opts ...UpdateOptio return h.opts.rpcUpdateRelease(rlsName, chart, rls.NewReleaseServiceClient(c), opts...) } -// Version returns the server version +// GetVersion returns the server version // // Note: there aren't currently any supported StatusOptions, // but they are kept in the API signature as a placeholder for future additions. diff --git a/pkg/version/version.go b/pkg/version/version.go index ba36c3d4c..eb96bd7c8 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -17,26 +17,27 @@ limitations under the License. // Package version represents the current version of the project. package version // import "k8s.io/helm/pkg/version" -import ( - "k8s.io/helm/pkg/proto/hapi/version" +import "k8s.io/helm/pkg/proto/hapi/version" + +var ( + // 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.0.0-alpha.4" + + // BuildMetadata is extra build time data + BuildMetadata = "" + // GitCommit is the git sha1 + GitCommit = "" + // GitTreeState is the state of the git tree + GitTreeState = "" ) -// 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. -// -// BuildMetadata gets filled in during build, do not touch -// GitCommit gets filled in during build, do not touch -var Version = "v2.0.0-alpha.4" -var BuildMetadata = "" -var GitCommit = "" - // GetVersion returns the semver string of the version - func GetVersion() string { if BuildMetadata == "" { return Version @@ -45,9 +46,10 @@ func GetVersion() string { } // GetVersionProto returns protobuf representing the version -func GetVersionProto() version.Version { - return version.Version{ - SemVer: GetVersion(), - GitCommit: GitCommit, +func GetVersionProto() *version.Version { + return &version.Version{ + SemVer: GetVersion(), + GitCommit: GitCommit, + GitTreeState: GitTreeState, } } diff --git a/versioning.mk b/versioning.mk index 94f3ceaa8..4825c4e72 100644 --- a/versioning.mk +++ b/versioning.mk @@ -3,6 +3,7 @@ MUTABLE_VERSION ?= canary GIT_COMMIT := $(shell git rev-parse HEAD) GIT_SHA := $(shell git rev-parse --short HEAD) GIT_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null) +GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean") ifdef VERSION DOCKER_VERSION = $(VERSION) @@ -15,8 +16,9 @@ BINARY_VERSION ?= ${GIT_TAG}-${GIT_SHA} IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${SHORT_NAME}:${DOCKER_VERSION} MUTABLE_IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${SHORT_NAME}:${MUTABLE_VERSION} -LDFLAGS += -X k8s.io/helm/pkg/version.SemVer=${GIT_TAG} +LDFLAGS += -X k8s.io/helm/pkg/version.Version=${GIT_TAG} LDFLAGS += -X k8s.io/helm/pkg/version.GitCommit=${GIT_COMMIT} +LDFLAGS += -X k8s.io/helm/pkg/version.GitTreeState=${GIT_DIRTY} DOCKER_PUSH = docker push ifeq ($(DOCKER_REGISTRY),gcr.io)