-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.sh
71 lines (52 loc) · 1.21 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
#!/bin/bash
# Copyright 2019-2020 Axetroy. All rights reserved. Apache License 2.0.
# Reference:
# https://github.com/golang/go/blob/master/src/go/build/syslist.go
os_archs=(
darwin/amd64
linux/amd64
windows/amd64
)
releases=()
fails=()
for os_arch in "${os_archs[@]}"
do
goos=${os_arch%/*}
goarch=${os_arch#*/}
filename=wsm
if [[ ${goos} == "windows" ]];
then
filename+=.exe
fi
echo building ${os_arch}
CGO_ENABLED=0 GOOS=${goos} GOARCH=${goarch} go build -mod=vendor -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -ldflags "-s -w" -o ./bin/${filename} ./cmd/user/main.go
# if build success
if [[ $? == 0 ]];then
releases+=(${os_arch})
cd ./bin
tar -czf wsm_${goos}_${goarch}.tar.gz ${filename}
rm -rf ./${filename}
cd ../
else
fails+=(${os_arch})
fi
done
echo
if [[ -n "$fails" ]]; then
echo "fails:"
for os_arch in "${fails[@]}"
do
printf "\t%s\n" "${os_arch}"
done
fi
if [[ -n "releases" ]]; then
echo "release:"
for os_arch in "${releases[@]}"
do
printf "\t%s\n" "${os_arch}"
done
else
echo "there's no build success"
exit 1
fi
echo