-
Notifications
You must be signed in to change notification settings - Fork 512
/
versions.sh
executable file
·195 lines (183 loc) · 5.03 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash
set -Eeuo pipefail
# see https://golang.org/dl/
potentiallySupportedArches=(
amd64
arm32v5
arm32v6
arm32v7
arm64v8
i386
mips64le
ppc64le
riscv64
s390x
windows-amd64
# special case (fallback)
src
)
potentiallySupportedArches="$(jq -sRc <<<"${potentiallySupportedArches[*]}" 'rtrimstr("\n") | split(" ")')"
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
# https://pkg.go.dev/golang.org/x/website/internal/dl
# https://github.com/golang/go/issues/23746
# https://github.com/golang/go/issues/34864
# https://github.com/golang/website/blob/41e922072f17ab2826d9479338314c025602a3a1/internal/dl/server.go#L174-L182 ... (the only way to get "unstable" releases is via "all", so we get to sort through "archive" releases too)
goVersions="$(
wget -qO- 'https://golang.org/dl/?mode=json&include=all' | jq -c '
[
.[]
| ( .version | ltrimstr("go") ) as $version
| ( $version | sub("^(?<m>[0-9]+[.][0-9]+).*$"; "\(.m)") ) as $major
| {
version: $version,
major: ( $major + if .stable then "" else "-rc" end ),
arches: (
[
.files[]
| select(.kind == "archive" or .kind == "source")
| (
if .kind == "source" then
"src"
else
if .os != "linux" then
.os + "-"
else "" end
+ (
.arch
| sub("^386$"; "i386")
| sub("^arm64$"; "arm64v8")
| sub("^arm-?v?(?<v>[0-9]+)l?$"; "arm32v\(.v)")
)
end
) as $bashbrewArch
| {
( $bashbrewArch ): (
{
url: ("https://dl.google.com/go/" + .filename),
sha256: .sha256,
env: { GOOS: .os, GOARCH: .arch },
}
),
}
]
| add
# upstream (still as of 2023-12-19) only publishes "armv6" binaries, which are appropriate for v7 as well
| if (has("arm32v7") | not) and has("arm32v6") then
.["arm32v7"] = .["arm32v6"]
else . end
)
}
]
'
)"
for version in "${versions[@]}"; do
export version
if \
! goJson="$(jq <<<"$goVersions" -ce '
[ .[] | select(.major == env.version) ] | sort_by(
.version
| split(".")
| map(
if test("^[0-9]+$") then
tonumber
else . end
)
)[-1]
')" \
|| ! fullVersion="$(jq <<<"$goJson" -r '.version')" \
|| [ -z "$fullVersion" ] \
; then
echo >&2 "warning: cannot find full version for $version"
continue
fi
echo "$version: $fullVersion"
doc="$(jq <<<"$goJson" -c --argjson potentiallySupportedArches "$potentiallySupportedArches" '{
version: .version,
arches: (
.arches
| . += (
( $potentiallySupportedArches - keys ) # "missing" arches that we ought to include in our list
| map(
{
(.): {
env: (
# hacky, but probably close enough (cleaned up in the next block)
capture("^((?<GOOS>[^-]+)-)?(?<GOARCH>.+)$")
| .GOOS //= "linux"
)
},
}
)
| add
)
| with_entries(
.key as $bashbrewArch
| .value.supported = (
# https://github.com/docker-library/golang/pull/500#issuecomment-1863578601 - as of Go 1.21+, we no longer build from source
.value.url
and ($potentiallySupportedArches | index($bashbrewArch))
)
| .value.env +=
if $bashbrewArch == "i386" then
# i386 in Debian is non-SSE2, Alpine appears to be similar (but interesting, not FreeBSD?)
{ GOARCH: "386", GO386: "softfloat" }
elif $bashbrewArch == "amd64" then
# https://go.dev/doc/go1.18#amd64
{ GOAMD64: "v1" }
# TODO ^^ figure out what to do with GOAMD64 / GO386 if/when the OS baselines change and these choices needs to be per-variant /o\ (probably move it to the template instead, in fact, since that is where we can most easily toggle based on variant)
elif $bashbrewArch == "riscv64" and env.version != "1.22" then
# https://go.dev/doc/go1.23#riscv
{ GORISCV64: "rva20u64" }
elif $bashbrewArch | startswith("arm64v") then
{ GOARCH: "arm64" }
+ if env.version != "1.22" then {
# https://go.dev/doc/go1.23#arm64
GOARM64: ($bashbrewArch | ltrimstr("arm64") | if index(".") then . else . + ".0" end),
} else {} end
elif $bashbrewArch | startswith("arm32v") then
{ GOARCH: "arm", GOARM: ($bashbrewArch | ltrimstr("arm32v")) }
else {} end
| if $bashbrewArch == "src" then del(.value.env) else . end
)
),
variants: [
"bookworm",
"bullseye",
(
"3.20",
"3.19",
empty
| "alpine" + .),
if .arches | has("windows-amd64") and .["windows-amd64"].url then
(
"ltsc2022",
"1809",
empty
| "windows/windowsservercore-" + .),
(
"ltsc2022",
"1809",
empty
| "windows/nanoserver-" + .)
else empty end
],
}')"
json="$(jq <<<"$json" -c --argjson doc "$doc" '.[env.version] = $doc')"
done
jq <<<"$json" '
def sort_keys:
to_entries
| sort_by(.key)
| from_entries
;
sort_keys
| .[].arches |= sort_keys
' > versions.json