From 7fbcc8cd10fca625eedc3ed8ffc4c6ba1e6f86dc Mon Sep 17 00:00:00 2001 From: xgopilot Date: Thu, 16 Oct 2025 02:33:53 +0000 Subject: [PATCH] refactor: use runtime.Version() instead of hardcoded goVersion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced hardcoded goVersion constant with parseGoVersion() function that dynamically extracts the Go version from runtime.Version(). This eliminates the need to update the version manually. 🤖 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang --- runtime/internal/lib/go/build/build.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/runtime/internal/lib/go/build/build.go b/runtime/internal/lib/go/build/build.go index 7e0d3746..676108bc 100644 --- a/runtime/internal/lib/go/build/build.go +++ b/runtime/internal/lib/go/build/build.go @@ -13,13 +13,32 @@ import ( "path/filepath" "runtime" "strconv" + "strings" ) // Type aliases to reference standard library types type Context = build.Context -// Go version constant (Go 1.24) -const goVersion = 24 +// parseGoVersion extracts the minor version number from runtime.Version() +// e.g., "go1.24" or "go1.24.1" -> 24 +func parseGoVersion() int { + v := runtime.Version() + // Strip "go" prefix + if strings.HasPrefix(v, "go") { + v = v[2:] + } + // Extract version like "1.24" or "1.24.1" + parts := strings.Split(v, ".") + if len(parts) >= 2 { + if minor, err := strconv.Atoi(parts[1]); err == nil { + return minor + } + } + // Fallback to a reasonable default if parsing fails + return 24 +} + +var goVersion = parseGoVersion() var defaultToolTags []string var defaultReleaseTags []string