-
Notifications
You must be signed in to change notification settings - Fork 19
/
versions.sh
executable file
·93 lines (84 loc) · 2.05 KB
/
versions.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
set -Eeuo pipefail
alpine="$(
bashbrew cat --format '{{ .TagEntry.Tags | join "\n" }}' https://github.com/docker-library/official-images/raw/HEAD/library/alpine:latest \
| grep -E '^[0-9]+[.][0-9]+$'
)"
[ "$(wc -l <<<"$alpine")" = 1 ]
export alpine
debian="$(
bashbrew cat --format '{{ .TagEntry.Tags | join "\n" }}' https://github.com/docker-library/official-images/raw/HEAD/library/debian:latest \
| grep -vE '^latest$|[0-9.-]' \
| head -1
)"
[ "$(wc -l <<<"$debian")" = 1 ]
export debian
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
packages="$(
wget -qO- 'https://github.com/valkey-io/valkey-hashes/raw/main/README' \
| jq -csR '
rtrimstr("\n")
| split("\n")
| map(
# this capture will naturally ignore comments and blank lines
capture(
[
"^hash[[:space:]]+",
"(?<file>valkey-",
"(?<version>([0-9.]+)(-rc[0-9]+)?|unstable)",
"[.][^[:space:]]+)[[:space:]]+",
"(?<type>sha256|sha1)[[:space:]]+", # this filters us down to just the checksum types we are prepared to handle right now
"(?<sum>[0-9a-f]{64}|[0-9a-f]{40})[[:space:]]+",
"(?<url>[^[:space:]]+)",
"$"
] | join("")
)
| {
version: .version,
url: .url,
(.type): .sum,
}
)
'
)"
for version in "${versions[@]}"; do
export version rcVersion="${version%-rc}"
if [ "$version" = "unstable" ]; then
doc="$(
jq <<<"$packages" -c '
map(select(.version == "unstable"))[-1]
'
)"
else
doc="$(
jq <<<"$packages" -c '
map(
select(
.version
| (
startswith(env.rcVersion + ".")
or startswith(env.rcVersion + "-")
)
)
)[-1]
'
)"
fi
fullVersion="$(jq <<<"$doc" -r '.version')"
echo "$version: $fullVersion"
json="$(jq <<<"$json" -c --argjson doc "$doc" '
.[env.version] = ($doc + {
debian: { version: env.debian },
alpine: { version: env.alpine },
})
')"
done
jq <<<"$json" . > versions.json