forked from XiaoMengXinX/Fuck163MusicTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
32 lines (24 loc) · 579 Bytes
/
build.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
#!/bin/bash
COMMIT_SHA=$(git rev-parse HEAD)
VERSION=$(git describe --tags)
BUILD_TIME=$(date +'%Y-%m-%d %T')
CUSTOM_GOOS=$1
CUSTOM_GOARCH=$2
OUTPUT_ARG=""
if [[ "$CUSTOM_GOOS" != "" ]]; then
export GOOS="$CUSTOM_GOOS"
fi
if [[ "$CUSTOM_GOARCH" != "" ]]; then
export GOARCH="$CUSTOM_GOARCH"
fi
if [[ "$3" == "-o" ]]; then
export OUTPUT_ARG="-o $4"
fi
export CGO_ENABLED=0
LDFlags="\
-s -w
-X 'main.version=${VERSION}' \
-X 'main.commitSHA=${COMMIT_SHA}' \
-X 'main.buildTime=${BUILD_TIME}' \
"
go build ${OUTPUT_ARG} -trimpath -ldflags "${LDFlags}"