From b7b9b227996d8c62fb3e24075673597d2c7f8bd2 Mon Sep 17 00:00:00 2001 From: Siddhartha Khuntia <77291662+sidkhuntia@users.noreply.github.com> Date: Wed, 22 Nov 2023 13:21:43 +0530 Subject: [PATCH] feat:add version flag to ldflags and print version in banner (#158) Signed-off-by: Siddhartha Khuntia --- .goreleaser.yml | 8 +++++++- pkg/utils/banner.go | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index b2b69b65..90de4ce1 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -6,6 +6,8 @@ builds: main: ./main.go env: - CGO_ENABLED=0 + ldflags: + - -X github.com/yonahd/kor/pkg/utils.Version={{.Version}} goos: - linux goarch: @@ -17,6 +19,8 @@ builds: main: ./main.go env: - CGO_ENABLED=0 + ldflags: + - -X github.com/yonahd/kor/pkg/utils.Version={{.Version}} goos: - darwin goarch: @@ -32,7 +36,7 @@ builds: - amd64 ldflags: - -buildmode=exe - + - -X github.com/yonahd/kor/pkg/utils.Version={{.Version}} archives: - format: tar.gz name_template: >- @@ -57,3 +61,5 @@ changelog: - 'README' - Merge pull request - Merge branch +snapshot: + name_template: "{{ .Version }}" \ No newline at end of file diff --git a/pkg/utils/banner.go b/pkg/utils/banner.go index fafa9357..dc8aa7a5 100644 --- a/pkg/utils/banner.go +++ b/pkg/utils/banner.go @@ -1,9 +1,13 @@ package utils import ( + "fmt" + "github.com/fatih/color" ) +var Version = "dev" + func PrintLogo(outputFormat string) { boldBlue := color.New(color.FgHiBlue, color.Bold) asciiLogo := ` @@ -15,7 +19,7 @@ func PrintLogo(outputFormat string) { ` // processing of the `outputFormat` happens inside of the rootCmd so this requires a pretty large change // to keep the banner. Instead just loop through os args and find if the format was set and handle it there - + fmt.Printf("version: v%s\n", Version) if outputFormat != "yaml" && outputFormat != "json" { boldBlue.Println(asciiLogo) }