Skip to content

Commit d7f66ae

Browse files
authored
[build] Add go mod tidy before go mod vendor for Go 1.24 compat (#157)
What: Adds a go mod tidy step before go mod vendor in the Makefile's $(GO_DEPS) target, with a version guard that only runs tidy when installed Go >= go.mod's directive. Why: Go 1.24 (Debian Trixie) enforces stricter module graph consistency, causing go mod vendor to fail unless go mod tidy runs first. On older Go (e.g. bookworm Go 1.21), tidy is skipped — no behavior change. How: Shell-based version comparison using sort -V to compare installed Go version against go.mod directive. Same pattern as sonic-mgmt-common#207. Testing: CI green, built successfully under Trixie (Go 1.24) and bookworm (Go 1.21). PR approved. Signed-off-by: Rustiqly <rustiqly@users.noreply.github.com>
1 parent 79619b6 commit d7f66ae

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ $(GO_MOD):
3737
$(GO) mod init github.com/Azure/sonic-mgmt-framework
3838

3939
$(GO_DEPS): $(GO_MOD) $(GO_CODEGEN_INIT)
40+
@# Run go mod tidy only if installed Go >= go.mod's go directive
41+
@GO_MOD_VER=$$(sed -n 's/^go //p' go.mod) && \
42+
GO_CUR_VER=$$($(GO) env GOVERSION | sed 's/go//') && \
43+
if printf '%s\n' "$$GO_MOD_VER" "$$GO_CUR_VER" | sort -V | head -1 | grep -qx "$$GO_MOD_VER"; then \
44+
echo "Running go mod tidy (Go $$GO_CUR_VER >= go.mod $$GO_MOD_VER)"; \
45+
$(GO) mod tidy; \
46+
else \
47+
echo "Skipping go mod tidy (Go $$GO_CUR_VER < go.mod $$GO_MOD_VER)"; \
48+
fi
4049
$(GO) mod vendor
4150
$(MGMT_COMMON_DIR)/patches/apply.sh vendor
4251
touch $@

0 commit comments

Comments
 (0)