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

Commit 70a176e

Browse files
Merge pull request #44 from r2d4/version
Add version command
2 parents 639bbbf + 5440083 commit 70a176e

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ VERSION_MAJOR ?= 0
22
VERSION_MINOR ?= 2
33
VERSION_BUILD ?= 0
44

5+
VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
6+
57
GOOS ?= $(shell go env GOOS)
68
GOARCH = amd64
79
BUILD_DIR ?= ./out
@@ -17,13 +19,14 @@ BUILD_PACKAGE = $(REPOPATH)
1719
# container_image_ostree_stub allows building the library without requiring the libostree development libraries
1820
# container_image_openpgp forces a Golang-only OpenPGP implementation for signature verification instead of the default cgo/gpgme-based implementation
1921
GO_BUILD_TAGS := "container_image_ostree_stub containers_image_openpgp"
22+
GO_LDFLAGS := "-X $(REPOPATH)/version.version=$(VERSION)"
2023
GO_FILES := $(shell go list -f '{{join .Deps "\n"}}' $(BUILD_PACKAGE) | grep $(ORG) | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}')
2124

2225
$(BUILD_DIR)/$(PROJECT): out/$(PROJECT)-$(GOOS)-$(GOARCH)
2326
cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@
2427

2528
$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
26-
GOOS=$* GOARCH=$(GOARCH) go build -tags $(GO_BUILD_TAGS) -o $@ $(BUILD_PACKAGE)
29+
GOOS=$* GOARCH=$(GOARCH) go build -tags $(GO_BUILD_TAGS) -ldflags $(GO_LDFLAGS) -o $@ $(BUILD_PACKAGE)
2730

2831
$(BUILD_DIR):
2932
mkdir -p $(BUILD_DIR)

cmd/version.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/GoogleCloudPlatform/container-diff/version"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var versionCmd = &cobra.Command{
11+
Use: "version",
12+
Short: "Print the version of container-diff",
13+
Long: `Print the version of container-diff.`,
14+
Run: func(command *cobra.Command, args []string) {
15+
fmt.Println(version.GetVersion())
16+
},
17+
}
18+
19+
func init() {
20+
RootCmd.AddCommand(versionCmd)
21+
}

version/version.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package version
2+
3+
var version = "v0.0.0-unset"
4+
5+
func GetVersion() string {
6+
return version
7+
}

0 commit comments

Comments
 (0)