Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/alpine.func
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,28 @@ setup_go() {
return 1
;;
esac

# A bare major.minor version (e.g. "1.22", as commonly found in go.mod's `go`
# directive) has no matching tarball -- go.dev only publishes patch releases
# (go1.22.12, not go1.22) -- so resolve it to the latest matching patch first.
if [[ "$GO_VERSION" =~ ^([0-9]+)\.([0-9]+)$ ]]; then
local go_major="${BASH_REMATCH[1]}" go_minor="${BASH_REMATCH[2]}"
need_tool jq || return 1
local go_releases go_patch
go_releases=$(curl -fsSL "https://go.dev/dl/?mode=json&include=all" 2>/dev/null) || true
go_patch=$(printf '%s' "$go_releases" | jq -r --arg maj "$go_major" --arg min "$go_minor" '
[.[] | select(.stable == true) | .version
| capture("^go(?<maj>[0-9]+)\\.(?<min>[0-9]+)\\.(?<patch>[0-9]+)$")
| select(.maj == $maj and .min == $min)
| (.patch | tonumber)]
| max // empty' 2>/dev/null)
if [[ -z "$go_patch" ]]; then
msg_error "Could not resolve latest patch release for Go ${GO_VERSION}.x"
return 1
fi
GO_VERSION="${go_major}.${go_minor}.${go_patch}"
fi

TARBALL="go${GO_VERSION}.linux-${ARCH}.tar.gz"
URL="https://go.dev/dl/${TARBALL}"
msg_info "Setup Go $GO_VERSION (tarball)"
Expand Down
21 changes: 21 additions & 0 deletions lib/runtime.func
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,27 @@ setup_go() {
GO_VERSION="$go_version_tmp"
fi

# A bare major.minor version (e.g. "1.22", as commonly found in go.mod's `go`
# directive) has no matching tarball -- go.dev only publishes patch releases
# (go1.22.12, not go1.22) -- so resolve it to the latest matching patch first.
if [[ "$GO_VERSION" =~ ^([0-9]+)\.([0-9]+)$ ]]; then
local go_major="${BASH_REMATCH[1]}" go_minor="${BASH_REMATCH[2]}"
ensure_dependencies jq || return 100
local go_releases go_patch
go_releases=$(curl_with_retry "https://go.dev/dl/?mode=json&include=all" "-" 2>/dev/null) || true
go_patch=$(printf '%s' "$go_releases" | jq -r --arg maj "$go_major" --arg min "$go_minor" '
[.[] | select(.stable == true) | .version
| capture("^go(?<maj>[0-9]+)\\.(?<min>[0-9]+)\\.(?<patch>[0-9]+)$")
| select(.maj == $maj and .min == $min)
| (.patch | tonumber)]
| max // empty' 2>/dev/null)
if [[ -z "$go_patch" ]]; then
msg_error "Could not resolve latest patch release for Go ${GO_VERSION}.x"
return 250
fi
GO_VERSION="${go_major}.${go_minor}.${go_patch}"
fi

local GO_BIN="/usr/local/bin/go"
local GO_INSTALL_DIR="/usr/local/go"

Expand Down
Loading