version command

This commit is contained in:
nicksherron 2020-02-09 20:35:45 -05:00
parent 376ddc8e1b
commit 225056870a
2 changed files with 4 additions and 5 deletions

View file

@ -1,8 +1,7 @@
.PHONY: build build-alpine clean test help default docker-build
BIN_NAME=bashhub-server
VERSION := $(shell grep "const Version " version/version.go | sed -E 's/.*"(.+)"$$/\1/')
VERSION=$(shell git tag | sort --version-sort -r | head -1)
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)
BUILD_DATE=$(shell date '+%Y-%m-%d-%H:%M:%S')
@ -27,7 +26,7 @@ help:
build:
@echo "building ${BIN_NAME} ${VERSION}"
@echo "GOPATH=${GOPATH}"
go build -ldflags "-X github.com/nicksherron/bashhub-server/cmd.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/nicksherron/bashhub-server/cmd.BuildDate=${BUILD_DATE}" -o bin/${BIN_NAME}
go build -ldflags "-X github.com/nicksherron/bashhub-server/cmd.Version=${VERSION} -X github.com/nicksherron/bashhub-server/cmd.GitCommit=${GIT_COMMIT} -X github.com/nicksherron/bashhub-server/cmd.BuildDate=${BUILD_DATE}" -o bin/${BIN_NAME}
get-deps:
dep ensure

View file

@ -25,7 +25,7 @@ import (
// versionCmd represents the version command
var (
Build string
GitCommit string
BuildDate string
Version string
OsArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)
@ -36,7 +36,7 @@ var (
Short: "Print the version number and build info",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Build Date:", BuildDate)
fmt.Println("Git Commit:", Build)
fmt.Println("Git Commit:", GitCommit)
fmt.Println("Version:", Version)
fmt.Println("Go Version:", GoVersion)
fmt.Println("OS / Arch:", OsArch)