Inject git version when building a release

This commit is contained in:
Dan Sosedoff 2015-04-30 20:40:06 -05:00
parent 4224b3d326
commit ca894c621f
2 changed files with 20 additions and 3 deletions

View File

@ -1,3 +1,5 @@
TARGETS = darwin/amd64 darwin/386 linux/amd64 linux/386 windows/amd64 windows/386
GIT_COMMIT = $(shell git rev-parse HEAD)
DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')" DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')"
BINDATA_IGNORE = $(shell git ls-files -io --exclude-standard $< | sed 's/^/-ignore=/;s/[.]/[.]/g') BINDATA_IGNORE = $(shell git ls-files -io --exclude-standard $< | sed 's/^/-ignore=/;s/[.]/[.]/g')
@ -37,7 +39,10 @@ build: assets
@echo "You can now execute ./pgweb" @echo "You can now execute ./pgweb"
release: assets release: assets
gox -osarch="darwin/amd64 darwin/386 linux/amd64 linux/386 windows/amd64 windows/386" -output="./bin/pgweb_{{.OS}}_{{.Arch}}" gox \
-osarch="$(TARGETS)" \
-ldflags "-X main.GitCommit $(GIT_COMMIT)" \
-output="./bin/pgweb_{{.OS}}_{{.Arch}}"
bootstrap: bootstrap:
gox -build-toolchain gox -build-toolchain

16
main.go
View File

@ -16,6 +16,9 @@ import (
const VERSION = "0.5.2" const VERSION = "0.5.2"
// The git commit that was compiled. This will be filled in by the compiler.
var GitCommit string
var options command.Options var options command.Options
func exitWithMessage(message string) { func exitWithMessage(message string) {
@ -61,11 +64,20 @@ func initOptions() {
options = command.Opts options = command.Opts
if options.Version { if options.Version {
fmt.Printf("pgweb v%s\n", VERSION) printVersion()
os.Exit(0) os.Exit(0)
} }
fmt.Println("Pgweb version", VERSION) printVersion()
}
func printVersion() {
str := fmt.Sprintf("Pgweb v%s", VERSION)
if GitCommit != "" {
str += fmt.Sprintf(" (git: %s)", GitCommit)
}
fmt.Println(str)
} }
func startServer() { func startServer() {