-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathbuild.sh
executable file
·35 lines (30 loc) · 971 Bytes
/
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
#!/usr/bin/env bash
package=goca/goca.go
package_name=goca
buildDate=$(date -R)
gitTag=$(git describe --exact-match HEAD 2> /dev/null)
gitCommit=$(git rev-parse HEAD)
build_dir=build/
ldflags="-X \"main.buildDate=$buildDate\" \
-X \"main.gitTag=$gitTag\" \
-X \"main.gitCommit=$gitCommit\" \
-s \
-w"
platforms=("windows/amd64" "windows/386" "darwin/amd64" "linux/amd64" "linux/386" "linux/arm64" "linux/arm")
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name'-'$GOOS'-'$GOARCH
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi
GOOS=$GOOS GOARCH=$GOARCH go build -o $build_dir$output_name -ldflags "$ldflags" $package
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
else
sha256sum $build_dir$output_name > $build_dir$output_name.sha256
fi
done