forked from kool-dev/kool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_artifacts.sh
executable file
·80 lines (66 loc) · 1.98 KB
/
build_artifacts.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
#!/bin/bash
while [ $# -gt 0 ]; do
case "$1" in
--version )
BUILD_VERSION="$2"
shift 2
;;
-- )
shift
break
;;
*)
echo "Invalid Argument: ${1}"
exit 1
;;
esac
done
if [ -f .env ]; then
source .env
fi
GO_IMAGE=${GO_IMAGE:-golang:1.19}
if [ "$BUILD_VERSION" == "" ]; then
echo "missing environment variable BUILD_VERSION"
exit 5
fi
read -p "You are going to build all artifacts for version $BUILD_VERSION. Continue? (y/N) "
if [[ ! $REPLY =~ ^(yes|YES|y|Y)$ ]]
then
exit
fi
rm -rf dist
mkdir -p dist
# ATTENTION - binary names must match the -GOOS-GOARCH suffix
# because self-update relies on this pattern to work.
BUILD=(\
"dist/kool-darwin-amd64|--env GOOS=darwin --env GOARCH=amd64" \
"dist/kool-darwin-arm64|--env GOOS=darwin --env GOARCH=arm64" \
"dist/kool-linux-amd64|--env GOOS=linux --env GOARCH=amd64" \
"dist/kool-linux-arm6|--env GOOS=linux --env GOARCH=arm --env GOARM=6" \
"dist/kool-linux-arm7|--env GOOS=linux --env GOARCH=arm --env GOARM=7" \
"dist/kool-windows-amd64.exe|--env GOOS=windows --env GOARCH=amd64" \
"dist/kool-linux-arm64|--env GOOS=linux --env GOARCH=arm64" \
)
for i in "${!BUILD[@]}"; do
dist=$(echo ${BUILD[$i]} | cut -d'|' -f1)
flags=$(echo ${BUILD[$i]} | cut -d'|' -f2)
echo "Building to ${flags}"
docker run --rm \
$flags \
--env CGO_ENABLED=0 \
-v $(pwd):/code -w /code $GO_IMAGE \
go build -a -tags 'osusergo netgo static_build' \
-ldflags '-X kool-dev/kool/commands.version='$BUILD_VERSION' -extldflags "-static"' \
-o $dist
done
echo "Building kool-install.exe"
cp dist/kool-windows-amd64.exe dist/kool.exe
docker run --rm -i \
-v $(pwd):/work -w /work \
amake/innosetup /dApplicationVersion=$BUILD_VERSION inno-setup/kool.iss
mv inno-setup/Output/mysetup.exe dist/kool-install.exe
echo "Going to generate CHECKSUMS"
for file in dist/*; do
shasum -a 256 $file > $file.sha256
done
echo "Finished building all artifacts for version $BUILD_VERSION"