From 69fd87fc2c8c2e7b10b0fa01826324c91f13537e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Klinec?= Date: Wed, 22 May 2024 21:11:07 +0200 Subject: [PATCH] add flavour, version command, fix version source - make makefile single source of truth for version - trigger the flow in the tests --- .gitignore | 1 + Makefile | 27 +++++++++++++++++++++------ cmd/keymaster/main.go | 7 ++++++- keymaster.spec => keymaster.spec.tpl | 4 +--- 4 files changed, 29 insertions(+), 10 deletions(-) rename keymaster.spec => keymaster.spec.tpl (99%) diff --git a/.gitignore b/.gitignore index 1d3ed4c1..fc3317aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ config.yml +keymaster.spec diff --git a/Makefile b/Makefile index 89cd86a3..6c212a63 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,15 @@ endif BINARY=keymaster # These are the values we want to pass for Version and BuildTime -VERSION=1.15.3 +VERSION?=1.15.3 DEFAULT_HOST?= -DEFAULT_LDFLAGS=-X main.Version=${VERSION} +VERSION_FLAVOUR?= +EXTRA_LDFLAGS?= +PRINTVERSION=${VERSION} +ifneq ($(VERSION_FLAVOUR),) +PRINTVERSION=${VERSION}-${VERSION_FLAVOUR} +endif +DEFAULT_LDFLAGS=-X main.Version=${PRINTVERSION} ${EXTRA_LDFLAGS} CLIENT_LDFLAGS=${DEFAULT_LDFLAGS} -X main.defaultHost=${DEFAULT_HOST} #BUILD_TIME=`date +%FT%T%z` @@ -39,16 +45,25 @@ all: install-client cd cmd/keymaster-unlocker; go install -ldflags "${DEFAULT_LDFLAGS}" cd cmd/keymaster-eventmond; go install -ldflags "${DEFAULT_LDFLAGS}" -build: cmd/keymasterd/binData.go +build: prebuild go build ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}" -o $(OUTPUT_DIR) ./... cmd/keymasterd/binData.go: -go-bindata -fs -o cmd/keymasterd/binData.go -prefix cmd/keymasterd/data cmd/keymasterd/data/... -install-client: cmd/keymasterd/binData.go +keymaster.spec: + ifeq ($(OS), Windows_NT) + powershell -Command "Get-Content keymaster.spec.tpl | ForEach-Object { \$$_.Replace('{{VERSION}}', '$(VERSION)') } | Set-Content keymaster.spec" + else + sed 's/{{VERSION}}/$(VERSION)/g' keymaster.spec.tpl > keymaster.spec; + endif + +prebuild: keymaster.spec cmd/keymasterd/binData.go + +install-client: prebuild cd cmd/keymaster; go install ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}" -build-client: cmd/keymasterd/binData.go +build-client: prebuild go build -ldflags "${CLIENT_LDFLAGS}" -o $(OUTPUT_DIR) $(CLIENT_DEST) win-client: client-test @@ -64,7 +79,7 @@ clean: rm -f bin/* rm -f keymaster-*.tar.gz -${BINARY}-${VERSION}.tar.gz: +${BINARY}-${VERSION}.tar.gz: prebuild mkdir ${BINARY}-${VERSION} rsync -av --exclude="config.yml" --exclude="*.pem" --exclude="*.out" lib/ ${BINARY}-${VERSION}/lib/ rsync -av --exclude="config.yml" --exclude="*.pem" --exclude="*.out" --exclude="*.key" cmd/ ${BINARY}-${VERSION}/cmd/ diff --git a/cmd/keymaster/main.go b/cmd/keymaster/main.go index 0e12122c..2640762e 100644 --- a/cmd/keymaster/main.go +++ b/cmd/keymaster/main.go @@ -68,7 +68,8 @@ var ( "If true, use the smart round-robin dialer") webauthBrowser = flag.String("webauthBrowser", "", "Browser command to use for webauth") - + printVersion = flag.Bool("version", false, + "Print version and exit") FilePrefix = "keymaster" ) @@ -496,6 +497,10 @@ func main() { flag.Usage = Usage flag.Parse() logger := cmdlogger.New() + if *printVersion { + fmt.Println(Version) + return + } rootCAs, err := maybeGetRootCas(*rootCAFilename, logger) if err != nil { logger.Fatal(err) diff --git a/keymaster.spec b/keymaster.spec.tpl similarity index 99% rename from keymaster.spec rename to keymaster.spec.tpl index 58b384b1..d7b78a66 100644 --- a/keymaster.spec +++ b/keymaster.spec.tpl @@ -1,5 +1,5 @@ Name: keymaster -Version: 1.15.3 +Version: {{VERSION}} Release: 1%{?dist} Summary: Short term access certificate generator and client @@ -74,5 +74,3 @@ systemctl daemon-reload %config(noreplace) %{_datarootdir}/keymasterd/customization_data/web_resources/* %config(noreplace) %{_datarootdir}/keymasterd/customization_data/templates/* %changelog - -