-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·79 lines (66 loc) · 2.06 KB
/
make.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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
# Use xtrace for debugging.
#set -o xtrace
# Capture arguments then disable unset variables.
FUNC=$1
set -o nounset
PROJECT_NAME="launchpoint"
REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BUILD_DIR="${REPO_ROOT}/builds"
VERSION="v0.0.1"
COMMIT=$(git rev-list -1 HEAD)
DATE=$(date -uR)
GOVERSION=$(go version | awk '{print $3 " " $4}')
function build() {
cd "$REPO_ROOT"
BUILD_GOOS=${1:-$(go env GOOS)}
BUILD_GOARCH=${2:-$(go env GOARCH)}
BUILD_OUTPUT="${BUILD_DIR}/${PROJECT_NAME}-${VERSION}-${BUILD_GOOS}-${BUILD_GOARCH}/${PROJECT_NAME}"
LDFLAGS="-X \"main.Version=${VERSION}\""
LDFLAGS="${LDFLAGS} -X \"main.Platform=${BUILD_GOOS}/${BUILD_GOARCH}\""
LDFLAGS="${LDFLAGS} -X \"main.Commit=${COMMIT}\""
LDFLAGS="${LDFLAGS} -X \"main.BuildDate=${DATE}\""
LDFLAGS="${LDFLAGS} -X \"main.GoVersion=${GOVERSION}\""
echo "Building ${PROJECT_NAME} ${VERSION} ${BUILD_GOOS} ${BUILD_GOARCH}."
GOOS=$BUILD_GOOS GOARCH=$BUILD_GOARCH CGO_ENABLED=0 GO111MODULE=on go build -ldflags "${LDFLAGS}" -o "${BUILD_OUTPUT}" .
}
function build-all() {
build linux arm
build linux arm64
}
function package-all() {
if [ ! -d "${BUILD_DIR}" ]; then
echo "No builds to package."
exit
fi
for BUILD in "${BUILD_DIR}"/*; do
if [ ! -d "${BUILD}" ]; then
continue
fi
ZIP_NAME=${BUILD_DIR}/$(basename "${BUILD}").zip
if [ ! -f "${ZIP_NAME}" ]; then
rm "${ZIP_NAME}"
fi
echo "Packaging build ${ZIP_NAME}."
cd "${BUILD}"
zip -q "${ZIP_NAME}" ./*
done
}
function install() {
build
cp "${BUILD_OUTPUT}" "${GOPATH}/bin"
}
function clean() {
rm -r "${BUILD_DIR}"
}
# Check the first argument passed is a function.
if [ "$(type -t $FUNC)" != "function" ]; then
# If not warn and print the list of functions.
echo "No target: $FUNC"
echo "Try: $0 { $(compgen -A function | tr '\n' ' ')}"
exit 1
fi
# Run the function named by the first argument.
$FUNC