From 086db00b7a675074e1201f914aa4e8289f1bb384 Mon Sep 17 00:00:00 2001 From: Gregory Shilin Date: Wed, 16 Nov 2022 17:41:55 +0200 Subject: [PATCH] Autogenerate Version=- (#36) --- .github/workflows/publish-release.yaml | 2 +- Makefile | 14 +++++++++++--- cmd/ocm-support/version/cmd.go | 2 +- pkg/info/info.go | 2 ++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-release.yaml b/.github/workflows/publish-release.yaml index d27a1cb..64fc917 100644 --- a/.github/workflows/publish-release.yaml +++ b/.github/workflows/publish-release.yaml @@ -134,4 +134,4 @@ jobs: f"/repos/{repository}/releases/{release}/assets?name={asset}" ), ) - response.raise_for_status() \ No newline at end of file + response.raise_for_status() diff --git a/Makefile b/Makefile index 8cccdce..73cad5e 100644 --- a/Makefile +++ b/Makefile @@ -3,18 +3,26 @@ OUTPUT_DIR :=_output # Constants GOPATH := $(shell go env GOPATH) +# Version +revision:=$(shell git rev-parse --short HEAD) +build_time:=$(shell date +%D@%T) +version_stamp:=$(revision)-$(build_time) +# Set the linker flags so that the version will be included in the binaries: +import_path:=github.com/openshift-online/ocm-support-cli +ldflags:=-X $(import_path)/pkg/info.VersionStamp=$(version_stamp) + build: clean - go build -o ocm-support ./cmd/ocm-support || exit 1 + go build -o ocm-support -ldflags="$(ldflags)" ./cmd/ocm-support || exit 1 install: clean - go build -o $(GOPATH)/bin/ocm-support ./cmd/ocm-support || exit 1 + go build -o $(GOPATH)/bin/ocm-support -ldflags="$(ldflags)" ./cmd/ocm-support || exit 1 clean: rm -f ocm-support cmds: for cmd in $$(ls cmd); do \ - go build "./cmd/$${cmd}" || exit 1; \ + go build -ldflags="$(ldflags)" "./cmd/$${cmd}" || exit 1; \ done ensureOCM: diff --git a/cmd/ocm-support/version/cmd.go b/cmd/ocm-support/version/cmd.go index 7fc0c2c..7637094 100644 --- a/cmd/ocm-support/version/cmd.go +++ b/cmd/ocm-support/version/cmd.go @@ -18,5 +18,5 @@ var Cmd = &cobra.Command{ } func run(cmd *cobra.Command, argv []string) { - _, _ = fmt.Fprintf(os.Stdout, "%s\n", info.Version) + _, _ = fmt.Fprintf(os.Stdout, "%s (build %s)\n", info.Version, info.VersionStamp) } diff --git a/pkg/info/info.go b/pkg/info/info.go index 9207329..578a7fb 100644 --- a/pkg/info/info.go +++ b/pkg/info/info.go @@ -4,3 +4,5 @@ package info // Version of the ocm-support-cli const Version = "0.1.0" + +var VersionStamp string