generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathmirror_vale.sh
executable file
·56 lines (47 loc) · 1.57 KB
/
mirror_vale.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
RELEASES=$(mktemp)
RAW=$(mktemp)
REPOSITORY=${1:-"errata-ai/vale"}
JQ_FILTER=\
'map(
{
"key": .tag_name,
"value": .assets
| map(select((.name | contains("vale_")) and (.name | endswith("checksums.txt") | not) ))
| map({
"key": .name | capture("vale_[0-9\\.]+_(?<platform>.*)\\.(tar\\.gz|zip)") | .platform,
"value": .name,
})
| from_entries
}
) | from_entries'
SHA256_FILTER=\
'
map(
select(.name == $tag)
| .assets
| map(.browser_download_url)[]
| select(endswith("checksums.txt"))
)[]
'
curl > $RELEASES \
--silent \
--header "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${REPOSITORY}/releases?per_page=1
jq "$JQ_FILTER" <$RELEASES >$RAW
# Combine the new versions with the existing ones.
# New versions should appear first, but existing content should overwrite new
CURRENT=$(mktemp)
python3 -c "import json; exec(open('$SCRIPT_DIR/vale_versions.bzl').read()); print(json.dumps(VALE_VERSIONS))" > $CURRENT
OUT=$(mktemp)
jq --slurp '.[0] * .[1]' $RAW $CURRENT > $OUT
# Overwrite the file with updated content
(
echo '"This file is automatically updated by mirror_vale.sh"'
echo -n "VALE_VERSIONS = "
cat $OUT
)>$SCRIPT_DIR/vale_versions.bzl
echo "For now, you must manually replace placeholder sha256 with their content from checksums.txt:"
echo "https://github.com/errata-ai/vale/releases/download/v3.7.0/vale_3.7.0_checksums.txt"