forked from shazow/ssh-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_release
executable file
·67 lines (52 loc) · 1.31 KB
/
build_release
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
#!/usr/bin/env bash
usage() {
echo "Build and bundle Go releases with the current dir as the build dir."
echo "Usage: $0 PACKAGE [ASSETS...]"
}
main() {
set -eo pipefail
[[ "$TRACE" ]] && set -x
if [[ ! "$1" ]]; then
usage
exit 1
fi
if [[ ! "$GOOS" ]]; then
export GOOS="linux"
echo "Defaulting to GOOS=$GOOS"
fi
if [[ ! "$GOARCH" ]]; then
export GOARCH="amd64"
echo "Defaulting to GOARCH=$GOARCH"
fi
if [[ ! "$BUILDDIR" ]]; then
export BUILDDIR="build"
echo "Defaulting to BUILDDIR=$BUILDDIR"
fi
build "$@"
}
build() {
local package="$1"; shift
local assets="$@"
local bin="$(basename $package)"
local tarball="${bin}-${GOOS}_${GOARCH}.tgz"
local outdir="$BUILDDIR/$bin"
local tardir="$bin"
if [ "$GOOS" == "windows" ]; then
bin="$bin.exe"
fi
if [[ -d "$outdir" ]]; then
echo "err: outdir already exists: $PWD/$outdir"
fi
mkdir -p "$outdir"
go build -ldflags "$LDFLAGS" -o "$outdir/$bin" "$package"
# Stage asset bundle
if [[ "$assets" ]]; then
ln -f $assets "$outdir"
fi
# Create tarball
tar -C "$BUILDDIR" -czvf "$BUILDDIR/$tarball" "$tardir"
# Cleanup
rm -rf "$outdir"
echo "Packaged: $tarball"
}
main "$@"