diff --git a/Makefile b/Makefile index 8b702304..5a8c6fd8 100755 --- a/Makefile +++ b/Makefile @@ -75,6 +75,8 @@ copr-fix: ; $(info adding copyright header...) GO ?= CGO_ENABLED=0 go # Allow setting of go build flags from the command line. GOFLAGS := +TAG := $(shell git describe --tags --abbrev=0) +LDFLAGS=-ldflags "-X github.com/clusterlink-net/clusterlink/pkg/versioninfo.GitTag=$(TAG)" # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -102,11 +104,11 @@ codegen: controller-gen ## Generate ClusterRole, CRDs and DeepCopyObject. build: @echo "Start go build phase" - $(GO) build -o ./bin/gwctl ./cmd/gwctl + $(GO) build $(LDFLAGS) -o ./bin/gwctl ./cmd/gwctl $(GO) build -o ./bin/cl-controlplane ./cmd/cl-controlplane $(GO) build -o ./bin/cl-dataplane ./cmd/cl-dataplane $(GO) build -o ./bin/cl-go-dataplane ./cmd/cl-go-dataplane - $(GO) build -o ./bin/cl-adm ./cmd/cl-adm + $(GO) build $(LDFLAGS) -o ./bin/cl-adm ./cmd/cl-adm $(GO) build -o ./bin/cl-operator ./cmd/cl-operator/main.go docker-build: build diff --git a/pkg/versioninfo/variables.go b/pkg/versioninfo/variables.go index 660f88bf..21b79b86 100644 --- a/pkg/versioninfo/variables.go +++ b/pkg/versioninfo/variables.go @@ -15,30 +15,12 @@ package versioninfo import ( - _ "embed" - "strings" "time" ) -// @TODO -// The placement of version.txt inside this package is not ideal. -// Unfortunately Go does not allow ".." in embed paths. A possible workaround is to -// use "go:generate" comment to copy the file from the root to this location (and adding -// the local version to .gitignore...). - -// An alternative to using a fixed file, would be to use a go:generate comment with -// "git describe" (git describe output is something like v1.1-19-g175c485, where v1.1 -// is the most recent annotated tag, 19 is the number of commits since that tag, g stands -// for "git," and 175c485 is the short commit hash. -// Build date can also be added to the version with "go:generate date +%F". -var ( - //go:embed version.txt - semver string - // SemVer will be the version specified in version.txt file. - SemVer = strings.TrimSpace(semver) -) - var ( + // GitTag will hold the Git tag information. + GitTag string // Version will be the version tag if the binary is built or "(devel)". Version = "unknown" // Revision is taken from the vcs.revision tag. diff --git a/pkg/versioninfo/version.go b/pkg/versioninfo/version.go index 219abfc9..9dbaf35b 100644 --- a/pkg/versioninfo/version.go +++ b/pkg/versioninfo/version.go @@ -40,9 +40,8 @@ func init() { // The format is -[-]. func Short() string { parts := make([]string, 0, 4) - - if SemVer != "" { - parts = append(parts, SemVer) + if GitTag != "" { + parts = append(parts, GitTag) } if Version != "unknown" && Version != "(devel)" { parts = append(parts, Version) diff --git a/pkg/versioninfo/version.txt b/pkg/versioninfo/version.txt deleted file mode 100644 index 8a9ecc2e..00000000 --- a/pkg/versioninfo/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.0.1 \ No newline at end of file