@@ -119,6 +119,13 @@ func (opts BuildOpts) getNodePath() string {
119119 return "node"
120120}
121121
122+ type GoVersionCheckResult struct {
123+ GoStatus string
124+ GoPath string
125+ GoVersion string
126+ ErrorString string
127+ }
128+
122129func FindGoExecutable () (string , error ) {
123130 // First try the standard PATH lookup
124131 if goPath , err := exec .LookPath ("go" ); err == nil {
@@ -156,72 +163,133 @@ func FindGoExecutable() (string, error) {
156163 return "" , fmt .Errorf ("go command not found in PATH or common installation locations" )
157164}
158165
159- func verifyEnvironment (verbose bool , opts BuildOpts ) (* BuildEnv , error ) {
160- oc := opts .OutputCapture
161-
162- if opts .SdkVersion == "" && opts .SdkReplacePath == "" {
163- return nil , fmt .Errorf ("either SdkVersion or SdkReplacePath must be set" )
164- }
165-
166- if opts .SdkVersion != "" {
167- versionRegex := regexp .MustCompile (`^v\d+\.\d+\.\d+` )
168- if ! versionRegex .MatchString (opts .SdkVersion ) {
169- return nil , fmt .Errorf ("SdkVersion must be in semantic version format (e.g., v0.0.0), got: %s" , opts .SdkVersion )
170- }
171- }
172-
166+ func CheckGoVersion (customGoPath string ) GoVersionCheckResult {
173167 var goPath string
174168 var err error
175169
176- if opts .GoPath != "" {
177- goPath = opts .GoPath
178- if verbose {
179- oc .Printf ("Using custom go path: %s" , opts .GoPath )
180- }
170+ if customGoPath != "" {
171+ goPath = customGoPath
181172 } else {
182173 goPath , err = FindGoExecutable ()
183174 if err != nil {
184- return nil , fmt .Errorf ("go command not found: %w" , err )
185- }
186- if verbose {
187- oc .Printf ("Using go path: %s" , goPath )
175+ return GoVersionCheckResult {
176+ GoStatus : "notfound" ,
177+ GoPath : "" ,
178+ GoVersion : "" ,
179+ ErrorString : "" ,
180+ }
188181 }
189182 }
190183
191- // Run go version command
192184 cmd := exec .Command (goPath , "version" )
193185 output , err := cmd .Output ()
194186 if err != nil {
195- return nil , fmt .Errorf ("failed to run 'go version': %w" , err )
187+ return GoVersionCheckResult {
188+ GoStatus : "error" ,
189+ GoPath : goPath ,
190+ GoVersion : "" ,
191+ ErrorString : fmt .Sprintf ("failed to run 'go version': %v" , err ),
192+ }
196193 }
197194
198- // Parse go version output and check for 1.22+
199195 versionStr := strings .TrimSpace (string (output ))
200- if verbose {
201- oc .Printf ("Found %s" , versionStr )
202- }
203196
204- // Extract version like "go1.22.0" from output
205197 versionRegex := regexp .MustCompile (`go(1\.\d+)` )
206198 matches := versionRegex .FindStringSubmatch (versionStr )
207199 if len (matches ) < 2 {
208- return nil , fmt .Errorf ("unable to parse go version from: %s" , versionStr )
200+ return GoVersionCheckResult {
201+ GoStatus : "error" ,
202+ GoPath : goPath ,
203+ GoVersion : versionStr ,
204+ ErrorString : fmt .Sprintf ("unable to parse go version from: %s" , versionStr ),
205+ }
209206 }
210207
211208 goVersion := matches [1 ]
212209
213- // Check if version is 1.22+
214210 minorRegex := regexp .MustCompile (`1\.(\d+)` )
215211 minorMatches := minorRegex .FindStringSubmatch (goVersion )
216212 if len (minorMatches ) < 2 {
217- return nil , fmt .Errorf ("unable to parse minor version from: %s" , goVersion )
213+ return GoVersionCheckResult {
214+ GoStatus : "error" ,
215+ GoPath : goPath ,
216+ GoVersion : versionStr ,
217+ ErrorString : fmt .Sprintf ("unable to parse minor version from: %s" , goVersion ),
218+ }
218219 }
219220
220221 minor , err := strconv .Atoi (minorMatches [1 ])
221- if err != nil || minor < MinSupportedGoMinorVersion {
222- return nil , fmt .Errorf ("go version 1.%d or higher required, found: %s" , MinSupportedGoMinorVersion , versionStr )
222+ if err != nil {
223+ return GoVersionCheckResult {
224+ GoStatus : "error" ,
225+ GoPath : goPath ,
226+ GoVersion : versionStr ,
227+ ErrorString : fmt .Sprintf ("failed to parse minor version: %v" , err ),
228+ }
229+ }
230+
231+ if minor < MinSupportedGoMinorVersion {
232+ return GoVersionCheckResult {
233+ GoStatus : "badversion" ,
234+ GoPath : goPath ,
235+ GoVersion : versionStr ,
236+ ErrorString : "" ,
237+ }
223238 }
224239
240+ return GoVersionCheckResult {
241+ GoStatus : "ok" ,
242+ GoPath : goPath ,
243+ GoVersion : versionStr ,
244+ ErrorString : "" ,
245+ }
246+ }
247+
248+ func verifyEnvironment (verbose bool , opts BuildOpts ) (* BuildEnv , error ) {
249+ oc := opts .OutputCapture
250+
251+ if opts .SdkVersion == "" && opts .SdkReplacePath == "" {
252+ return nil , fmt .Errorf ("either SdkVersion or SdkReplacePath must be set" )
253+ }
254+
255+ if opts .SdkVersion != "" {
256+ versionRegex := regexp .MustCompile (`^v\d+\.\d+\.\d+` )
257+ if ! versionRegex .MatchString (opts .SdkVersion ) {
258+ return nil , fmt .Errorf ("SdkVersion must be in semantic version format (e.g., v0.0.0), got: %s" , opts .SdkVersion )
259+ }
260+ }
261+
262+ result := CheckGoVersion (opts .GoPath )
263+
264+ switch result .GoStatus {
265+ case "notfound" :
266+ return nil , fmt .Errorf ("go command not found" )
267+ case "badversion" :
268+ return nil , fmt .Errorf ("go version 1.%d or higher required, found: %s" , MinSupportedGoMinorVersion , result .GoVersion )
269+ case "error" :
270+ return nil , fmt .Errorf ("%s" , result .ErrorString )
271+ case "ok" :
272+ if verbose {
273+ if opts .GoPath != "" {
274+ oc .Printf ("Using custom go path: %s" , result .GoPath )
275+ } else {
276+ oc .Printf ("Using go path: %s" , result .GoPath )
277+ }
278+ oc .Printf ("Found %s" , result .GoVersion )
279+ }
280+ default :
281+ return nil , fmt .Errorf ("unexpected go status: %s" , result .GoStatus )
282+ }
283+
284+ versionRegex := regexp .MustCompile (`go(1\.\d+)` )
285+ matches := versionRegex .FindStringSubmatch (result .GoVersion )
286+ if len (matches ) < 2 {
287+ return nil , fmt .Errorf ("unable to parse go version from: %s" , result .GoVersion )
288+ }
289+ goVersion := matches [1 ]
290+
291+ var err error
292+
225293 // Check if node is available
226294 if opts .NodePath != "" {
227295 // Custom node path specified - verify it's absolute and executable
0 commit comments