Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
Provide automatic buildinfo for plugins (#3261)
Browse files Browse the repository at this point in the history
Fixes #3230

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
  • Loading branch information
marckhouzam authored Sep 2, 2022
1 parent 254f018 commit 833477e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
22 changes: 22 additions & 0 deletions cli/runtime/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Package buildinfo holds global variables set at build time to provide information about the plugin build.
package buildinfo

var (
// Date is the date the plugin binary was built.
// It should be set using:
// go build --ldflags "-X 'github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo.Date=...'"
Date string

// SHA is the git commit SHA the plugin binary was built with.
// Is should be set using:
// go build --ldflags "-X 'github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo.SHA=...'"
SHA string

// Version is the version of the plugin built.
// It should be set using:
// go build --ldflags "-X 'github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo.Version=...'"
Version string
)
4 changes: 4 additions & 0 deletions pkg/v1/builder/template/plugintemplates/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ GOARCH ?= $(shell go env GOARCH)
GOHOSTOS ?= $(shell go env GOHOSTOS)
GOHOSTARCH ?= $(shell go env GOHOSTARCH)

LD_FLAGS = -X 'github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo.Date=$(BUILD_DATE)'
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo.SHA=$(BUILD_SHA)'
LD_FLAGS += -X 'github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo.Version=$(BUILD_VERSION)'

TOOLS_DIR := tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
Expand Down
5 changes: 3 additions & 2 deletions pkg/v1/builder/template/plugintemplates/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"github.com/aunum/log"

cliv1alpha1 "github.com/vmware-tanzu/tanzu-framework/apis/cli/v1alpha1"
"github.com/vmware-tanzu/tanzu-framework/cli/runtime/buildinfo"
"github.com/vmware-tanzu/tanzu-framework/cli/runtime/plugin"
)

var descriptor = cliv1alpha1.PluginDescriptor{
Name: "{{ .PluginName | ToLower }}",
Description: "{{ .Description | ToLower }}",
Version: "v0.0.1",
BuildSHA: "",
Version: buildinfo.Version,
BuildSHA: buildinfo.SHA,
Group: cliv1alpha1.ManageCmdGroup, // set group
}

Expand Down

0 comments on commit 833477e

Please # to comment.