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/coreutils_mirror_release.sh

58 lines
2 KiB
Bash
Raw Normal View History

2023-01-16 18:02:17 +00:00
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
2023-12-08 08:30:39 +00:00
JQ_FILTER='map({
"key": .tag_name,
"value": .assets
| map(select(
(.name | startswith("coreutils-")) and
2023-01-16 18:02:17 +00:00
((.name | endswith(".tar.gz")) or (.name | endswith(".zip"))) and
(.name | contains("i686") | not) and
(
( (.name | contains("windows")) and (.name | contains("gnu") | not) ) or
( (.name | contains("windows") | not) and (.name | contains("gnu") ) and (.name | contains("gnueabihf") | not) ) or
2023-01-16 18:02:17 +00:00
( .name | contains("darwin") )
)
))
| map({
key: .name |
ltrimstr("coreutils-") |
rtrimstr(".tar.gz") |
rtrimstr(".zip") |
sub("-pc"; "") |
2023-01-16 18:02:17 +00:00
sub("-apple"; "") |
sub("-unknown"; "") |
sub("x86_64"; "amd64") |
sub("aarch64"; "arm64") |
gsub("\\d+.\\d+.\\d+-"; "") |
rtrimstr("-msvc") |
2023-01-16 18:02:17 +00:00
rtrimstr("-gnu") |
split("-") |
reverse |
join("_"),
value: {
filename: .name,
sha256: "sha256-",
}
2023-01-16 18:02:17 +00:00
})
| from_entries
2023-01-16 18:02:17 +00:00
}) | from_entries
'
INFO="$(curl --silent -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/uutils/coreutils/releases?per_page=1 | jq "$JQ_FILTER")"
2023-12-08 08:30:39 +00:00
for VERSION in $(jq -r 'keys | join("\n")' <<<$INFO); do
for PLATFORM in $(jq -r ".[\"$VERSION\"] | keys | join(\"\n\")" <<<$INFO); do
FILENAME=$(jq -r ".[\"$VERSION\"][\"$PLATFORM\"].filename" <<<$INFO)
SHA256=$(curl -fLs "https://github.com/uutils/coreutils/releases/download/$VERSION/$FILENAME" | sha256sum | xxd -r -p | base64)
INFO=$(jq ".[\"$VERSION\"][\"$PLATFORM\"].sha256 = \"sha256-$SHA256\"" <<<$INFO)
done
2023-01-16 18:02:17 +00:00
done
echo -n "COREUTILS_VERSIONS = "
echo $INFO | jq -M
echo ""
echo "Copy the version info into lib/private/coreutils_toolchain.bzl"