2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-11-26 13:30:30 +00:00
bazel-lib/tools/yq_mirror_release.sh

35 lines
1.4 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
2022-04-20 04:45:06 +00:00
# Produce a dictionary for the current yq release,
# suitable for adding to lib/private/yq_toolchain.bzl
set -o errexit -o nounset -o pipefail
2022-04-20 04:45:06 +00:00
# Find the latest version
if [ "${1:-}" ]; then
version=$1
else
version=$(curl --silent "https://api.github.com/repos/mikefarah/yq/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
fi
2022-04-20 04:45:06 +00:00
# yq publishes its checksums and a script to extract them
curl --silent --location "https://github.com/mikefarah/yq/releases/download/v$version/extract-checksum.sh" -o /tmp/extract-checksum.sh
curl --silent --location "https://github.com/mikefarah/yq/releases/download/v$version/checksums_hashes_order" -o /tmp/checksums_hashes_order
curl --silent --location "https://github.com/mikefarah/yq/releases/download/v$version/checksums" -o /tmp/checksums
2022-04-20 04:45:06 +00:00
cd /tmp
chmod u+x extract-checksum.sh
# Extract the checksums and output a starlark map entry
echo "\"$version\": {"
platforms=(darwin_{amd64,arm64} linux_{amd64,arm64,s390x,ppc64le} windows_amd64)
for release in ${platforms[@]}; do
2022-04-20 04:45:06 +00:00
artifact=$release
if [[ $release == windows* ]]; then
artifact="$release.exe"
fi
echo " \"$release\": \"$(./extract-checksum.sh SHA-384 $artifact | awk '{ print $2 }' | xxd -r -p | base64 | awk '{ print "sha384-" $1 }' )\","
done
echo "},"
printf "\n"
echo "Paste the above into VERSIONS in yq_toolchain.bzl."