Make alias-choosing code generic so GA can be fully automated

This means that when 4.2 is GA, our update automation should pick it up automatically, and update `latest` and `4` to point to it.
This commit is contained in:
Tianon Gravi 2025-08-08 13:48:32 -07:00
parent 34c247bc2a
commit 423cdaa94f
3 changed files with 26 additions and 12 deletions

View File

@ -1,10 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -Eeuo pipefail set -Eeuo pipefail
declare -A aliases=(
[4.1]='4 latest'
[3.13]='3'
)
defaultVariant='ubuntu' defaultVariant='ubuntu'
self="$(basename "$BASH_SOURCE")" self="$(basename "$BASH_SOURCE")"
@ -14,7 +10,7 @@ if [ "$#" -eq 0 ]; then
versions="$(jq -r ' versions="$(jq -r '
to_entries to_entries
# sort version numbers with highest first # sort version numbers with highest first
| sort_by(.key | split("[.-]"; "") | map(try tonumber // .)) | sort_by(.key | split("[.-]"; "") | map(tonumber? // .))
| reverse | reverse
| map(if .value then .key | @sh else empty end) | map(if .value then .key | @sh else empty end)
| join(" ") | join(" ")
@ -81,6 +77,8 @@ join() {
echo "${out#$sep}" echo "${out#$sep}"
} }
declare -A usedAliases=()
for version; do for version; do
export version export version
rcVersion="${version%-rc}" rcVersion="${version%-rc}"
@ -103,16 +101,22 @@ for version; do
versionAliases=() versionAliases=()
if [ "$version" = "$rcVersion" ]; then if [ "$version" = "$rcVersion" ]; then
while [ "$fullVersion" != "$version" -a "${fullVersion%[.-]*}" != "$fullVersion" ]; do while [ "$fullVersion" != "$version" -a "${fullVersion%[.-]*}" != "$fullVersion" ]; do
versionAliases+=( $fullVersion ) versionAliases+=( "$fullVersion" )
fullVersion="${fullVersion%[.-]*}" fullVersion="${fullVersion%[.-]*}"
done done
else else
versionAliases+=( $fullVersion ) versionAliases+=( "$fullVersion" )
fi
versionAliases+=( $version )
if [ "$version" = "$rcVersion" ]; then
for tagAlias in "${fullVersion%%.*}" latest; do
if [ -z "${usedAliases[$tagAlias]:-}" ]; then
versionAliases+=( "$tagAlias" )
usedAliases["$tagAlias"]="$version"
fi
done
fi fi
versionAliases+=(
$version
${aliases[$version]:-}
)
for variant in ubuntu alpine; do for variant in ubuntu alpine; do
dir="$version/$variant" dir="$version/$variant"

View File

@ -53,6 +53,7 @@
"version": "4.1.3" "version": "4.1.3"
}, },
"4.1-rc": null, "4.1-rc": null,
"4.2": null,
"4.2-rc": { "4.2-rc": {
"alpine": { "alpine": {
"version": "3.22" "version": "3.22"

View File

@ -96,7 +96,6 @@ for version in "${versions[@]}"; do
if [[ "$fullVersion" == "$rcFullVersion"* ]] || [ "$latestVersion" = "$rcFullVersion" ]; then if [[ "$fullVersion" == "$rcFullVersion"* ]] || [ "$latestVersion" = "$rcFullVersion" ]; then
# "x.y.z-rc1" == x.y.z* # "x.y.z-rc1" == x.y.z*
echo >&2 "warning: skipping/removing '$version' ('$rcVersion' is at '$rcFullVersion' which is newer than '$fullVersion')" echo >&2 "warning: skipping/removing '$version' ('$rcVersion' is at '$rcFullVersion' which is newer than '$fullVersion')"
json="$(jq <<<"$json" -c '.[env.version] = null')"
continue continue
fi fi
fi fi
@ -184,6 +183,16 @@ for version in "${versions[@]}"; do
} }
' '
)" )"
# make sure RCs and releases have corresponding pairs
json="$(jq <<<"$json" -c '
.[
env.rcVersion
+ if env.version == env.rcVersion then
"-rc"
else "" end
] //= null
')"
done done
jq <<<"$json" -S . > versions.json jq <<<"$json" -S . > versions.json