diff --git a/Makefile b/Makefile index c5b8ac7..5f1c3ce 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,18 @@ clean: @echo BIN_OUTPUT: ${BIN_OUTPUT} @rm -rf dist cover.out +VERSION ?= $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") +GIT_TAG := $(shell git describe --tags --abbrev=0 --exact-match > /dev/null 2>&1; echo $$?) + +ifneq ($(GIT_TAG),0) + ifeq ($(origin VERSION),file) + VERSION := devel + endif +endif + +LDFLAGS ?= -w -X main.Version=${VERSION} build: clean - @go build -v -trimpath -o ${BIN_OUTPUT} . + @go build -v -trimpath -ldflags "${LDFLAGS}" -o ${BIN_OUTPUT} . test: clean @go test -v -count=1 -cover ./... diff --git a/main.go b/main.go index 07a2d3e..8597c4e 100644 --- a/main.go +++ b/main.go @@ -1,15 +1,15 @@ package main import ( - "os" - "github.com/daixiang0/gci/cmd/gci" + "os" + "strings" ) -var version = "0.13.4" +var Version = "0.0.0" func main() { - e := gci.NewExecutor(version) + e := gci.NewExecutor(strings.TrimPrefix(Version, "v")) err := e.Execute() if err != nil {