-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·59 lines (43 loc) · 1.36 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash -eu
SCRIPT_DIR=$(cd $(dirname $0); pwd)
# Get version from global/version.go
VERSION=`cat ./src/global/version.go | grep -o "Version.*\".*\"" | sed -e 's/.*=\s//g' -e 's/"//g'`
COMMIT=`git rev-parse --short HEAD`
if ! git diff --quiet; then
COMMIT="${COMMIT}-working"
fi
BIN_BASENAME=b-route-reader-go
ENTRYPOINT=main.go
BUILD_DIR=./build
BIN_DIR=${SCRIPT_DIR}/${BUILD_DIR}/bin
WORK_DIR=${SCRIPT_DIR}/${BUILD_DIR}/work
RELEASE_DIR=${SCRIPT_DIR}/${BUILD_DIR}/release
# MAIN
sed -i src/global/version.go -e 's/GitBuild = ".*"/GitBuild = "$COMMIT"/g'
# delete build dir
rm -rf ${BUILD_DIR}
mkdir -p ${BIN_DIR}
mkdir -p ${RELEASE_DIR}
mkdir -p ${WORK_DIR}
cp LICENSE ${WORK_DIR}
cp README.md ${WORK_DIR}
function build_unixlike () {
# $1 OS $2 ARCH
echo Building $1 $2 binary
FINAL_PATH=${RELEASE_DIR}/${BIN_BASENAME}_${VERSION}_$1_$2.tar.gz
GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -o ${BIN_DIR}/${BIN_BASENAME} ${ENTRYPOINT}
# copy bin to work
cp ${BIN_DIR}/${BIN_BASENAME} ${WORK_DIR}/
# copyback bin
cp ${BIN_DIR}/${BIN_BASENAME} ${BIN_DIR}/${BIN_BASENAME}_$1_$2
ORG_DIR=`pwd`
cd ${WORK_DIR}
tar -cvzf ${FINAL_PATH} --exclude *.tar.gz ./*
cd ${ORG_DIR}
echo "done => ${FINAL_PATH}"
}
# Unixlike
build_unixlike linux amd64
build_unixlike linux arm
build_unixlike linux arm64
git checkout src/global/version.go