diff --git a/Makefile b/Makefile index fa11f871..02281c52 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +VERSION?=$$(git describe --tags --always) + +LDFLAGS="-X main.version=$(VERSION)" + .PHONY: clean clean: rm -rf ./dist/ @@ -7,7 +11,7 @@ clean: .PHONY: build build: - go build -o git-chglog ./cmd/git-chglog + go build -ldflags=$(LDFLAGS) -o git-chglog ./cmd/git-chglog .PHONY: test test: diff --git a/cmd/git-chglog/main.go b/cmd/git-chglog/main.go index 562a0a78..8503b149 100644 --- a/cmd/git-chglog/main.go +++ b/cmd/git-chglog/main.go @@ -12,6 +12,9 @@ import ( "github.com/urfave/cli/v2" ) +// version is passed in via LDFLAGS main.version +var version string + // CreateApp creates and initializes CLI application // with description, flags, version, etc. func CreateApp(actionFunc cli.ActionFunc) *cli.App { @@ -74,7 +77,7 @@ func CreateApp(actionFunc cli.ActionFunc) *cli.App { app := cli.NewApp() app.Name = "git-chglog" app.Usage = "todo usage for git-chglog" - app.Version = Version + app.Version = version app.Flags = []cli.Flag{ // init diff --git a/cmd/git-chglog/version.go b/cmd/git-chglog/version.go deleted file mode 100644 index da70d6c8..00000000 --- a/cmd/git-chglog/version.go +++ /dev/null @@ -1,4 +0,0 @@ -package main - -// Version of git-chglog cli client -const Version = "v0.12.0"