blob: 5ecfa4dd356bfd0409e131d0209640d00ad00f7d [file] [edit]
#!/usr/bin/env bash
# Copyright 2026 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Download a public release asset to a caller-owned temporary file.
set -euo pipefail
set +x
url="https://api.github.com/repos/$1/releases/assets/$2"
sha256="$3"
output="$4"
authorization=""
if [[ -n "${GH_TOKEN:-}" ]]; then
authorization="Authorization: Bearer ${GH_TOKEN}"
fi
for attempt in 1 2 3; do
echo "Downloading $1 release asset $2 (attempt ${attempt}/3)" >&2
# A cached redirect may point at an expired signed asset URL.
if curl --proto '=https' --proto-redir '=https' --fail --silent --show-error \
--header 'Accept: application/octet-stream' --header @- \
--location --connect-timeout 15 --max-time 600 \
"${url}?request=$(date +%s)-${attempt}" --output "${output}" <<< "${authorization}"; then
echo "${sha256} *${output}" | sha256sum --check
exit 0
fi
if [[ "${attempt}" != 3 ]]; then
sleep "$((5 * attempt))"
fi
done
exit 1