2019-04-18 15:18:20 -04:00
|
|
|
function retry() {
|
2020-05-25 11:07:58 -04:00
|
|
|
if eval "$@"; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in 2 1; do
|
|
|
|
sleep 3s
|
|
|
|
echo "Retrying $i..."
|
2017-03-22 10:31:07 -04:00
|
|
|
if eval "$@"; then
|
2020-05-25 11:07:58 -04:00
|
|
|
return 0
|
2017-03-22 10:31:07 -04:00
|
|
|
fi
|
2020-05-25 11:07:58 -04:00
|
|
|
done
|
|
|
|
return 1
|
2017-03-22 10:31:07 -04:00
|
|
|
}
|
2018-05-11 11:06:08 -04:00
|
|
|
|
2019-04-18 15:18:20 -04:00
|
|
|
function setup_db_user_only() {
|
2020-05-25 11:07:58 -04:00
|
|
|
source scripts/create_postgres_user.sh
|
2018-05-14 13:49:46 -04:00
|
|
|
}
|
|
|
|
|
2019-04-18 15:18:20 -04:00
|
|
|
function setup_db() {
|
2020-05-25 11:07:58 -04:00
|
|
|
run_timed_command "setup_db_user_only"
|
|
|
|
run_timed_command "bundle exec rake db:drop db:create db:structure:load db:migrate gitlab:db:setup_ee"
|
2019-07-22 11:11:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_api_client_dependencies_with_apk() {
|
|
|
|
apk add --update openssl curl jq
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_gitlab_gem() {
|
2020-10-26 14:08:27 -04:00
|
|
|
gem install httparty --no-document --version 0.18.1
|
2021-03-17 08:09:19 -04:00
|
|
|
gem install gitlab --no-document --version 4.17.0
|
2019-07-22 11:11:50 -04:00
|
|
|
}
|
|
|
|
|
2020-08-25 11:10:17 -04:00
|
|
|
function install_tff_gem() {
|
2020-12-09 10:10:12 -05:00
|
|
|
gem install test_file_finder --version 0.1.1
|
2020-08-25 11:10:17 -04:00
|
|
|
}
|
|
|
|
|
2020-05-14 11:08:14 -04:00
|
|
|
function run_timed_command() {
|
|
|
|
local cmd="${1}"
|
|
|
|
local start=$(date +%s)
|
|
|
|
echosuccess "\$ ${cmd}"
|
|
|
|
eval "${cmd}"
|
|
|
|
local ret=$?
|
|
|
|
local end=$(date +%s)
|
|
|
|
local runtime=$((end-start))
|
|
|
|
|
|
|
|
if [[ $ret -eq 0 ]]; then
|
|
|
|
echosuccess "==> '${cmd}' succeeded in ${runtime} seconds."
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
echoerr "==> '${cmd}' failed (${ret}) in ${runtime} seconds."
|
|
|
|
return $ret
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-07-22 11:11:50 -04:00
|
|
|
function echoerr() {
|
|
|
|
local header="${2}"
|
|
|
|
|
|
|
|
if [ -n "${header}" ]; then
|
|
|
|
printf "\n\033[0;31m** %s **\n\033[0m" "${1}" >&2;
|
|
|
|
else
|
|
|
|
printf "\033[0;31m%s\n\033[0m" "${1}" >&2;
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function echoinfo() {
|
|
|
|
local header="${2}"
|
|
|
|
|
|
|
|
if [ -n "${header}" ]; then
|
|
|
|
printf "\n\033[0;33m** %s **\n\033[0m" "${1}" >&2;
|
|
|
|
else
|
|
|
|
printf "\033[0;33m%s\n\033[0m" "${1}" >&2;
|
|
|
|
fi
|
|
|
|
}
|
2020-03-19 20:09:29 -04:00
|
|
|
|
2020-05-14 11:08:14 -04:00
|
|
|
function echosuccess() {
|
|
|
|
local header="${2}"
|
|
|
|
|
|
|
|
if [ -n "${header}" ]; then
|
|
|
|
printf "\n\033[0;32m** %s **\n\033[0m" "${1}" >&2;
|
|
|
|
else
|
|
|
|
printf "\033[0;32m%s\n\033[0m" "${1}" >&2;
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-09-14 11:09:28 -04:00
|
|
|
function fail_pipeline_early() {
|
|
|
|
local dont_interrupt_me_job_id
|
2021-01-12 01:10:31 -05:00
|
|
|
dont_interrupt_me_job_id=$(scripts/api/get_job_id.rb --job-query "scope=success" --job-name "dont-interrupt-me")
|
2020-09-14 11:09:28 -04:00
|
|
|
|
2020-09-16 05:09:43 -04:00
|
|
|
if [[ -n "${dont_interrupt_me_job_id}" ]]; then
|
2020-09-14 11:09:28 -04:00
|
|
|
echoinfo "This pipeline cannot be interrupted due to \`dont-interrupt-me\` job ${dont_interrupt_me_job_id}"
|
|
|
|
else
|
|
|
|
echoinfo "Failing pipeline early for fast feedback due to test failures in rspec fail-fast."
|
2021-01-12 01:10:31 -05:00
|
|
|
scripts/api/cancel_pipeline.rb
|
2020-09-14 11:09:28 -04:00
|
|
|
fi
|
|
|
|
}
|