From f951c0dd5743194faee8fb13d4c1954228c9ddf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 18 Oct 2024 07:37:52 +0200 Subject: [PATCH] Print release tag in hugo version Fixes #506 --- hugoreleaser.toml | 2 +- main.go | 17 ++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/hugoreleaser.toml b/hugoreleaser.toml index 0a265f9..f032958 100644 --- a/hugoreleaser.toml +++ b/hugoreleaser.toml @@ -26,7 +26,7 @@ archive_alias_replacements = {} binary = "s3deploy" flags = ["-buildmode", "exe"] env = ["CGO_ENABLED=0"] - ldflags = "" + ldflags = "-s -w -X main.tag=${HUGORELEASER_TAG}" # Archive settings can be set on any of Project > Archive. # Follows the same merge rules as Build settings. diff --git a/main.go b/main.go index 568fc1e..0aaf918 100644 --- a/main.go +++ b/main.go @@ -15,9 +15,9 @@ import ( ) var ( - version = "v2" - commit = "none" - date = "unknown" + commit = "none" + tag = "(devel)" + date = "unknown" ) func main() { @@ -37,7 +37,7 @@ func parseAndRun(args []string) error { initVersionInfo() if !cfg.Silent { - fmt.Printf("s3deploy %v, commit %v, built at %v\n", version, commit, date) + fmt.Printf("s3deploy %v, commit %v, built at %v\n", tag, commit, date) } if cfg.Help { @@ -59,22 +59,14 @@ func parseAndRun(args []string) error { } return nil - } func initVersionInfo() { - if commit != "none" { - // Set by goreleaser. - return - } - bi, ok := debug.ReadBuildInfo() if !ok { return } - version = bi.Main.Version - for _, s := range bi.Settings { switch s.Key { case "vcs": @@ -85,5 +77,4 @@ func initVersionInfo() { case "vcs.modified": } } - }