ci(metis): retry Go module network calls in quality gate
This commit is contained in:
parent
7dc89e3bb5
commit
fd3efbc13a
@ -6,16 +6,37 @@ build_dir="${repo_root}/build"
|
|||||||
gopath_bin="$(go env GOPATH)/bin"
|
gopath_bin="$(go env GOPATH)/bin"
|
||||||
junit_report="${gopath_bin}/go-junit-report"
|
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}"
|
mkdir -p "${build_dir}"
|
||||||
|
|
||||||
if [ ! -x "${junit_report}" ]; then
|
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
|
fi
|
||||||
|
|
||||||
cd "${repo_root}"
|
cd "${repo_root}"
|
||||||
|
export GOPROXY="${GOPROXY:-https://proxy.golang.org,direct}"
|
||||||
|
run_with_retry 4 go mod download
|
||||||
|
|
||||||
set +e
|
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=$?
|
test_rc=$?
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user