Inject git version when building a release
This commit is contained in:
parent
4224b3d326
commit
ca894c621f
7
Makefile
7
Makefile
@ -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//')"
|
||||
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"
|
||||
|
||||
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:
|
||||
gox -build-toolchain
|
||||
|
16
main.go
16
main.go
@ -16,6 +16,9 @@ import (
|
||||
|
||||
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
|
||||
|
||||
func exitWithMessage(message string) {
|
||||
@ -61,11 +64,20 @@ func initOptions() {
|
||||
options = command.Opts
|
||||
|
||||
if options.Version {
|
||||
fmt.Printf("pgweb v%s\n", VERSION)
|
||||
printVersion()
|
||||
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user