From 9247df089100b694daf701b3717e52f3ae4343e1 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 7 Nov 2024 20:31:11 +0100 Subject: [PATCH] feat: set version from git tag on build - add version variable and default it to "devel" - add ldflags to `.goreleaser.yaml` for version tagging --- .goreleaser.yaml | 2 ++ cmd/client/app.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 8f87b3f..284f2f8 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/ChronoTomato/cmd/client.version={{.Version}} upx: - enabled: true diff --git a/cmd/client/app.go b/cmd/client/app.go index 6a87b53..1607183 100644 --- a/cmd/client/app.go +++ b/cmd/client/app.go @@ -2,6 +2,8 @@ package client import ( "flag" + "fmt" + "os" "git.smsvc.net/pomodoro/ChronoTomato/internal/helper" "git.smsvc.net/pomodoro/ChronoTomato/internal/websocket" @@ -13,8 +15,9 @@ import ( ) var ( - config ChronoTomato.Config - client websocket.Client + version = "devel" + config ChronoTomato.Config + client websocket.Client ) type app struct { @@ -68,9 +71,15 @@ func Start() { parameter_url = flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)") parameter_password = flag.String("password", "", "Control password for pomodoro session") parameter_configfile = flag.String("config", defaultConfigFile, "Path to config file") + showVersion = flag.Bool("version", false, "Show Version") ) flag.Parse() + if *showVersion { + fmt.Println("ChronoTomato", version) + os.Exit(0) + } + // read passed config file or try to use default config if *parameter_configfile != defaultConfigFile { config = helper.ParseConfig(*parameter_configfile)