forked from uber/cadence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-build-ldflags.sh
executable file
·44 lines (37 loc) · 1.49 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
37
38
39
40
41
42
43
44
#!/bin/sh
MODE=$1
if [ "$MODE" != "LDFLAG" ] && [ "$MODE" != "ECHO" ]; then
echo "Usage: $0 <LDFLAG|ECHO>"
exit 1
fi
# $(git rev-parse --short HEAD) \"$(git log -1 --format=%cI-%h)\"
export GIT_REVISION=$(git log -1 --format=%cI-%h) # use commit date time and hash: e.g. 2021-07-27 19:36:53 -0700-40c5f1896, doc: https://git-scm.com/docs/pretty-formats
export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
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 [ -z ${CADENCE_RELEASE_VERSION} ]; then
# If not set CADENCE_RELEASE_VERSION, then use the most recent tag.
export RELEASE_VERSION=$(git describe --tags --abbrev=0 --dirty 2>/dev/null || echo unknown)
else
# If passing a CADENCE_RELEASE_VERSION explicitly, then use it
export RELEASE_VERSION=${CADENCE_RELEASE_VERSION}
fi
if [ "$MODE" = "LDFLAG" ]; then
LD_FLAGS="-X ${BASE_PACKAGE}.Revision=${GIT_REVISION} \
-X ${BASE_PACKAGE}.Branch=${GIT_BRANCH} \
-X ${BASE_PACKAGE}.ReleaseVersion=${RELEASE_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