Skip to content

Commit d5b2f84

Browse files
committed
[add] added git version info. Fixed cross-slot issue
1 parent 41b38c1 commit d5b2f84

File tree

4 files changed

+904
-15
lines changed

4 files changed

+904
-15
lines changed

Makefile

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ DIST_OS_ARCHS = "linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64
1515
.PHONY: all test coverage
1616
all: test coverage build
1717

18+
# Build-time GIT variables
19+
ifeq ($(GIT_SHA),)
20+
GIT_SHA:=$(shell git rev-parse HEAD)
21+
endif
22+
23+
ifeq ($(GIT_DIRTY),)
24+
GIT_DIRTY:=$(shell git diff --no-ext-diff 2> /dev/null | wc -l)
25+
endif
26+
1827
build:
19-
$(GOBUILD) .
28+
$(GOBUILD) -ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" .
2029

2130
build-race:
22-
$(GOBUILDRACE) .
31+
$(GOBUILDRACE) -ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" .
2332

2433
checkfmt:
2534
@echo 'Checking gofmt';\
@@ -48,7 +57,9 @@ coverage: get test
4857
release:
4958
$(GOGET) github.com/mitchellh/gox
5059
$(GOGET) github.com/tcnksm/ghr
51-
GO111MODULE=on gox -osarch ${DIST_OS_ARCHS} -output "${DISTDIR}/${BIN_NAME}_{{.OS}}_{{.Arch}}" .
60+
GO111MODULE=on gox -osarch ${DIST_OS_ARCHS} \
61+
-output "${DISTDIR}/${BIN_NAME}_{{.OS}}_{{.Arch}}" \
62+
-ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" .
5263

5364
publish: release
5465
@for f in $(shell ls ${DISTDIR}); \

0 commit comments

Comments
 (0)