Skip to content

Commit 7ac2ea6

Browse files
authored
ci(microbenchmark): use gvm instead of g with retries (#14856)
1 parent 5dfb894 commit 7ac2ea6

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

.ci/scripts/bench.sh

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ function buildkite::download_last_artifact {
125125
BUILDKITE_DOWNLOAD_URL="${download_url}" buildkite::req_download_artifact
126126
}
127127

128+
#######################################
129+
# Retry n number of times the given command
130+
function retry() {
131+
local retries=$1
132+
shift
133+
134+
local count=0
135+
until "$@"; do
136+
exit=$?
137+
wait=$((2 ** count))
138+
count=$((count + 1))
139+
if [ $count -lt "$retries" ]; then
140+
>&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
141+
sleep $wait
142+
else
143+
>&2 echo "Retry $count/$retries exited $exit, no more retries left."
144+
return $exit
145+
fi
146+
done
147+
return 0
148+
}
149+
128150
## Buildkite specific configuration
129151
if [ "${CI}" == "true" ] ; then
130152
# If HOME is not set then use the Buildkite workspace
@@ -147,17 +169,20 @@ if [ "${CI}" == "true" ] ; then
147169
[ -z "${REPO}" ] && echo "Environment variable 'REPO' must be defined" && exit 1;
148170
export BUILDKITE_TOKEN="${BUILDKITE_TOKEN_SECRET}"
149171

172+
echo "--- Setting up the :golang: environment..."
173+
GO_VERSION=$(cat .go-version)
174+
OS_NAME=linux
175+
OS_ARCH=amd64
176+
retry 5 curl -sL -o "${BASE_PROJECT}"/gvm "https://github.com/andrewkroh/gvm/releases/download/v0.5.2/gvm-${OS_NAME}-${OS_ARCH}"
177+
chmod +x "${BASE_PROJECT}"/gvm
178+
retry 5 "${BASE_PROJECT}"/gvm install "$GO_VERSION"
179+
eval "$("${BASE_PROJECT}"/gvm use "$GO_VERSION")"
180+
echo "Golang version:"
181+
go version
182+
GOPATH=$(command go env GOPATH)
150183
# Redirect go env to current dir
151-
export GOROOT="${BASE_PROJECT}/.go"
152-
export GOPATH="${BASE_PROJECT}/go"
153184
export PATH="${GOPATH}/bin:${PATH}"
154185

155-
# Install g (go version manager)
156-
curl -sSL https://git.io/g-install | bash -s -- -y
157-
158-
# Install specific version
159-
g install $(cat .go-version)
160-
161186
# Make sure gomod can be deleted automatically as part of the CI
162187
function teardown {
163188
local arg=${?}

0 commit comments

Comments
 (0)