Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve Go detection #5112

Merged
merged 2 commits into from
Nov 7, 2024
Merged

fix: improve Go detection #5112

merged 2 commits into from
Nov 7, 2024

Conversation

ldez
Copy link
Member

@ldez ldez commented Nov 7, 2024

To reproduce:

before
$ docker run --rm -v $(pwd):/app -w /app -it golang:1.23.2-alpine sh  
/app # GOTOOLCHAIN=go1.22.1 go install github.com/golangci/golangci-lint/cmd/[email protected]
...
/app # golangci-lint version
golangci-lint has version v1.61.0 built with go1.22.1 from (unknown, modified: ?, mod sum: "h1:VvbOLaRVWmyxCnUIMTbf1kDsaJbTzH20FAMXTAlQGu8=") on (unknown)

/app # rm -rf /go/pkg/mod/golang.org/toolchain@*

/app # go version
go version go1.23.2 linux/amd64

/app # golangci-lint run
###### High memory and CPU consumption and kill
after
$ docker run --rm -v $(pwd):/app -w /app -it golang:1.23.2-alpine sh  
/app # ./golangci-lint version
golangci-lint has version (devel) built with go1.22.9 from (ac4d2c5c57fb41b42287cc0bad8b908eede8d01a, modified: false, mod sum: "") on 2024-11-07T14:40:46Z
/app # ./golangci-lint run
Error: can't load config: the Go language version (go1.22) used to build golangci-lint is lower than the targeted Go version (1.23.1)
Failed executing command with error: can't load config: the Go language version (go1.22) used to build golangci-lint is lower than the targeted Go version (1.23.1)
/app # 

There is still an unmanaged case:

  • golangci-lint built with go1.22
  • local Go version go1.23
  • go 1.22 with no toolchain inside the go.mod

But this case cannot be caught without calling the Go binary, and I think this is a bad idea.

Also technically, the go version inside the go.mod is enough to analyze but the problem happens when Go handles the toolchain version before running golangci-lint.
In this case, Go will install a newer version of Go (go1.23), and the problem will happen.

toolchain defines the minimum Go compiler version used to build.
go defines the minimum Go language version used to write the code.

The difference is really important: if your module is a lib, then the user of this lib will rely on go and not on toolchain. This is the same thing for the tool pattern, only go will be used and not on toolchain.


Related to #4909
Related to #4938

@ldez ldez added the bug Something isn't working label Nov 7, 2024
@ldez ldez added this to the next milestone Nov 7, 2024
@ldez ldez merged commit 7560b4f into golangci:master Nov 7, 2024
15 checks passed
@ldez ldez deleted the fix/detect-go-version branch November 7, 2024 18:36
@ldez ldez modified the milestones: next, v1.62 Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants