Skip to content

Commit 573134f

Browse files
committed
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 <[email protected]>
1 parent d6c14b4 commit 573134f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

scripts/sync_go_toolchain_directive.sh

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ source ./scripts/test_lib.sh
1212

1313
TARGET_GO_VERSION="${TARGET_GO_VERSION:-"$(cat "${ETCD_ROOT_DIR}/.go-version")"}"
1414
find . -name 'go.mod' -exec go mod edit -toolchain=go"${TARGET_GO_VERSION}" {} \;
15+
go work edit -toolchain=go"${TARGET_GO_VERSION}"

scripts/verify_go_versions.sh

+16
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ function verify_go_versions() {
3434
fi
3535
}
3636

37+
# Workaround to get go.work's toolchain, as go work edit -json doesn't return
38+
# the toolchain as of Go 1.24. When this is fixed, we can replace these two
39+
# checks with verify_go_versions go.work
40+
toolchain_version="$(grep toolchain go.work | cut -d' ' -f2)"
41+
if [[ "go${target_go_version}" != "${toolchain_version}" ]]; then
42+
log_error "go toolchain directive out of sync for go.work, got: ${toolchain_version}"
43+
toolchain_out_of_sync="true"
44+
fi
45+
go_line_version="$(go work edit -json | jq -r .Go)"
46+
if ! printf '%s\n' "${go_line_version}" "${target_go_version}" | sort --check=silent --version-sort; then
47+
log_error "go directive in go.work is greater than maximum allowed: go${target_go_version}"
48+
go_line_violation="true"
49+
fi
50+
3751
while read -r mod; do
3852
verify_go_versions "${mod}";
3953
done < <(find . -name 'go.mod')
@@ -51,3 +65,5 @@ fi
5165
if [[ "${go_line_violation}" == "true" ]] || [[ "${toolchain_out_of_sync}" == "true" ]]; then
5266
exit 1
5367
fi
68+
69+
log_success "SUCCESS: Go toolchain directive in sync"

0 commit comments

Comments
 (0)