Skip to content

Commit e2c6734

Browse files
committed
Go: Only call EmitNewerGoVersionNeeded at most once
1 parent 6eac48c commit e2c6734

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

go/extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -574,22 +574,26 @@ func installDependenciesAndBuild() {
574574
}
575575
}
576576

577+
// Find the greatest version of Go that is required by the workspaces to check it against the version
578+
// of Go that is installed on the system.
579+
greatestGoVersion := project.RequiredGoVersion(&workspaces)
580+
581+
// This diagnostic is not required if the system Go version is 1.21 or greater, since the
582+
// Go tooling should install required Go versions as needed.
583+
if semver.Compare(toolchain.GetEnvGoSemVer(), "v1.21.0") < 0 && greatestGoVersion.Found && semver.Compare("v"+greatestGoVersion.Version, toolchain.GetEnvGoSemVer()) > 0 {
584+
diagnostics.EmitNewerGoVersionNeeded(toolchain.GetEnvGoSemVer(), "v"+greatestGoVersion.Version)
585+
if val, _ := os.LookupEnv("GITHUB_ACTIONS"); val == "true" {
586+
log.Printf(
587+
"A go.mod file requires version %s of Go, but version %s is installed. Consider adding an actions/setup-go step to your workflow.\n",
588+
"v"+greatestGoVersion.Version,
589+
toolchain.GetEnvGoSemVer())
590+
}
591+
}
592+
577593
// Attempt to extract all workspaces; we will tolerate individual extraction failures here
578594
for i, workspace := range workspaces {
579595
goVersionInfo := workspace.RequiredGoVersion()
580596

581-
// This diagnostic is not required if the system Go version is 1.21 or greater, since the
582-
// Go tooling should install required Go versions as needed.
583-
if semver.Compare(toolchain.GetEnvGoSemVer(), "v1.21.0") < 0 && goVersionInfo.Found && semver.Compare("v"+goVersionInfo.Version, toolchain.GetEnvGoSemVer()) > 0 {
584-
diagnostics.EmitNewerGoVersionNeeded(toolchain.GetEnvGoSemVer(), "v"+goVersionInfo.Version)
585-
if val, _ := os.LookupEnv("GITHUB_ACTIONS"); val == "true" {
586-
log.Printf(
587-
"The go.mod file requires version %s of Go, but version %s is installed. Consider adding an actions/setup-go step to your workflow.\n",
588-
"v"+goVersionInfo.Version,
589-
toolchain.GetEnvGoSemVer())
590-
}
591-
}
592-
593597
fixGoVendorIssues(&workspace, goVersionInfo.Found)
594598

595599
tryUpdateGoModAndGoSum(workspace)

0 commit comments

Comments
 (0)