feat: always retrieve version from git tag

This commit is contained in:
Sebastian Mark 2024-11-09 15:59:30 +01:00
parent 262b1fe033
commit 8c88ec0b50
2 changed files with 17 additions and 6 deletions

View file

@ -15,8 +15,6 @@ builds:
- arm64 - arm64
env: env:
- CGO_ENABLED=0 - CGO_ENABLED=0
ldflags:
- -s -w -X git.smsvc.net/pomodoro/GoTomato/internal/metadata.GoTomatoVersion={{.Version}}
upx: upx:
- enabled: true - enabled: true

View file

@ -1,7 +1,20 @@
package metadata package metadata
import "strings" import (
"os/exec"
"strings"
)
// This will be overwritten by goreleaser on build var (
var GoTomatoVersion = "devel" // The GoTomato version GoTomatoVersion = "" // The GoTomato version
var ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0] // The protocol 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
}