retry download on unpack error

Sometimes, the downloaded tar file gets corrupted and fails to unpack.
Add a couple retries to avoid spurious CI failures in dependent projs.

```
[2022-12-09T23:17:22.588Z] + ./scripts/setup_scenarios.sh
[2022-12-09T23:17:22.588Z] Downloading consensus spec test vectors
[2022-12-09T23:17:22.588Z] ~/workspace/atforms_macos_aarch64_dev_etan_y/vendor/nim-eth2-scenarios ~/workspace/atforms_macos_aarch64_dev_etan_y
[2022-12-09T23:17:22.588Z] Downloading: v1.2.0/general.tar.gz
[2022-12-09T23:17:24.296Z] Downloading: v1.2.0/minimal.tar.gz
[2022-12-09T23:17:29.150Z] Downloading: v1.2.0/mainnet.tar.gz
[2022-12-09T23:17:30.331Z] Unpacking: v1.2.0/general.tar.gz
[2022-12-09T23:17:30.671Z] Unpacking: v1.2.0/minimal.tar.gz
[2022-12-09T23:17:36.665Z] Unpacking: v1.2.0/mainnet.tar.gz
[2022-12-09T23:17:36.665Z] tar: Error opening archive: Unrecognized archive format
[2022-12-09T23:17:36.665Z] Tar failed. Aborting.
script returned exit code 1
```
This commit is contained in:
Etan Kissling 2022-12-11 15:35:24 +01:00
parent 5163f18ae2
commit 9e23fbeba9
No known key found for this signature in database
GPG Key ID: B21DA824C5A3D03D
1 changed files with 23 additions and 16 deletions

View File

@ -47,24 +47,31 @@ unpack_version() {
[[ -z "$1" ]] && { echo "usage: unpack_version() vX.Y.Z"; exit 1; }
version="$1"
dl_version "$version"
local retries=0 ok=0
while (( !ok && ++retries <= 5 )); do # downloaded tar.gz may be corrupted
dl_version "$version"
# suppress warnings when unpacking with GNU tar an archive created with BSD tar (probably on macOS)
EXTRA_TAR_PARAMS=""
tar --version | grep -qi 'gnu' && EXTRA_TAR_PARAMS="--warning=no-unknown-keyword --ignore-zeros"
# suppress warnings when unpacking with GNU tar an archive created with BSD tar (probably on macOS)
EXTRA_TAR_PARAMS=""
tar --version | grep -qi 'gnu' && EXTRA_TAR_PARAMS="--warning=no-unknown-keyword --ignore-zeros"
if [[ ! -d "tests-${version}" ]]; then
for flavour in "${FLAVOURS[@]}"; do
echo "Unpacking: ${version}/${flavour}.tar.gz"
mkdir -p "tests-${version}"
tar -C "tests-${version}" --strip-components 1 ${EXTRA_TAR_PARAMS} --exclude=phase1 -xzf \
"tarballs/${version}/${flavour}.tar.gz" \
|| {
echo "Tar failed. Aborting."
rm -rf "tests-${version}"
exit 1
}
done
ok=1
if [[ ! -d "tests-${version}" ]]; then
for flavour in "${FLAVOURS[@]}"; do
echo "Unpacking: ${version}/${flavour}.tar.gz"
mkdir -p "tests-${version}"
tar -C "tests-${version}" --strip-components 1 ${EXTRA_TAR_PARAMS} --exclude=phase1 -xzf \
"tarballs/${version}/${flavour}.tar.gz" \
|| {
rm -rf "tests-${version}" "tarballs/${version}/${flavour}.tar.gz"
ok=0
}
done
fi
done
if (( !ok )); then
echo "Unpacking test vectors failed too often. Aborting."
exit 1
fi
}