-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
85 lines (73 loc) · 2.62 KB
/
release.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
81
82
83
84
85
#!/bin/sh
set -eu
version="v0.0.2"
dev=false
dockerOnly=false
while [[ $# -gt 0 ]]; do
case $1 in
-v|--version)
version="$2"
shift
shift
;;
-dev)
dev=true
version="dev"
shift
;;
-d|--docker)
dockerOnly=true
shift
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
esac
done
build_darwin() {
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_darwin_x86_64.tar.gz -C bin jam && rm bin/jam
GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_darwin_arm64.tar.gz -C bin jam && rm bin/jam
}
build_linux() {
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_linux_x86_64.tar.gz -C bin jam && rm bin/jam
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_linux_arm64.tar.gz -C bin jam && rm bin/jam
}
build_windows() {
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_windows_x86_64.tar.gz -C bin jam && rm bin/jam
GOOS=windows GOARCH=arm64 go build -ldflags "-X main.version=$version" -o bin/jam && tar -czf release/jam_"$version"_windows_arm64.tar.gz -C bin jam && rm bin/jam
}
build_docker_hub() {
if [ "$dev" = false ]; then
docker buildx build --build-arg VERSION="$version" --push --platform=linux/amd64,linux/arm64 --tag=exelban/jam:latest .
fi
docker buildx build --build-arg VERSION="$version" --push --platform=linux/amd64,linux/arm64 --tag=exelban/jam:"$version" .
}
build_github_registry() {
if [ "$dev" = false ]; then
docker buildx build --build-arg VERSION="$version" --push --platform=linux/amd64,linux/arm64 --tag=ghcr.io/exelban/jam:latest .
fi
docker buildx build --build-arg VERSION="$version" --push --platform=linux/amd64,linux/arm64 --tag=ghcr.io/exelban/jam:"$version" .
}
if [ "$dev" = true ]; then
printf "\033[32;1m%s\033[0m\n" "Building dev version..."
else
printf "\033[32;1m%s\033[0m\n" "Building version ${version}..."
fi
build_docker_hub
build_github_registry
if [ "$dockerOnly" = false ]; then
printf "\033[32;1m%s\033[0m\n" "Building precompiled binaries with version ${version}..."
rm -rf "bin" && rm -rf "release"
mkdir -p "release"
echo "Building darwin..."
build_darwin
echo "Building linux..."
build_linux
echo "Building windows..."
build_windows
rm -rf "bin"
printf "\033[32;1m%s\033[0m\n" "JAM ${version} was successfully build."
open release
fi
exit 0