-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·62 lines (53 loc) · 1.61 KB
/
deploy.sh
File metadata and controls
executable file
·62 lines (53 loc) · 1.61 KB
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
#!/bin/sh
set -eu
# GoZen deploy script - builds binaries for GitHub Releases
# Usage:
# ./deploy.sh Build for current platform
# ./deploy.sh --all Build for all supported platforms
#
# Binaries are placed in dist/ with naming: zen-<os>-<arch>
# Upload them to GitHub Releases. install.sh will download them by this name.
VERSION="$(grep 'var Version' cmd/root.go | sed 's/.*"\(.*\)"/\1/')" || { echo "Error: Version not found in cmd/root.go"; exit 1; }
if [ -z "$VERSION" ]; then
echo "Error: Version not found in cmd/root.go"
exit 1
fi
DIST_DIR="dist"
PROJECT="zen"
info() { printf "\033[1;34m==>\033[0m %s\n" "$1"; }
ok() { printf "\033[1;32m==>\033[0m %s\n" "$1"; }
err() { printf "\033[1;31mError:\033[0m %s\n" "$1" >&2; }
if ! command -v go >/dev/null 2>&1; then
err "Go compiler not found. Install Go from https://go.dev/dl/"
exit 1
fi
rm -rf "$DIST_DIR"
mkdir -p "$DIST_DIR"
build_binary() {
_os="$1"
_arch="$2"
_out="${DIST_DIR}/${PROJECT}-${_os}-${_arch}"
info "Building ${_os}/${_arch}..."
GOOS="$_os" GOARCH="$_arch" go build -ldflags="-s -w" -o "$_out" .
ok "Created ${_out}"
}
case "${1:-}" in
--all)
build_binary darwin amd64
build_binary darwin arm64
build_binary linux amd64
build_binary linux arm64
;;
*)
_os="$(uname -s | tr '[:upper:]' '[:lower:]')"
_arch="$(uname -m)"
case "$_arch" in
x86_64) _arch="amd64" ;;
aarch64) _arch="arm64" ;;
esac
build_binary "$_os" "$_arch"
;;
esac
printf "\n"
ok "Build complete (v${VERSION})"
info "Upload binaries in ${DIST_DIR}/ to GitHub Releases tag v${VERSION}"