Skip to content

Commit

Permalink
ci(microbenchmark): use gvm instead of g with retries (#14856)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Dec 9, 2024
1 parent 5dfb894 commit 7ac2ea6
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions .ci/scripts/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,28 @@ function buildkite::download_last_artifact {
BUILDKITE_DOWNLOAD_URL="${download_url}" buildkite::req_download_artifact
}

#######################################
# Retry n number of times the given command
function retry() {
local retries=$1
shift

local count=0
until "$@"; do
exit=$?
wait=$((2 ** count))
count=$((count + 1))
if [ $count -lt "$retries" ]; then
>&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
sleep $wait
else
>&2 echo "Retry $count/$retries exited $exit, no more retries left."
return $exit
fi
done
return 0
}

## Buildkite specific configuration
if [ "${CI}" == "true" ] ; then
# If HOME is not set then use the Buildkite workspace
Expand All @@ -147,17 +169,20 @@ if [ "${CI}" == "true" ] ; then
[ -z "${REPO}" ] && echo "Environment variable 'REPO' must be defined" && exit 1;
export BUILDKITE_TOKEN="${BUILDKITE_TOKEN_SECRET}"

echo "--- Setting up the :golang: environment..."
GO_VERSION=$(cat .go-version)
OS_NAME=linux
OS_ARCH=amd64
retry 5 curl -sL -o "${BASE_PROJECT}"/gvm "https://github.com/andrewkroh/gvm/releases/download/v0.5.2/gvm-${OS_NAME}-${OS_ARCH}"
chmod +x "${BASE_PROJECT}"/gvm
retry 5 "${BASE_PROJECT}"/gvm install "$GO_VERSION"
eval "$("${BASE_PROJECT}"/gvm use "$GO_VERSION")"
echo "Golang version:"
go version
GOPATH=$(command go env GOPATH)
# Redirect go env to current dir
export GOROOT="${BASE_PROJECT}/.go"
export GOPATH="${BASE_PROJECT}/go"
export PATH="${GOPATH}/bin:${PATH}"

# Install g (go version manager)
curl -sSL https://git.io/g-install | bash -s -- -y

# Install specific version
g install $(cat .go-version)

# Make sure gomod can be deleted automatically as part of the CI
function teardown {
local arg=${?}
Expand Down

0 comments on commit 7ac2ea6

Please sign in to comment.