forked from uber/cadence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-build-ldflags.sh
executable file
·36 lines (30 loc) · 1.05 KB
/
go-build-ldflags.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh
MODE=$1
if [ "$MODE" != "LDFLAG" ] && [ "$MODE" != "ECHO" ]; then
echo "Usage: $0 <LDFLAG|ECHO>"
exit 1
fi
export GIT_REVISION=$(git rev-parse --short HEAD)
export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
export GIT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo unknown)
export BUILD_DATE=$(date '+%F-%T') # outputs something in this format 2017-08-21-18:58:45
export BUILD_TS_UNIX=$(date '+%s') # second since epoch
export BASE_PACKAGE=github.com/uber/cadence/common/metrics
if [ "$MODE" = "LDFLAG" ]; then
LD_FLAGS="-X ${BASE_PACKAGE}.Revision=${GIT_REVISION} \
-X ${BASE_PACKAGE}.Branch=${GIT_BRANCH} \
-X ${BASE_PACKAGE}.Version=${GIT_VERSION} \
-X ${BASE_PACKAGE}.BuildDate=${BUILD_DATE} \
-X ${BASE_PACKAGE}.BuildTimeUnix=${BUILD_TS_UNIX}"
echo $LD_FLAGS
fi
if [ "$MODE" = "ECHO" ]; then
cat <<EOF
BASE_PACKAGE=${BASE_PACKAGE}
GIT_REVISION=${GIT_REVISION}
GIT_BRANCH=${GIT_BRANCH}
GIT_VERSION=${GIT_VERSION}
BUILD_DATE=${BUILD_DATE}
BUILD_TS_UNIX=${BUILD_TS_UNIX}
EOF
fi