2019-07-31 22:56:46 +05:30
|
|
|
function retry() {
|
2020-06-23 00:09:42 +05:30
|
|
|
if eval "$@"; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in 2 1; do
|
|
|
|
sleep 3s
|
|
|
|
echo "Retrying $i..."
|
2017-08-17 22:00:37 +05:30
|
|
|
if eval "$@"; then
|
2020-06-23 00:09:42 +05:30
|
|
|
return 0
|
2017-08-17 22:00:37 +05:30
|
|
|
fi
|
2020-06-23 00:09:42 +05:30
|
|
|
done
|
|
|
|
return 1
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
function test_url() {
|
|
|
|
local url="${1}"
|
|
|
|
local curl_output="${2}"
|
|
|
|
local status
|
|
|
|
|
|
|
|
status=$(curl -s -o "${curl_output}" -L -w ''%{http_code}'' "${url}")
|
|
|
|
|
|
|
|
if [[ $status == "200" ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
function bundle_install_script() {
|
|
|
|
local extra_install_args="${1}"
|
|
|
|
|
|
|
|
if [[ "${extra_install_args}" =~ "--without" ]]; then
|
|
|
|
echoerr "The '--without' flag shouldn't be passed as it would replace the default \${BUNDLE_WITHOUT} (currently set to '${BUNDLE_WITHOUT}')."
|
|
|
|
echoerr "Set the 'BUNDLE_WITHOUT' variable instead, e.g. '- export BUNDLE_WITHOUT=\"\${BUNDLE_WITHOUT}:any:other:group:not:to:install\"'."
|
|
|
|
exit 1;
|
|
|
|
fi;
|
|
|
|
|
|
|
|
bundle --version
|
2021-11-11 11:23:49 +05:30
|
|
|
bundle config set path "$(pwd)/vendor"
|
2021-06-08 01:23:25 +05:30
|
|
|
bundle config set clean 'true'
|
2021-11-11 11:23:49 +05:30
|
|
|
test -d jh && bundle config set gemfile 'jh/Gemfile'
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
echo "${BUNDLE_WITHOUT}"
|
2021-06-08 01:23:25 +05:30
|
|
|
bundle config
|
|
|
|
|
|
|
|
run_timed_command "bundle install ${BUNDLE_INSTALL_FLAGS} ${extra_install_args} && bundle check"
|
|
|
|
|
|
|
|
if [[ $(bundle info pg) ]]; then
|
|
|
|
# When we test multiple versions of PG in the same pipeline, we have a single `setup-test-env`
|
|
|
|
# job but the `pg` gem needs to be rebuilt since it includes extensions (https://guides.rubygems.org/gems-with-extensions).
|
|
|
|
# Uncomment the following line if multiple versions of PG are tested in the same pipeline.
|
|
|
|
run_timed_command "bundle pristine pg"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
function setup_db_user_only() {
|
2020-06-23 00:09:42 +05:30
|
|
|
source scripts/create_postgres_user.sh
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
function setup_db() {
|
2020-06-23 00:09:42 +05:30
|
|
|
run_timed_command "setup_db_user_only"
|
2021-11-18 22:05:49 +05:30
|
|
|
run_timed_command_with_metric "bundle exec rake db:drop db:create db:structure:load db:migrate gitlab:db:setup_ee" "setup_db"
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
function install_api_client_dependencies_with_apk() {
|
|
|
|
apk add --update openssl curl jq
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_gitlab_gem() {
|
2021-01-29 00:20:46 +05:30
|
|
|
gem install httparty --no-document --version 0.18.1
|
2021-04-29 21:17:54 +05:30
|
|
|
gem install gitlab --no-document --version 4.17.0
|
2019-07-31 22:56:46 +05:30
|
|
|
}
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
function install_tff_gem() {
|
2021-02-22 17:27:13 +05:30
|
|
|
gem install test_file_finder --version 0.1.1
|
2020-11-24 15:15:51 +05:30
|
|
|
}
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
function run_timed_command() {
|
|
|
|
local cmd="${1}"
|
2021-11-18 22:05:49 +05:30
|
|
|
local metric_name="${2}"
|
|
|
|
local timed_metric_file
|
2020-05-24 23:13:21 +05:30
|
|
|
local start=$(date +%s)
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
echosuccess "\$ ${cmd}"
|
|
|
|
eval "${cmd}"
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
local ret=$?
|
|
|
|
local end=$(date +%s)
|
|
|
|
local runtime=$((end-start))
|
|
|
|
|
|
|
|
if [[ $ret -eq 0 ]]; then
|
|
|
|
echosuccess "==> '${cmd}' succeeded in ${runtime} seconds."
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
if [[ -n "${metric_name}" ]]; then
|
|
|
|
timed_metric_file=$(timed_metric_file $metric_name)
|
|
|
|
echo "# TYPE ${metric_name} gauge" > "${timed_metric_file}"
|
|
|
|
echo "# UNIT ${metric_name} seconds" >> "${timed_metric_file}"
|
|
|
|
echo "${metric_name} ${runtime}" >> "${timed_metric_file}"
|
|
|
|
fi
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
return 0
|
|
|
|
else
|
|
|
|
echoerr "==> '${cmd}' failed (${ret}) in ${runtime} seconds."
|
|
|
|
return $ret
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
function run_timed_command_with_metric() {
|
|
|
|
local cmd="${1}"
|
|
|
|
local metric_name="${2}"
|
|
|
|
local metrics_file=${METRICS_FILE:-metrics.txt}
|
|
|
|
|
|
|
|
run_timed_command "${cmd}" "${metric_name}"
|
|
|
|
|
|
|
|
local ret=$?
|
|
|
|
|
|
|
|
cat $(timed_metric_file $metric_name) >> "${metrics_file}"
|
|
|
|
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
|
|
|
function timed_metric_file() {
|
|
|
|
local metric_name="${1}"
|
|
|
|
|
|
|
|
echo "$(pwd)/tmp/duration_${metric_name}.txt"
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
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-04-22 19:07:51 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
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-11-24 15:15:51 +05:30
|
|
|
function fail_pipeline_early() {
|
|
|
|
local dont_interrupt_me_job_id
|
2021-03-08 18:12:59 +05:30
|
|
|
dont_interrupt_me_job_id=$(scripts/api/get_job_id.rb --job-query "scope=success" --job-name "dont-interrupt-me")
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
if [[ -n "${dont_interrupt_me_job_id}" ]]; then
|
|
|
|
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-03-08 18:12:59 +05:30
|
|
|
scripts/api/cancel_pipeline.rb
|
2020-11-24 15:15:51 +05:30
|
|
|
fi
|
|
|
|
}
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
function danger_as_local() {
|
|
|
|
# Force danger to skip CI source GitLab and fallback to "local only git repo".
|
|
|
|
unset GITLAB_CI
|
|
|
|
# We need to base SHA to help danger determine the base commit for this shallow clone.
|
2021-12-11 22:18:48 +05:30
|
|
|
bundle exec danger dry_run --fail-on-errors=true --verbose --base="${CI_MERGE_REQUEST_DIFF_BASE_SHA}" --head="${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA:-$CI_COMMIT_SHA}"
|
2021-09-30 23:02:18 +05:30
|
|
|
}
|