From e07656c992dd1844029713e7f75aed38f0197f4a Mon Sep 17 00:00:00 2001 From: zhuwenxing Date: Mon, 4 Sep 2023 19:20:20 +0800 Subject: [PATCH] Update version by goreleaser (#191) Signed-off-by: zhuwenxing --- .goreleaser.yaml | 8 ++++++++ cmd/root.go | 6 ++++++ cmd/version.go | 20 -------------------- main.go | 7 +++++++ 4 files changed, 21 insertions(+), 20 deletions(-) delete mode 100644 cmd/version.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 99fa0b9..f780cfe 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,6 +10,11 @@ builds: goos: - linux - darwin + ldflags: + - -w -s + - -X main.version={{ .Version }} + - -X main.commit={{ .Commit }} + - -X main.date={{ .Date }} archives: - format: tar.gz @@ -25,6 +30,9 @@ checksum: name_template: 'checksums.txt' snapshot: name_template: "{{ incpatch .Version }}-next" + + + changelog: sort: asc use: github diff --git a/cmd/root.go b/cmd/root.go index b53534c..4cde080 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,6 +2,8 @@ package cmd import ( "errors" + "fmt" + "github.com/spf13/cobra" ) @@ -23,3 +25,7 @@ func Execute() { rootCmd.Execute() } + +func SetVersionInfo(version, commit, date string) { + rootCmd.Version = fmt.Sprintf("%s (Built on %s from Git SHA %s)", version, date, commit) +} diff --git a/cmd/version.go b/cmd/version.go deleted file mode 100644 index 94d1d5e..0000000 --- a/cmd/version.go +++ /dev/null @@ -1,20 +0,0 @@ -package cmd - -import ( - "fmt" - "github.com/spf13/cobra" -) - -const Version = "1.0-beta" - -var versionCmd = &cobra.Command{ - Use: "version", - Short: "print the version of Milvus backup tool", - Run: func(cmd *cobra.Command, args []string) { - fmt.Println(fmt.Sprintf("Version: %s", Version)) - }, -} - -func init() { - rootCmd.AddCommand(versionCmd) -} diff --git a/main.go b/main.go index 4ca7310..96f1bd3 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,12 @@ import ( _ "github.com/zilliztech/milvus-backup/docs" ) +var ( + version = "dev" + commit = "unknown" + date = "unknown" +) + // @title Milvus Backup Service // @version 1.0 // @description A data backup & restore tool for Milvus @@ -14,5 +20,6 @@ import ( // @license.url http://www.apache.org/licenses/LICENSE-2.0.html // @BasePath /api/v1 func main() { + cmd.SetVersionInfo(version, commit, date) cmd.Execute() }