From 8c88ec0b508b7373dfe16d9347a270c9b49bf95a Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sat, 9 Nov 2024 15:59:30 +0100 Subject: [PATCH] feat: always retrieve version from git tag --- .goreleaser.yaml | 2 -- internal/metadata/version.go | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 9bdad83..f72fe6a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -15,8 +15,6 @@ builds: - arm64 env: - CGO_ENABLED=0 - ldflags: - - -s -w -X git.smsvc.net/pomodoro/GoTomato/internal/metadata.GoTomatoVersion={{.Version}} upx: - enabled: true diff --git a/internal/metadata/version.go b/internal/metadata/version.go index ecac17b..2b080e5 100644 --- a/internal/metadata/version.go +++ b/internal/metadata/version.go @@ -1,7 +1,20 @@ package metadata -import "strings" +import ( + "os/exec" + "strings" +) -// This will be overwritten by goreleaser on build -var GoTomatoVersion = "devel" // The GoTomato version -var ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0] // The protocol version +var ( + GoTomatoVersion = "" // The GoTomato version + ProtocolVersion = "" // The protocol version +) + +func init() { + if GoTomatoVersion == "" { + output, _ := exec.Command("git", "describe", "--tags").Output() + trimmed_output := strings.TrimSpace(string(output)) // strip newlines + GoTomatoVersion = strings.Replace(trimmed_output, "v", "", 1) // strip leading "v" + } + ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0] // The protocol version +}