From 93f39507c1477cd7b8853be0d40d7b441b60ccfd Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 7 Nov 2024 11:38:45 +0100 Subject: [PATCH] feat(gorleaser): set version from git tag on build - make `GoTomatoVersion` a variable and default it to "devel" - add ldflags to `.goreleaser.yaml` for version tagging - remove "v" from output of `-version` --- .goreleaser.yaml | 2 ++ cmd/server/main.go | 4 ++-- internal/metadata/version.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index aa2e879..4b315c5 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -15,6 +15,8 @@ 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/cmd/server/main.go b/cmd/server/main.go index 29241f0..a109f38 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -28,8 +28,8 @@ func Start() { // show server and protocl version and exit if *showVersionFlag { - fmt.Printf("Server-Version: v%s\n", metadata.GoTomatoVersion) - fmt.Printf("Protocol-Version: v%s\n", metadata.ProtocolVersion) + fmt.Println("Server-Version:", metadata.GoTomatoVersion) + fmt.Println("Protocol-Version:", metadata.ProtocolVersion) os.Exit(0) } diff --git a/internal/metadata/version.go b/internal/metadata/version.go index 22e394e..ecac17b 100644 --- a/internal/metadata/version.go +++ b/internal/metadata/version.go @@ -2,5 +2,6 @@ package metadata import "strings" -const GoTomatoVersion = "0.1.1" // The GoTomato version +// This will be overwritten by goreleaser on build +var GoTomatoVersion = "devel" // The GoTomato version var ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0] // The protocol version