Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #304 from cben/version
Browse files Browse the repository at this point in the history
version: Move vX.Y.Z to version.go so it works with `go get`, add git info
  • Loading branch information
nkubala committed Apr 1, 2019
2 parents 4fb337a + 91e0989 commit 367eb42
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Bump these on release
VERSION_MAJOR ?= 0
VERSION_MINOR ?= 15
VERSION_BUILD ?= 0

VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
# On release, remember to also bump const in version/version.go
GIT_VERSION ?= $(shell git describe --always --tags --long --dirty)

GOOS ?= $(shell go env GOOS)
GOARCH = amd64
Expand All @@ -31,11 +27,11 @@ SUPPORTED_PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH) windows-$(GOARCH).exe
BUILD_PACKAGE = $(REPOPATH)

# These build tags are from the containers/image library.
#
#
# container_image_ostree_stub allows building the library without requiring the libostree development libraries
# container_image_openpgp forces a Golang-only OpenPGP implementation for signature verification instead of the default cgo/gpgme-based implementation
GO_BUILD_TAGS := "container_image_ostree_stub containers_image_openpgp"
GO_LDFLAGS := "-X $(REPOPATH)/version.version=$(VERSION)"
GO_LDFLAGS := "-X $(REPOPATH)/version.gitVersion=$(GIT_VERSION)"
GO_FILES := $(shell go list -f '{{join .Deps "\n"}}' $(BUILD_PACKAGE) | grep $(ORG) | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}')

$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
Expand Down Expand Up @@ -68,7 +64,7 @@ integration: $(BUILD_DIR)/$(PROJECT)

.PHONY: release
release: cross
gsutil cp $(BUILD_DIR)/$(PROJECT)-* gs://$(RELEASE_BUCKET)/$(VERSION)/
gsutil cp $(BUILD_DIR)/$(PROJECT)-* gs://$(RELEASE_BUCKET)/$(shell $(BUILD_DIR)/$(PROJECT) version --short)/
gsutil cp $(BUILD_DIR)/$(PROJECT)-* gs://$(RELEASE_BUCKET)/latest/

.PHONY: clean
Expand Down
10 changes: 9 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ var versionCmd = &cobra.Command{
Long: `Print the version of container-diff.`,
Args: cobra.ExactArgs(0),
Run: func(command *cobra.Command, args []string) {
fmt.Println(version.GetVersion())
if shortVersion {
fmt.Println(version.GetShortVersion())
} else {
fmt.Println(version.GetVersion())
}
},
}

// `version --short` is useful for `make release`
var shortVersion bool

func init() {
versionCmd.Flags().BoolVarP(&shortVersion, "short", "", false, "Output single vX.Y.Z word")
RootCmd.AddCommand(versionCmd)
}
15 changes: 13 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ limitations under the License.

package version

var version = "v0.0.0-unset"
import "fmt"

func GetVersion() string {
// Bump this on release
var version = "v0.15.0"

// When built using `make` this is overridden via -ldflags
var gitVersion = "(unknown)"

// returns just the vX.Y.Z version suitable for `make release`
func GetShortVersion() string {
return version
}

func GetVersion() string {
return fmt.Sprintf("%s built from git %s", version, gitVersion)
}

0 comments on commit 367eb42

Please sign in to comment.