Add git commit hash and build date to version
This commit adds git commit hash and build date to airshipctl version command. Relates-To: #630 Signed-off-by: Sreejith Punnapuzha <Sreejith.Punnapuzha@outlook.com> Change-Id: Ic27db40cf80153cb5d3af3accacd33e85d36010d
This commit is contained in:
parent
419300b277
commit
0620debbbe
2
.github/workflows/release-github.yaml
vendored
2
.github/workflows/release-github.yaml
vendored
@ -52,6 +52,8 @@ jobs:
|
|||||||
uses: goreleaser/goreleaser-action@v1
|
uses: goreleaser/goreleaser-action@v1
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
|
commit: currentcommit
|
||||||
|
date: builddate
|
||||||
args: release --release-notes=release-notes.md --skip-validate --debug
|
args: release --release-notes=release-notes.md --skip-validate --debug
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
@ -19,6 +19,8 @@ builds:
|
|||||||
ldflags:
|
ldflags:
|
||||||
- '-extldflags "-static"'
|
- '-extldflags "-static"'
|
||||||
- -X opendev.org/airship/airshipctl/pkg/version.gitVersion={{ .Version }}
|
- -X opendev.org/airship/airshipctl/pkg/version.gitVersion={{ .Version }}
|
||||||
|
- -X opendev.org/airship/airshipctl/pkg/version.gitCommit={{ .Commit }}
|
||||||
|
- -X opendev.org/airship/airshipctl/pkg/version.buildDate={{ .Date }}
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
id: linux
|
id: linux
|
||||||
|
8
Makefile
8
Makefile
@ -1,10 +1,16 @@
|
|||||||
SHELL := /bin/bash
|
SHELL := /bin/bash
|
||||||
|
|
||||||
GIT_VERSION ?= v0.1.0
|
GIT_VERSION ?= v0.1.0
|
||||||
|
GIT_COMMIT ?= $(shell git rev-parse HEAD)
|
||||||
|
BUILD_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||||
GIT_MODULE ?= opendev.org/airship/airshipctl/pkg/version
|
GIT_MODULE ?= opendev.org/airship/airshipctl/pkg/version
|
||||||
|
|
||||||
|
LDFLAGS += -X ${GIT_MODULE}.gitVersion=${GIT_VERSION}
|
||||||
|
LDFLAGS += -X ${GIT_MODULE}.gitCommit=${GIT_COMMIT}
|
||||||
|
LDFLAGS += -X ${GIT_MODULE}.buildDate=${BUILD_DATE}
|
||||||
|
|
||||||
GO_FLAGS := -ldflags '-extldflags "-static"' -tags=netgo -trimpath
|
GO_FLAGS := -ldflags '-extldflags "-static"' -tags=netgo -trimpath
|
||||||
GO_FLAGS += -ldflags "-X ${GIT_MODULE}.gitVersion=${GIT_VERSION}"
|
GO_FLAGS += -ldflags '$(LDFLAGS)'
|
||||||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
||||||
ifeq (,$(shell go env GOBIN 2> /dev/null))
|
ifeq (,$(shell go env GOBIN 2> /dev/null))
|
||||||
GOBIN = $(shell go env GOPATH 2> /dev/null)/bin
|
GOBIN = $(shell go env GOPATH 2> /dev/null)/bin
|
||||||
|
@ -1 +1 @@
|
|||||||
airshipctl: devel
|
airshipctl: version.Info{GitVersion:"devel", GitCommit:"", BuildDate:""}
|
||||||
|
@ -41,5 +41,5 @@ func NewVersionCommand() *cobra.Command {
|
|||||||
|
|
||||||
func clientVersion() string {
|
func clientVersion() string {
|
||||||
v := version.Get()
|
v := version.Get()
|
||||||
return v.GitVersion
|
return fmt.Sprintf("%#v", v)
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ package version
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
gitVersion = "devel"
|
gitVersion = "devel"
|
||||||
|
gitCommit = ""
|
||||||
|
buildDate = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
// Info structure provides version data for airshipctl
|
// Info structure provides version data for airshipctl
|
||||||
@ -23,7 +25,9 @@ var (
|
|||||||
// provided from Makefile during building airshipctl
|
// provided from Makefile during building airshipctl
|
||||||
// or defined in a local var for development purposes
|
// or defined in a local var for development purposes
|
||||||
type Info struct {
|
type Info struct {
|
||||||
GitVersion string `json:"gitVersion"`
|
GitVersion string `json:"gitVersion,omitempty"`
|
||||||
|
GitCommit string `json:"gitCommit,omitempty"`
|
||||||
|
BuildDate string `json:"buildDate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get function shows airshipctl version
|
// Get function shows airshipctl version
|
||||||
@ -31,5 +35,7 @@ type Info struct {
|
|||||||
func Get() Info {
|
func Get() Info {
|
||||||
return Info{
|
return Info{
|
||||||
GitVersion: gitVersion,
|
GitVersion: gitVersion,
|
||||||
|
GitCommit: gitCommit,
|
||||||
|
BuildDate: buildDate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user