forked from gocd-contrib/gocd-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·105 lines (87 loc) · 1.77 KB
/
build.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
set -e
cd "$(dirname "$0")"
PROGNAME="gocd"
rm -f "$PROGNAME"
rm -rf dist
RELEASE="X.x.x"
for arg in $@; do
case $arg in
--verbose)
extra_flags="$extra_flags -v"
shift
;;
--skip-tests)
skip=true
shift
;;
--prod)
multiplatform=true
shift
;;
--release)
RELEASE="$2"
shift
;;
--release=*)
RELEASE="${arg#*=}"
shift
;;
*)
shift
;;
esac
done
RELEASE="${RELEASE}-${GO_PIPELINE_LABEL:-localbuild}"
function ldflags {
local _os="${1:-$(go env GOOS)}"
local _arch="${2:-$(go env GOARCH)}"
echo "-X main.Version=${RELEASE} -X main.GitCommit=${GIT_COMMIT} -X main.Platform=${_arch}-${_os}"
}
echo "Fetching dependencies"
go get -tags netgo -d $extra_flags ./...
if [[ "true" = "$skip" ]]; then
echo "Skipping tests"
else
go test $extra_flags ./...
fi
if (which git &> /dev/null); then
GIT_COMMIT=$(git rev-list --abbrev-commit -1 HEAD)
else
GIT_COMMIT="unknown"
fi
if [[ "true" = "$multiplatform" ]]; then
platforms=(
darwin/amd64
freebsd/386
freebsd/amd64
linux/386
linux/amd64
linux/arm
linux/arm64
windows/386
windows/amd64
)
echo "Release: $RELEASE, Revision: $GIT_COMMIT"
for plt in "${platforms[@]}"; do
mkdir -p "dist/${plt}"
arr=(${plt//\// })
_os="${arr[0]}"
_arch="${arr[1]}"
name="$PROGNAME"
if [ "windows" = "${_os}" ]; then
name="$name.exe"
fi
echo "Building $plt..."
GOOS="${_os}" go get -tags netgo -d $extra_flags ./...
GOOS="${_os}" GOARCH="${_arch}" go build \
-tags netgo \
-a \
-o "dist/${plt}/${name}" \
-ldflags "$(ldflags "$_os" "$_arch")"
done
else
go build \
-ldflags "$(ldflags)" \
-o "$PROGNAME"
fi