2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-11-30 01:41:21 +00:00
bazel-lib/tools/yq_mirror_release.sh
Alex Eagle 1df2becc7a chore: turn on more basic precommit checks
In particular this makes our bazelrc presets more compliant with client codebases, ensuring they can copy these files and not trip on their own pre-commit check
2023-02-17 11:00:00 -08:00

36 lines
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Produce a dictionary for the current yq release,
# suitable for adding to lib/private/yq_toolchain.bzl
set -o errexit -o nounset -o pipefail
# 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
# 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
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
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."