1
0
mirror of https://github.com/etcd-io/etcd.git synced 2026-02-05 06:46:49 +01:00

Migrate verify-go-versions to use a Go workspace

Add checking for the Go toolchain directive in the go.work file too.

Signed-off-by: Ivan Valdes <ivan@vald.es>
This commit is contained in:
Ivan Valdes
2025-02-14 21:05:54 -08:00
parent f06855c2e0
commit 2b1b74a457
2 changed files with 17 additions and 0 deletions

View File

@@ -25,3 +25,4 @@ source ./scripts/test_lib.sh
TARGET_GO_VERSION="${TARGET_GO_VERSION:-"$(cat "${ETCD_ROOT_DIR}/.go-version")"}"
find . -name 'go.mod' -exec go mod edit -toolchain=go"${TARGET_GO_VERSION}" {} \;
go work edit -toolchain=go"${TARGET_GO_VERSION}"

View File

@@ -47,6 +47,20 @@ function verify_go_versions() {
fi
}
# Workaround to get go.work's toolchain, as go work edit -json doesn't return
# the toolchain as of Go 1.24. When this is fixed, we can replace these two
# checks with verify_go_versions go.work
toolchain_version="$(grep toolchain go.work | cut -d' ' -f2)"
if [[ "go${target_go_version}" != "${toolchain_version}" ]]; then
log_error "go toolchain directive out of sync for go.work, got: ${toolchain_version}"
toolchain_out_of_sync="true"
fi
go_line_version="$(go work edit -json | jq -r .Go)"
if ! printf '%s\n' "${go_line_version}" "${target_go_version}" | sort --check=silent --version-sort; then
log_error "go directive in go.work is greater than maximum allowed: go${target_go_version}"
go_line_violation="true"
fi
while read -r mod; do
verify_go_versions "${mod}";
done < <(find . -name 'go.mod')
@@ -64,3 +78,5 @@ fi
if [[ "${go_line_violation}" == "true" ]] || [[ "${toolchain_out_of_sync}" == "true" ]]; then
exit 1
fi
log_success "SUCCESS: Go toolchain directive in sync"