kibana/.buildkite/scripts/common/util.sh
Tyler Smalley ab16b485cd
[ci] Disable Bazel cache on CI (#115428)
This is a short-term solution to reduce our hit count in Buildkite due to the increase in bootstraps so we can move forward with enabling Buildkite across all PRs.
2021-10-19 22:12:31 +01:00

89 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
checks-reporter-with-killswitch() {
if [ "$CHECKS_REPORTER_ACTIVE" == "true" ] ; then
yarn run github-checks-reporter "$@"
else
arguments=("$@");
"${arguments[@]:1}";
fi
}
is_pr() {
[[ "${GITHUB_PR_NUMBER-}" ]] && return
false
}
verify_no_git_changes() {
RED='\033[0;31m'
C_RESET='\033[0m' # Reset color
GIT_CHANGES="$(git ls-files --modified -- . ':!:.bazelrc')"
if [ "$GIT_CHANGES" ]; then
echo -e "\n${RED}ERROR: '$1' caused changes to the following files:${C_RESET}\n"
echo -e "$GIT_CHANGES\n"
exit 1
fi
}
# docker_run can be used in place of `docker run`
# it automatically passes along all of Buildkite's tracked environment variables, and mounts the buildkite-agent in the running container
docker_run() {
args=()
if [[ -n "${BUILDKITE_ENV_FILE:-}" ]] ; then
# Read in the env file and convert to --env params for docker
# This is because --env-file doesn't support newlines or quotes per https://docs.docker.com/compose/env-file/#syntax-rules
while read -r var; do
args+=( --env "${var%%=*}" )
done < "$BUILDKITE_ENV_FILE"
fi
BUILDKITE_AGENT_BINARY_PATH=$(command -v buildkite-agent)
args+=(
"--env" "BUILDKITE_JOB_ID"
"--env" "BUILDKITE_BUILD_ID"
"--env" "BUILDKITE_AGENT_ACCESS_TOKEN"
"--volume" "$BUILDKITE_AGENT_BINARY_PATH:/usr/bin/buildkite-agent"
)
docker run "${args[@]}" "$@"
}
is_test_execution_step() {
buildkite-agent meta-data set "${BUILDKITE_JOB_ID}_is_test_execution_step" 'true'
}
retry() {
local retries=$1; shift
local delay=$1; shift
local attempts=1
until "$@"; do
retry_exit_status=$?
echo "Exited with $retry_exit_status" >&2
if (( retries == "0" )); then
return $retry_exit_status
elif (( attempts == retries )); then
echo "Failed $attempts retries" >&2
return $retry_exit_status
else
echo "Retrying $((retries - attempts)) more times..." >&2
attempts=$((attempts + 1))
sleep "$delay"
fi
done
}
set_git_merge_base() {
GITHUB_PR_MERGE_BASE="$(buildkite-agent meta-data get merge-base --default '')"
if [[ ! "$GITHUB_PR_MERGE_BASE" ]]; then
git fetch origin "$GITHUB_PR_TARGET_BRANCH"
GITHUB_PR_MERGE_BASE="$(git merge-base HEAD FETCH_HEAD)"
buildkite-agent meta-data set merge-base "$GITHUB_PR_MERGE_BASE"
fi
export GITHUB_PR_MERGE_BASE
}