-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
versions.sh
executable file
·229 lines (204 loc) · 6.35 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env bash
set -Eeuo pipefail
shopt -s nullglob
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
declare -A checksums=()
check_file() {
local dirVersion="$1"; shift
local fullVersion="$1"; shift
local type="${1:-source}" # "source" or "windows"
local filename="Python-$fullVersion.tar.xz"
if [ "$type" = 'windows' ]; then
filename="python-$fullVersion-amd64.exe"
fi
local url="https://www.python.org/ftp/python/$dirVersion/$filename"
local sigstore
if sigstore="$(
wget -qO- -o/dev/null "$url.sigstore" \
| jq -r '
.messageSignature.messageDigest
| if .algorithm != "SHA2_256" then
error("sigstore bundle not using SHA2_256")
else .digest end
'
)" && [ -n "$sigstore" ]; then
sigstore="$(base64 -d <<<"$sigstore" | hexdump -ve '/1 "%02x"')"
checksums["$fullVersion"]="$(jq <<<"${checksums["$fullVersion"]:-null}" --arg type "$type" --arg sha256 "$sigstore" '.[$type].sha256 = $sha256')"
return 0
fi
# TODO is this even necessary/useful? the sigstore-based version above is *much* faster, supports all current versions (not just 3.12+ like this), *and* should be more reliable 🤔
local sbom
if sbom="$(
wget -qO- -o/dev/null "$url.spdx.json" \
| jq --arg filename "$filename" '
first(
.packages[]
| select(
.name == "CPython"
and .packageFileName == $filename
)
)
| .checksums
| map({
key: (.algorithm // empty | ascii_downcase),
value: (.checksumValue // empty),
})
| if length < 1 then
error("no checksums found for \($filename)")
else . end
| from_entries
| if has("sha256") then . else
error("missing sha256 for \($filename); have \(.)")
end
'
)" && [ -n "sbom" ]; then
checksums["$fullVersion"]="$(jq <<<"${checksums["$fullVersion"]:-null}" --arg type "$type" --argjson sums "$sbom" '.[$type] += $sums')"
return 0
fi
if ! wget -q -O /dev/null -o /dev/null --spider "$url"; then
return 1
fi
return 0
}
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
export version rcVersion
rcGrepV='-v'
if [ "$rcVersion" != "$version" ]; then
rcGrepV=
fi
possibles=( $(
{
git ls-remote --tags https://github.com/python/cpython.git "refs/tags/v${rcVersion}.*" \
| sed -r 's!^.*refs/tags/v([0-9a-z.]+).*$!\1!' \
| grep $rcGrepV -E -- '[a-zA-Z]+' \
|| :
# this page has a very aggressive varnish cache in front of it, which is why we also scrape tags from GitHub
wget -qO- 'https://www.python.org/ftp/python/' \
| grep '<a href="'"$rcVersion." \
| sed -r 's!.*<a href="([^"/]+)/?".*!\1!' \
| grep $rcGrepV -E -- '[a-zA-Z]+' \
|| :
} | sort -ruV
) )
fullVersion=
hasWindows=
declare -A impossible=()
for possible in "${possibles[@]}"; do
rcPossible="${possible%%[a-z]*}"
# varnish is great until it isn't (usually the directory listing we scrape below is updated/uncached significantly later than the release being available)
if check_file "$rcPossible" "$possible"; then
fullVersion="$possible"
if check_file "$rcPossible" "$possible" windows; then
hasWindows=1
fi
break
fi
if [ -n "${impossible[$rcPossible]:-}" ]; then
continue
fi
impossible[$rcPossible]=1
possibleVersions=( $(
wget -qO- -o /dev/null "https://www.python.org/ftp/python/$rcPossible/" \
| grep '<a href="Python-'"$rcVersion"'.*\.tar\.xz"' \
| sed -r 's!.*<a href="Python-([^"/]+)\.tar\.xz".*!\1!' \
| grep $rcGrepV -E -- '[a-zA-Z]+' \
| sort -rV \
|| true
) )
for possibleVersion in "${possibleVersions[@]}"; do
if check_file "$rcPossible" "$possibleVersion"; then
fullVersion="$possibleVersion"
if check_file "$rcPossible" "$possible" windows; then
hasWindows=1
fi
break
fi
done
done
if [ -z "$fullVersion" ]; then
{
echo
echo
echo " error: cannot find $version (alpha/beta/rc?)"
echo
echo
} >&2
exit 1
fi
ensurepipVersions="$(
wget -qO- "https://github.com/python/cpython/raw/v$fullVersion/Lib/ensurepip/__init__.py" \
| grep -E '^[^[:space:]]+_VERSION[[:space:]]*='
)"
# Note: We don't extract the pip version here, since our policy is now to use the pip version
# that is installed during the Python build (which is the version bundled in ensurepip), and
# to not support overriding it.
# TODO remove setuptools version handling entirely once Python 3.11 is EOL
setuptoolsVersion="$(sed -nre 's/^_SETUPTOOLS_VERSION[[:space:]]*=[[:space:]]*"(.*?)".*/\1/p' <<<"$ensurepipVersions")"
case "$rcVersion" in
3.9 | 3.10 | 3.11)
if [ -z "$setuptoolsVersion" ]; then
echo >&2 "error: $version: missing setuptools version"
exit 1
fi
if ! wget -q -O /dev/null -o /dev/null --spider "https://pypi.org/pypi/setuptools/$setuptoolsVersion/json"; then
echo >&2 "error: $version: setuptools version ($setuptoolsVersion) seems to be invalid?"
exit 1
fi
# https://github.com/docker-library/python/issues/781 (TODO remove this if 3.10 and 3.11 embed a newer setuptools and this section no longer applies)
if [ "$setuptoolsVersion" = '65.5.0' ]; then
setuptoolsVersion='65.5.1'
fi
;;
*)
# https://github.com/python/cpython/issues/95299 -> https://github.com/python/cpython/commit/ece20dba120a1a4745721c49f8d7389d4b1ee2a7
if [ -n "$setuptoolsVersion" ]; then
echo >&2 "error: $version: unexpected setuptools: $setuptoolsVersion"
exit 1
fi
;;
esac
echo "$version: $fullVersion"
export fullVersion pipVersion setuptoolsVersion hasWindows
doc="$(jq -nc '
{
version: env.fullVersion,
variants: [
(
"bookworm",
"bullseye",
empty
| ., "slim-" + .), # https://github.com/docker-library/ruby/pull/142#issuecomment-320012893
(
"3.20",
"3.19",
empty
| "alpine" + .),
if env.hasWindows != "" then
(
"ltsc2022",
"1809",
empty
| "windows/windowsservercore-" + .)
else empty end
],
} + if env.setuptoolsVersion != "" then {
setuptools: {
version: env.setuptoolsVersion,
},
} else {} end
')"
if [ -n "${checksums["$fullVersion"]:-}" ]; then
doc="$(jq <<<"$doc" -c --argjson checksums "${checksums["$fullVersion"]}" '.checksums = $checksums')"
fi
json="$(jq <<<"$json" -c --argjson doc "$doc" '.[env.version] = $doc')"
done
jq <<<"$json" -S . > versions.json