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

version: Move vX.Y.Z to version.go so it works with go get, add git info #304

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions Makefile
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
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
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)
}