forked from docker-library/golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versions.sh
executable file
·165 lines (152 loc) · 3.95 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
#!/usr/bin/env bash
set -Eeuo pipefail
# see https://golang.org/dl/
potentiallySupportedArches=(
amd64
arm32v5
arm32v6
arm32v7
arm64v8
i386
mips64le
ppc64le
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://github.com/golang/go/issues/23746
# https://github.com/golang/website/blob/dd8acb4c96edcd69706f19304941679dcb3822b0/internal/dl/server.go#L102-L107 ...
goVersions="$(
wget -qO- 'https://golang.org/dl/?mode=json&include=all' | jq -c --argjson potentiallySupportedArches "$potentiallySupportedArches" '
[
.[]
| ( .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("^armv(?<v>[0-9]+)l?$"; "arm32v\(.v)")
)
end
) as $bashbrewArch
| {
( $bashbrewArch ): (
{
sha256: .sha256,
url: ("https://dl.google.com/go/" + .filename),
supported: ($potentiallySupportedArches | index($bashbrewArch) != null),
} + if $bashbrewArch == "src" then {} else {
env: (
{ GOOS: .os, GOARCH: .arch }
+ if .arch == "386" and .os == "linux" then
# i386 in Debian is non-SSE2, Alpine appears to be similar (but interesting, not FreeBSD?)
{ GO386: (if $major == "1.15" then "387" else "softfloat" end) }
elif $bashbrewArch | startswith("arm32v") then
{ GOARCH: "arm", GOARM: ($bashbrewArch | ltrimstr("arm32v")) }
else {} end
),
} end
),
}
] | add)
}
# the published binaries only support glibc, which translates to Debian, so the "correct" binary for v7 is v6 (TODO find some way to reasonably benchmark the compiler on a proper v7 chip and determine whether recompiling for GOARM=7 is worthwhile)
| if (.arches | has("arm32v7") | not) and (.arches | has("arm32v6")) then
.arches["arm32v7"] = (.arches["arm32v6"] | .env.GOARM = "7")
else . end
| ( $potentiallySupportedArches - (.arches | keys) ) as $missingArches
| .arches = ([
.arches, (
$missingArches[]
| {
(.): {
supported: true,
env: (
{
GOOS: "linux",
GOARCH: .,
}
+ if startswith("arm32v") then
{ GOARCH: "arm", GOARM: ltrimstr("arm32v") }
else {} end
)
},
}
)
] | add)
]
'
)"
for version in "${versions[@]}"; do
export version
if \
! goJson="$(jq <<<"$goVersions" -c '
[ .[] | 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 '{
version: .version,
arches: .arches,
variants: [
"bullseye",
"buster",
"stretch",
(
"3.14",
"3.13"
| "alpine" + .),
if .arches | has("windows-amd64") then
(
"ltsc2022",
"1809",
"ltsc2016"
| "windows/windowsservercore-" + .),
(
"ltsc2022",
"1809"
| "windows/nanoserver-" + .)
else empty end
],
}')"
json="$(jq <<<"$json" -c --argjson doc "$doc" '.[env.version] = $doc')"
done
jq <<<"$json" -S . > versions.json