diff --git a/scripts/quality_gate.sh b/scripts/quality_gate.sh index 4bb8dfe..6fcec2e 100755 --- a/scripts/quality_gate.sh +++ b/scripts/quality_gate.sh @@ -6,16 +6,37 @@ build_dir="${repo_root}/build" gopath_bin="$(go env GOPATH)/bin" junit_report="${gopath_bin}/go-junit-report" +run_with_retry() { + local attempts="$1" + shift + local try=1 + local delay=3 + local rc=0 + while true; do + "$@" && return 0 + rc=$? + if [[ "${try}" -ge "${attempts}" ]]; then + return "${rc}" + fi + echo "[quality] retry ${try}/${attempts} after rc=${rc}: $*" >&2 + sleep "${delay}" + delay=$((delay * 2)) + try=$((try + 1)) + done +} + mkdir -p "${build_dir}" if [ ! -x "${junit_report}" ]; then - go install github.com/jstemmer/go-junit-report/v2@latest + run_with_retry 3 go install github.com/jstemmer/go-junit-report/v2@latest fi cd "${repo_root}" +export GOPROXY="${GOPROXY:-https://proxy.golang.org,direct}" +run_with_retry 4 go mod download set +e -go test -v -count=1 -coverprofile="${build_dir}/coverage.out" ./... > "${build_dir}/test.out" 2>&1 +run_with_retry 3 go test -v -count=1 -coverprofile="${build_dir}/coverage.out" ./... > "${build_dir}/test.out" 2>&1 test_rc=$? set -e