From 9967ddcfb7c85c8053652198df7e715437b9b9da Mon Sep 17 00:00:00 2001 From: Rustiqly Date: Sat, 7 Mar 2026 16:18:21 -0800 Subject: [PATCH] [build] Add go mod tidy with version guard before go mod vendor for Go 1.24 compat Add version-protected go mod tidy before go mod vendor, matching the approach in sonic-mgmt-common #207. The version check ensures go mod tidy only runs when the installed Go version is >= the go.mod directive, preventing failures in CI environments with older Go versions. Signed-off-by: Rustiqly --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 73ee131577..b223965cd0 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,15 @@ $(GO_MOD): $(GO) mod init github.com/Azure/sonic-mgmt-framework $(GO_DEPS): $(GO_MOD) $(GO_CODEGEN_INIT) + @# Run go mod tidy only if installed Go >= go.mod's go directive + @GO_MOD_VER=$$(sed -n 's/^go //p' go.mod) && \ + GO_CUR_VER=$$($(GO) env GOVERSION | sed 's/go//') && \ + if printf '%s\n' "$$GO_MOD_VER" "$$GO_CUR_VER" | sort -V | head -1 | grep -qx "$$GO_MOD_VER"; then \ + echo "Running go mod tidy (Go $$GO_CUR_VER >= go.mod $$GO_MOD_VER)"; \ + $(GO) mod tidy; \ + else \ + echo "Skipping go mod tidy (Go $$GO_CUR_VER < go.mod $$GO_MOD_VER)"; \ + fi $(GO) mod vendor $(MGMT_COMMON_DIR)/patches/apply.sh vendor touch $@