From f9bb50ab2a9010b6860d556da794e41be08113d2 Mon Sep 17 00:00:00 2001 From: "tingzhen.lin" Date: Mon, 26 Sep 2022 20:48:41 +0800 Subject: [PATCH] feat: extract latest git tag as version --- Makefile | 3 ++- cmd/version.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d70e942..bdb2cb7 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ +VERSION := $(shell git describe --abbrev=0) COMMIT_REVISION := $(shell git log --pretty=%h -1) -REVISION_FLAG := "-X github.com/lintingzhen/commitizen-go/cmd.revision=${COMMIT_REVISION}" +REVISION_FLAG := "-X github.com/lintingzhen/commitizen-go/cmd.revision=${COMMIT_REVISION} -X github.com/lintingzhen/commitizen-go/cmd.version=${VERSION}" TARGET := commitizen-go GOFILES := $(wildcard *.go) $(wildcard cmd/*.go) $(wildcard git/*.go) $(wildcard commit/*.go) diff --git a/cmd/version.go b/cmd/version.go index 2ba9c71..9ffb109 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,12 +6,13 @@ import ( "github.com/spf13/cobra" ) +var version string var revision string var VersionCmd = &cobra.Command{ Use: "version", Short: "Print version information and quit", Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("Commitizen-go version 1.0.0, build revision %s\n", revision) + fmt.Printf("Commitizen-go version %s, build revision %s\n", version, revision) }, }