-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_app.bash
executable file
·46 lines (38 loc) · 1.04 KB
/
build_app.bash
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
#!/usr/bin/env bash
package="github.com/AutomatedProcessImprovement/waiting-time-backend"
package_name="waiting-time-backend"
platforms=("linux/amd64" "darwin/amd64" "darwin/arm64" "windows/amd64")
go generate .
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
dir_name="$GOOS-$GOARCH"
build_dir="build/$dir_name"
output_name="$build_dir/$package_name"
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi
# clean build_dir if it exists
if [ -d "$build_dir" ]; then
rm -rf "$build_dir"
fi
# providing static assets for the server
mkdir -p "$build_dir/assets"
cp -r assets/samples "$build_dir/assets"
env GOOS="$GOOS" GOARCH="$GOARCH" go build -o $output_name $package
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
# archive the builds
(
cd build
if [ $GOOS = "windows" ]; then
zip -r "$dir_name.zip" "$dir_name"
else
tar -czf "$dir_name.tar.gz" "$dir_name"
fi
)
done