From 981ee7dce4b101d18f4c778c971d805364486e3c Mon Sep 17 00:00:00 2001 From: admju Date: Wed, 18 Sep 2024 19:31:18 +0000 Subject: [PATCH] version --- Makefile | 1 + src/Makefile | 8 ++++---- src/cmd/versionCmd.go | 19 +++++++++++++++++++ src/cmd/versionlCmd.go | 15 --------------- src/occonst/variables.go | 4 ++++ 5 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 src/cmd/versionCmd.go delete mode 100644 src/cmd/versionlCmd.go diff --git a/Makefile b/Makefile index 0028e85..2f0878b 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ help: .PHONY: publish publish: @echo Publication de : ${OC_VERSION} + @(cd src && make --quiet build VERSION=$(OC_VERSION)) @(cd publish && \ PUBLISH_REPO=${PUBLISH_REPO} \ PUBLISH_TOKEN=${PUBLISH_TOKEN} \ diff --git a/src/Makefile b/src/Makefile index f3f7465..5f82383 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,12 +12,12 @@ PLUGINS := $(wildcard ../plugins/*/*.go) OBJS := ${PLUGINS:.go=.so} ################## -DATE := $(shell date) +DATE := $(shell date --iso-8601) GOVERSION := $(shell go version) VERSION := $(shell git describe --tags --abbrev=8 --dirty --always --long) -PREFIX := "oc-deploy/version" +PREFIX := oc-deploy/occonst -LDFLAGS := -X '${PREFIX}.Version=${VERSION}' +LDFLAGS := "-X '${PREFIX}.Version=${VERSION}' -X '${PREFIX}.Date=${DATE}' -X '${PREFIX}.GoVersion=${GOVERSION}'" ################## @@ -49,7 +49,7 @@ help: @echo ${BIN_DIR}/${BIN_NAME}: ${SOURCES} $(OBJS) - go build -o ${BIN_DIR}/${BIN_NAME} -ldflags "${LDFLAGS}" + go build -o ${BIN_DIR}/${BIN_NAME} -ldflags ${LDFLAGS} get-deps: @go mod tidy diff --git a/src/cmd/versionCmd.go b/src/cmd/versionCmd.go new file mode 100644 index 0000000..b17eacc --- /dev/null +++ b/src/cmd/versionCmd.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "fmt" + "oc-deploy/occonst" + log "oc-deploy/log_wrapper" +) + +func VersionCmd() error { + + version := occonst.Version + date := occonst.Date + goversion := occonst.GoVersion + + log.Log().Debug().Msg(fmt.Sprintf("Version : %s (%s) ; GoVersion : %s", version, date, goversion)) + fmt.Println(version) + + return nil +} \ No newline at end of file diff --git a/src/cmd/versionlCmd.go b/src/cmd/versionlCmd.go deleted file mode 100644 index e31a708..0000000 --- a/src/cmd/versionlCmd.go +++ /dev/null @@ -1,15 +0,0 @@ -package cmd - -import ( - "fmt" - log "oc-deploy/log_wrapper" -) - -func VersionCmd() error { - - version := "0.1.0" - log.Log().Debug().Msg(fmt.Sprintf("Version : %s", version)) - fmt.Println(version) - - return nil -} \ No newline at end of file diff --git a/src/occonst/variables.go b/src/occonst/variables.go index 44c451e..4275f72 100644 --- a/src/occonst/variables.go +++ b/src/occonst/variables.go @@ -9,6 +9,10 @@ var OCDEPLOY_ONLINE_REPO = getenv("OCDEPLOY_ONLINE_REPO", "core/oc-version") var OCDEPLOY_OFFLINE_DIR = getenv("OCDEPLOY_OFFLINE_DIR", "../../offline") +var Version = "dev" +var Date = "now" +var GoVersion = "" + func getenv(key string, defaut string) string { value := os.Getenv(key) if len(value) == 0 {