-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·59 lines (50 loc) · 1.3 KB
/
deploy.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
#!/usr/bin/env bash
export GOPATH=$(pwd)
echo 'GOPATH:' $GOPATH
package=$1
if [[ -z "$package" ]]; then
echo "usage: $0 <package-name>"
exit 1
fi
ret=""
function join_by { local IFS="$1"; shift; ret="$*"; }
package=$1
package_list=($(echo "$package" | tr '/' ' '))
exe_file=${package_list[*]:(-1)}
unset 'package_list[${#package_list[@]}-1]'
join_by / ${package_list[*]}
package_path=$ret
unset 'package_list[0]'
join_by / ${package_list[*]}
package_name=$ret
exe_file=($(echo "$exe_file" | tr '.' '\n'))
exe_name=${exe_file[0]}
platforms=(
"linux/amd64"
"linux/386"
"windows/amd64"
"windows/386"
"darwin/amd64"
"darwin/386"
)
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
echo "building for" $GOOS $GOARCH
output_path=bin/$GOOS/$GOARCH/$package_name
output_name=$output_path/$exe_name
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi
env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $package
for dependency in $(source $package_path/dependencies.sh)
do
cp ./$package_path/$dependency ./$output_path/$dependency
done
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done