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

Commit 367eb42

Browse files
authored
Merge pull request #304 from cben/version
version: Move vX.Y.Z to version.go so it works with `go get`, add git info
2 parents 4fb337a + 91e0989 commit 367eb42

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

Makefile

+5-9
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Bump these on release
16-
VERSION_MAJOR ?= 0
17-
VERSION_MINOR ?= 15
18-
VERSION_BUILD ?= 0
19-
20-
VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
15+
# On release, remember to also bump const in version/version.go
16+
GIT_VERSION ?= $(shell git describe --always --tags --long --dirty)
2117

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

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

4137
$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
@@ -68,7 +64,7 @@ integration: $(BUILD_DIR)/$(PROJECT)
6864

6965
.PHONY: release
7066
release: cross
71-
gsutil cp $(BUILD_DIR)/$(PROJECT)-* gs://$(RELEASE_BUCKET)/$(VERSION)/
67+
gsutil cp $(BUILD_DIR)/$(PROJECT)-* gs://$(RELEASE_BUCKET)/$(shell $(BUILD_DIR)/$(PROJECT) version --short)/
7268
gsutil cp $(BUILD_DIR)/$(PROJECT)-* gs://$(RELEASE_BUCKET)/latest/
7369

7470
.PHONY: clean

cmd/version.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ var versionCmd = &cobra.Command{
2929
Long: `Print the version of container-diff.`,
3030
Args: cobra.ExactArgs(0),
3131
Run: func(command *cobra.Command, args []string) {
32-
fmt.Println(version.GetVersion())
32+
if shortVersion {
33+
fmt.Println(version.GetShortVersion())
34+
} else {
35+
fmt.Println(version.GetVersion())
36+
}
3337
},
3438
}
3539

40+
// `version --short` is useful for `make release`
41+
var shortVersion bool
42+
3643
func init() {
44+
versionCmd.Flags().BoolVarP(&shortVersion, "short", "", false, "Output single vX.Y.Z word")
3745
RootCmd.AddCommand(versionCmd)
3846
}

version/version.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@ limitations under the License.
1616

1717
package version
1818

19-
var version = "v0.0.0-unset"
19+
import "fmt"
2020

21-
func GetVersion() string {
21+
// Bump this on release
22+
var version = "v0.15.0"
23+
24+
// When built using `make` this is overridden via -ldflags
25+
var gitVersion = "(unknown)"
26+
27+
// returns just the vX.Y.Z version suitable for `make release`
28+
func GetShortVersion() string {
2229
return version
2330
}
31+
32+
func GetVersion() string {
33+
return fmt.Sprintf("%s built from git %s", version, gitVersion)
34+
}

0 commit comments

Comments
 (0)