Add commit & branch to Makefile

This commit is contained in:
Cameron Sparr 2016-09-13 08:45:06 +01:00
parent b6f81b538a
commit bc22309459
2 changed files with 8 additions and 6 deletions

View File

@ -1,4 +1,6 @@
VERSION := $(shell sh -c 'git describe --always --tags') VERSION := $(shell sh -c 'git describe --always --tags')
BRANCH := $(shell sh -c 'git rev-parse --abbrev-ref HEAD')
COMMIT := $(shell sh -c 'git rev-parse HEAD')
ifdef GOBIN ifdef GOBIN
PATH := $(GOBIN):$(PATH) PATH := $(GOBIN):$(PATH)
else else
@ -13,17 +15,18 @@ windows: prepare-windows build-windows
# Only run the build (no dependency grabbing) # Only run the build (no dependency grabbing)
build: build:
go install -ldflags "-X main.version=$(VERSION)" ./... go install -ldflags \
"-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)" ./...
build-windows: build-windows:
GOOS=windows GOARCH=amd64 go build -o telegraf.exe -ldflags \ GOOS=windows GOARCH=amd64 go build -o telegraf.exe -ldflags \
"-X main.version=$(VERSION)" \ "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)" \
./cmd/telegraf/telegraf.go ./cmd/telegraf/telegraf.go
build-for-docker: build-for-docker:
CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo -o telegraf -ldflags \ CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo -o telegraf -ldflags \
"-s -X main.version=$(VERSION)" \ "-s -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)" \
./cmd/telegraf/telegraf.go ./cmd/telegraf/telegraf.go
# run package script # run package script
package: package:

View File

@ -170,8 +170,7 @@ func reloadLoop(stop chan struct{}, s service.Service) {
} }
return return
case *fVersion: case *fVersion:
v := fmt.Sprintf("Telegraf - version %s", version) fmt.Printf("Telegraf v%s (git: %s %s)\n", version, branch, commit)
fmt.Println(v)
return return
case *fSampleConfig: case *fSampleConfig:
config.PrintSampleConfig(inputFilters, outputFilters) config.PrintSampleConfig(inputFilters, outputFilters)