-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·94 lines (87 loc) · 1.99 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
cd "${DIR}"
go env > .go.env
source .go.env
EXECUTABLE_NAME="sqlow"
if [[ "${GOOS}" == "windows" ]]; then
EXECUTABLE_NAME="sqlow.exe" # For when it's --default
fi
DO_ALL=false
VERSION=$(cat ./main.go | grep 'var VERSION' | tr '"' ' ' | awk '{print $4}')
BUILD_ZIP=true
OUTPUT_DIR="./dist/${GOOS}-${GOARCH}"
for i in "$@"; do
case $i in
--all)
DO_ALL=true
shift
;;
--default)
shift
;;
--go-arch=*)
GOARCH="${i#*=}"
shift
;;
--windows)
GOOS="windows"
GOARCH="amd64"
EXECUTABLE_NAME="sqlow.exe"
shift
;;
--linux)
GOOS="linux"
GOARCH="amd64"
shift
;;
--macos)
GOOS="darwin"
GOARCH="amd64"
shift
;;
--macos-m1)
GOOS="darwin"
GOARCH="arm64"
shift
;;
--version=*)
VERSION="${i#*=}"
shift
;;
--no-zip)
BUILD_ZIP="false"
shift
;;
--output=*)
OUTPUT_DIR="${i#*=}"
shift
;;
*)
echo "Unknown option ${i}"
exit 1
;;
esac
done
if [[ "${DO_ALL}" == "true" ]]; then
rm -rf ./dist
./build.sh --windows --version=${VERSION}
./build.sh --linux --version=${VERSION}
./build.sh --macos --version=${VERSION}
./build.sh --macos-m1 --version=${VERSION}
else
mkdir -p dist/${GOOS}-${GOARCH}
go build -o "${OUTPUT_DIR}/${EXECUTABLE_NAME}" --ldflags="-X \"main.VERSION=${VERSION} ${GOOS}/${GOARCH}\"" main.go
if [[ "${BUILD_ZIP}" == "true" ]]; then
pushd "${OUTPUT_DIR}/" > /dev/null 2>&1
cp ${DIR}/config.template.yml config.yml
zip -r "../${GOOS}-${GOARCH}.zip" ./* > /dev/null
popd > /dev/null 2>&1
fi
fi