From 16fc2991ca05343e2f1d489542ac11609703d670 Mon Sep 17 00:00:00 2001 From: Marty Zalega Date: Sat, 6 Jul 2024 08:05:11 +1000 Subject: [PATCH] chore(version): Include commit tag in version output --- .goreleaser.yaml | 6 +++--- main.go | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 605bc97..db3bb1b 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -18,15 +18,15 @@ builds: - "6" - "7" ldflags: - - "-s -w -X main.BuildDate={{ .Date }} -X main.Version={{ .Version }}" + - "-s -w -X main.BuildDate={{ .Date }} -X main.Version={{ .Version }} -X main.Commit={{.Commit}}" archives: - name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" format: binary brews: - directory: Formula homepage: "https://github.com/evilmarty/ilc" - description: "A simple way to create a command-line utility." - license: "GPL-3.0" + description: "Simplify creating command-line utilities" + license: "GPL" install: | bin.install Dir["*"].first => "ilc" test: | diff --git a/main.go b/main.go index 207cd8c..eaa9676 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( var ( Version = "No version provided" BuildDate = "Unknown build date" + Commit = "" mainFlagSet = flag.NewFlagSet("ILC", flag.ExitOnError) logger = log.New(io.Discard, "DEBUG: ", log.Lshortfile) ) @@ -25,6 +26,9 @@ func main() { } mainFlagSet.BoolFunc("version", "Displays the version", func(_ string) error { fmt.Printf("ILC - %s\nVersion: %s\n", BuildDate, Version) + if Commit != "" { + fmt.Printf("Commit: %s\n", Commit) + } os.Exit(0) return nil })