|  | # adapted from the hack scripts in kubernetes/kubernetes | 
|  |  | 
|  | GIT_COMMIT:=$(shell git rev-parse "HEAD^{commit}" 2>/dev/null) | 
|  |  | 
|  | # the raw git version from `git describe` -- our starting point | 
|  | GIT_VERSION_RAW:=$(shell git describe --tags --abbrev=14 "$(GIT_COMMIT)^{commit}" 2>/dev/null) | 
|  |  | 
|  | # use the number of dashes in the raw version to figure out what kind of | 
|  | # version this is, and turn it into a semver-compatible version | 
|  | DASHES_IN_VERSION:=$(shell echo "$(GIT_VERSION_RAW)" | sed "s/[^-]//g") | 
|  |  | 
|  | # just use the raw version by default | 
|  | GIT_VERSION:=$(GIT_VERSION_RAW) | 
|  |  | 
|  | ifeq ($(DASHES_IN_VERSION), ---) | 
|  | # we have a distance to a subversion (v1.1.0-subversion-1-gCommitHash) | 
|  | GIT_VERSION:=$(shell echo "$(GIT_VERSION_RAW)" | sed "s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{14\}\)$$/.\1\+\2/") | 
|  | endif | 
|  | ifeq ($(DASHES_IN_VERSION), --) | 
|  | # we have distance to base tag (v1.1.0-1-gCommitHash) | 
|  | GIT_VERSION:=$(shell echo "$(GIT_VERSION_RAW)" | sed "s/-g\([0-9a-f]\{14\}\)$$/+\1/") | 
|  | endif | 
|  |  | 
|  | # figure out if we have new or changed files | 
|  | ifeq ($(shell git status --porcelain 2>/dev/null), "") | 
|  | GIT_TREE_STATE:=clean | 
|  | else | 
|  | # append the -dirty manually, since `git describe --dirty` only considers | 
|  | # changes to existing files | 
|  | GIT_TREE_STATE:=dirty | 
|  | GIT_VERSION:=$(GIT_VERSION)-dirty | 
|  | endif | 
|  |  | 
|  | # construct a "shorter" version without the commit info, etc for use as container image tag, etc | 
|  | VERSION?=$(shell echo "$(GIT_VERSION)" | grep -E -o '^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(-(alpha|beta)\.[[:digit:]]+)?') | 
|  |  | 
|  | # construct the build date, taking into account SOURCE_DATE_EPOCH, which is | 
|  | # used for the purpose of reproducible builds | 
|  | ifdef SOURCE_DATE_EPOCH | 
|  | BUILD_DATE:=$(shell date --date=@${SOURCE_DATE_EPOCH} -u +'%Y-%m-%dT%H:%M:%SZ') | 
|  | else | 
|  | BUILD_DATE:=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') | 
|  | endif | 
|  |  | 
|  | # set the build information version ldflags (but not other ldflags) | 
|  | VERSION_LDFLAGS:=-X github.com/kubernetes-incubator/metrics-server/pkg/version.gitVersion=$(GIT_VERSION) -X github.com/kubernetes-incubator/metrics-server/pkg/version.gitCommit=$(GIT_COMMIT) -X github.com/kubernetes-incubator/metrics-server/pkg/version.gitTreeState=$(GIT_TREE_STATE) -X github.com/kubernetes-incubator/metrics-server/pkg/version.buildDate=$(BUILD_DATE) | 
|  |  | 
|  | export VERSION | 
|  | export VERSION_LDFLAGS | 
|  |  | 
|  | # print out a summary of the current version info | 
|  | version-info: | 
|  | @echo "Version: $(GIT_VERSION) ($(VERSION))" | 
|  | @echo "    built from $(GIT_COMMIT) ($(GIT_TREE_STATE))" | 
|  | @echo "    built on $(BUILD_DATE)" | 
|  | .PHONY: version-info |