scripts/release: Use go mod instead of go list

Replace `go list -m` with `go mod edit -json`, as the latter can return
the same information. This will be helpful when the project migrates to
using a Go workspace, as it will return the current module defined in
go.mod rather than all the modules from the current directory (using a
workspace, the top-level go.mod will return all the child modules from
the repository).

Signed-off-by: Ivan Valdes <ivan@vald.es>
This commit is contained in:
Ivan Valdes 2025-02-14 23:09:41 -08:00
parent 930bf4c41b
commit 7e66d3a9fc
No known key found for this signature in database
GPG Key ID: 4037D37741ED0CC5

View File

@ -31,7 +31,7 @@ function update_module_version() {
local v2version="${2}"
local modules
run go mod tidy
modules=$(run go list -f '{{if not .Main}}{{if not .Indirect}}{{.Path}}{{end}}{{end}}' -m all)
modules=$(go mod edit -json | jq -r '.Require[] | select(.Indirect | not) | .Path')
v3deps=$(echo "${modules}" | grep -E "${ROOT_MODULE}/.*/v3")
for dep in ${v3deps}; do
@ -97,16 +97,16 @@ function push_mod_tags_cmd {
# Any module ccan be used for this
local main_version
main_version=$(go list -f '{{.Version}}' -m "${ROOT_MODULE}/api/v3")
main_version=$(go mod edit -json | jq -r '.Require[] | select(.Path == "'"${ROOT_MODULE}"'/api/v3") | .Version')
local tags=()
keyid=$(get_gpg_key) || return 2
for module in $(modules); do
local version
version=$(go list -f '{{.Version}}' -m "${module}")
version=$(go mod edit -json | jq -r '.Require[] | select(.Path == "'"${module}"'") | .Version')
local path
path=$(go list -f '{{.Path}}' -m "${module}")
path=$(go mod edit -json | jq -r '.Require[] | select(.Path == "'"${module}"'") | .Path')
local subdir="${path//${ROOT_MODULE}\//}"
local tag
if [ -z "${version}" ]; then
@ -121,7 +121,7 @@ function push_mod_tags_cmd {
# consider main-module's tag as the latest.
run sleep 2
run git tag --local-user "${keyid}" --sign "${tag}" --message "${version}"
tags=("${tags[@]}" "${tag}")
tags+=("${tag}")
done
maybe_run git push -f "${REMOTE_REPO}" "${tags[@]}"
}