Skip to content

Commit

Permalink
version and build sha injected at link time into binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor O committed Mar 23, 2020
1 parent 705b4f3 commit 52705bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Makefile
@@ -1,3 +1,8 @@
VERSION = 0.0.1
BUILD ?=$(shell git rev-parse --short HEAD)
PKG ?=github.com/commitdev/commit0
BUILD_ARGS=-v -ldflags=all="-X ${PKG}/cmd.appVersion=${VERSION} -X ${PKG}/cmd.appBuild=${BUILD}"

check:
go test ./...

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

build:
go build -o commit0
go build ${BUILD_ARGS}

# Installs the CLI int your GOPATH
install-go:
Expand Down
8 changes: 7 additions & 1 deletion cmd/version.go
Expand Up @@ -6,6 +6,11 @@ import (
"github.com/spf13/cobra"
)

var (
appVersion = "SNAPSHOT"
appBuild = "SNAPSHOT"
)

func init() {
rootCmd.AddCommand(versionCmd)
}
Expand All @@ -14,6 +19,7 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of commit0",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v0.0.0") // Updated via updateVersion.sh
fmt.Printf("version: %v\n", appVersion)
fmt.Printf("build: %v\n", appBuild)
},
}
12 changes: 0 additions & 12 deletions updateVersion.sh

This file was deleted.

0 comments on commit 52705bc

Please sign in to comment.