From a7e9fbaf79e594d5c8212534e802d760e2dae196 Mon Sep 17 00:00:00 2001 From: Ashish Amarnath Date: Wed, 17 Jun 2020 07:28:18 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=83=E2=80=8D=E2=99=82=EF=B8=8F=20pass?= =?UTF-8?q?=20git=20state=20to=20build=20from=20makefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ashish Amarnath --- Makefile | 8 ++++++++ hack/build.sh | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 706fd7171..baaf1a949 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,10 @@ CLI_PLATFORMS ?= linux-amd64 linux-arm linux-arm64 darwin-amd64 windows-amd64 li CONTAINER_PLATFORMS ?= linux-amd64 linux-ppc64le linux-arm linux-arm64 MANIFEST_PLATFORMS ?= amd64 ppc64le arm arm64 +# set git sha and tree state +GIT_SHA = $(shell git rev-parse HEAD) +GIT_DIRTY = $(shell git status --porcelain 2> /dev/null) + ### ### These variables should not need tweaking. ### @@ -113,6 +117,8 @@ local: build-dirs VERSION=$(VERSION) \ PKG=$(PKG) \ BIN=$(BIN) \ + GIT_SHA=$(GIT_SHA) \ + GIT_DIRTY="$(GIT_DIRTY)" \ OUTPUT_DIR=$$(pwd)/_output/bin/$(GOOS)/$(GOARCH) \ ./hack/build.sh @@ -126,6 +132,8 @@ _output/bin/$(GOOS)/$(GOARCH)/$(BIN): build-dirs VERSION=$(VERSION) \ PKG=$(PKG) \ BIN=$(BIN) \ + GIT_SHA=$(GIT_SHA) \ + GIT_DIRTY=\"$(GIT_DIRTY)\" \ OUTPUT_DIR=/output/$(GOOS)/$(GOARCH) \ ./hack/build.sh'" diff --git a/hack/build.sh b/hack/build.sh index bdbfcdb73..641e27d28 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -39,10 +39,13 @@ if [ -z "${VERSION}" ]; then exit 1 fi +if [ -z "${GIT_SHA}" ]; then + echo "GIT_SHA must be set" + exit 1 +fi + export CGO_ENABLED=0 -GIT_SHA=$(git rev-parse HEAD) -GIT_DIRTY=$(git status --porcelain 2> /dev/null) if [[ -z "${GIT_DIRTY}" ]]; then GIT_TREE_STATE=clean else