Skip to content

Commit

Permalink
pkg/versioninfo: Use git tag instead of version.txt
Browse files Browse the repository at this point in the history
Signed-off-by: Kfir Toledo <[email protected]>
  • Loading branch information
kfirtoledo committed Mar 3, 2024
1 parent 11917aa commit 49a3aa8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
22 changes: 2 additions & 20 deletions pkg/versioninfo/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions pkg/versioninfo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ func init() {
// The format is <SemVer>-<GIT SHA>[-<dirty>].
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)
Expand Down
1 change: 0 additions & 1 deletion pkg/versioninfo/version.txt

This file was deleted.

0 comments on commit 49a3aa8

Please sign in to comment.