-
Notifications
You must be signed in to change notification settings - Fork 250
/
build.sh
executable file
·154 lines (140 loc) · 5.59 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
set -e
cd "$(dirname "${0}")"
####################################################################
# The next 3 lines are automatically edited by
# infrastructure/tooling/src/generate/generators/go-version.js
#
# DO NOT CHANGE HERE!
####################################################################
# Support go 1.21 or higher.
GO_MAJOR_VERSION=1
MIN_GO_MINOR_VERSION=21
unset CGO_ENABLED
unset GOOS
GO_VERSION="$(go version 2>/dev/null | cut -f3 -d' ')"
GO_MAJ="$(echo "${GO_VERSION}" | cut -f1 -d'.')"
GO_MIN="$(echo "${GO_VERSION}" | cut -f2 -d'.')"
if [ -z "${GO_VERSION}" ]; then
echo "Have you installed go? I get no result from \`go version\` command." >&2
exit 64
elif [ "${GO_MAJ}" != "go${GO_MAJOR_VERSION}" ] || [ "${GO_MIN}" -lt "${MIN_GO_MINOR_VERSION}" ]; then
echo "Go version go${GO_MAJOR_VERSION}.x needed, where x >= ${MIN_GO_MINOR_VERSION}, but the version I found is: '${GO_VERSION}'" >&2
echo "I found it here:" >&2
which go >&2
echo "The complete output of \`go version\` command is:" >&2
go version >&2
exit 65
fi
echo "Go version ok (${GO_VERSION} >= go${GO_MAJOR_VERSION}.${MIN_GO_MINOR_VERSION})"
TEST=false
PUBLISH=false
OUTPUT_ALL_PLATFORMS="Building just for the multiuser platform (build.sh -a argument NOT specified)"
OUTPUT_TEST="Test flag NOT detected (-t) as argument to build.sh script"
OUTPUT_DIR=.
ALL_PLATFORMS=false
SKIP_CODE_GEN=false
while getopts ":atpso:" opt; do
case "${opt}" in
a) ALL_PLATFORMS=true
OUTPUT_ALL_PLATFORMS="Building for all platforms (build.sh -a argument specified)"
;;
t) TEST=true
OUTPUT_TEST="Test flag detected (-t) as build.sh argument"
;;
p) PUBLISH=true
ALL_PLATFORMS=true
SKIP_CODE_GEN=true
OUTPUT_ALL_PLATFORMS="Publishing (build.sh -p argument specified)"
;;
o) OUTPUT_DIR=$OPTARG
;;
s) SKIP_CODE_GEN=true
echo "Skipping code generation (build.sh -s argument specified)"
esac
done
echo "${OUTPUT_ALL_PLATFORMS}"
echo "${OUTPUT_TEST}"
if ! $SKIP_CODE_GEN; then
go install ./gw-codegen
export PATH="$(go env GOPATH)/bin:${PATH}"
go generate ./...
fi
function install {
if ! $PUBLISH; then
GOOS="${2}" GOARCH="${3}" go vet -tags "${1}" ./...
# note, this just builds tests, it doesn't run them!
go list ./... | while read package; do
GOOS="${2}" GOARCH="${3}" CGO_ENABLED=0 go test -tags "${1}" -c "${package}"
done
fi
GOOS="${2}" GOARCH="${3}" CGO_ENABLED=0 go build -o "$OUTPUT_DIR/generic-worker-${1}-${2}-${3}" -ldflags "-X main.revision=$(git rev-parse HEAD)" -tags "${1}" -v .
# check that revision number made it into target binary
if [ "${2}" == "$(go env GOHOSTOS)" ] && [ "${3}" == "$(go env GOHOSTARCH)" ]; then
if ! "$OUTPUT_DIR/generic-worker-${1}-${2}-${3}" --version | \
grep -Eq 'revision: https://github.com/taskcluster/taskcluster/commits/[a-z0-9]{40}'; then
echo "The --version option does not output a proper revision link"
exit 1
else
# ANSI escape sequence for green tick
echo -e "\x1b\x5b\x33\x32\x6d\xe2\x9c\x93\x1b\x5b\x30\x6d Revision number included in $OUTPUT_DIR/generic-worker-${1}-${2}-${3}"
fi
fi
}
# NOTE: when changing this, also update
# ui/docs/reference/workers/generic-worker/support-tiers.mdx
if ${ALL_PLATFORMS}; then
install multiuser windows amd64
install multiuser windows 386
install multiuser darwin amd64
install multiuser darwin arm64
install simple darwin amd64
install simple darwin arm64
install multiuser linux amd64
install multiuser linux arm64
install simple linux amd64
install simple linux arm64
install multiuser freebsd amd64
install multiuser freebsd arm64
install simple freebsd amd64
install simple freebsd arm64
else
MY_GOHOSTOS="$(go env GOHOSTOS)"
MY_GOHOSTARCH="$(go env GOHOSTARCH)"
case "${MY_GOHOSTOS}" in
linux) install simple "${MY_GOHOSTOS}" "${MY_GOHOSTARCH}"
install multiuser "${MY_GOHOSTOS}" "${MY_GOHOSTARCH}"
;;
darwin) install simple "${MY_GOHOSTOS}" "${MY_GOHOSTARCH}"
install multiuser "${MY_GOHOSTOS}" "${MY_GOHOSTARCH}"
;;
freebsd) install simple "${MY_GOHOSTOS}" "${MY_GOHOSTARCH}"
install multiuser "${MY_GOHOSTOS}" "${MY_GOHOSTARCH}"
;;
windows) install multiuser "${MY_GOHOSTOS}" "${MY_GOHOSTARCH}"
;;
esac
fi
ls -1 "$OUTPUT_DIR"/generic-worker-*
proj_root=$(go list . | sed -e 's!/workers/generic-worker$!!' )
CGO_ENABLED=0 go install "${proj_root}/tools/livelog@latest"
CGO_ENABLED=0 go install "${proj_root}/tools/taskcluster-proxy@latest"
CGO_ENABLED=0 go install "${proj_root}/workers/generic-worker/resolvetask@latest"
CGO_ENABLED=0 go install golang.org/x/lint/golint@latest
CGO_ENABLED=0 go install github.com/gordonklaus/ineffassign@latest
CGO_ENABLED=0 go install golang.org/x/tools/cmd/goimports@latest
if $TEST; then
####################################################################
# The version number in this line is automatically updated by
# infrastructure/tooling/src/release/tasks.js
# when a new major release is made.
####################################################################
CGO_ENABLED=1 GORACE="history_size=7" go test -tags simple -failfast -ldflags "-X github.com/taskcluster/taskcluster/v58/workers/generic-worker.revision=$(git rev-parse HEAD)" -race -timeout 1h ./...
golint $(go list ./...) | sed "s*${PWD}/**"
ineffassign .
goimports -w .
fi
echo "Build successful!"
if ! $PUBLISH; then
git status
fi