Skip to content

Commit 8c72dc9

Browse files
authored
Merge pull request #107 from commitdev/version
version and build sha injected at link time into binary
2 parents 959abff + 52705bc commit 8c72dc9

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
VERSION = 0.0.1
2+
BUILD ?=$(shell git rev-parse --short HEAD)
3+
PKG ?=github.com/commitdev/commit0
4+
BUILD_ARGS=-v -ldflags=all="-X ${PKG}/cmd.appVersion=${VERSION} -X ${PKG}/cmd.appBuild=${BUILD}"
5+
16
check:
27
go test ./...
38

@@ -13,7 +18,7 @@ build-example-docker: clean-example
1318
docker run -v "$(shell pwd)/example/hello-world:/project" --user $(shell id -u):$(shell id -g) commit0:v0 generate -l go
1419

1520
build:
16-
go build -o commit0
21+
go build ${BUILD_ARGS}
1722

1823
# Installs the CLI int your GOPATH
1924
install-go:

cmd/version.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9+
var (
10+
appVersion = "SNAPSHOT"
11+
appBuild = "SNAPSHOT"
12+
)
13+
914
func init() {
1015
rootCmd.AddCommand(versionCmd)
1116
}
@@ -14,6 +19,7 @@ var versionCmd = &cobra.Command{
1419
Use: "version",
1520
Short: "Print the version number of commit0",
1621
Run: func(cmd *cobra.Command, args []string) {
17-
fmt.Println("v0.0.0") // Updated via updateVersion.sh
22+
fmt.Printf("version: %v\n", appVersion)
23+
fmt.Printf("build: %v\n", appBuild)
1824
},
1925
}

updateVersion.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)