golangci/golangci-lint-action

Reading golangci-lint version from go.mod

zhulik opened this issue · 6 comments

Welcome

  • Yes, I understand that the GitHub action repository is not the repository of golangci-lint itself.
  • Yes, I've searched similar issues on GitHub and didn't find any.

Your feature request related to a problem? Please describe.

With introduction of the tool directive in go 1.24 it's now possible to specify golangci-lint version right in go.mod, I think it would be nice if this action installed version specified in it instead of having it pinned in multiple places.

Describe the solution you'd like.

To preserve backwards compatibility, a new possible value for install-mode can be introduced: install-mode: "gotool", in this case version input value will be ignored and version specified in go.mod will be installed.

In this case, golangci-lint should be also ran as go tool github.com/golangci/golangci-lint/cmd/golangci-lint run

Describe alternatives you've considered.

As an alternative a new possible value for version can be added version: "gotool", this will keep the specified way of installation and running unchanged, only version will be read from go.mod.

Additional context.

No response

ldez commented

Hello,

Reading the go.mod has already been implemented since 2021, you just have to let the version field empty.

Using go tool to install golangci-lint is strongly discouraged.

https://golangci-lint.run/welcome/install/#install-from-sources

My bad, you're correct. My first attempt was using goinstall mode along with omitting version. With this config latest version was installed, so I thought this is the default behavior for binary too. Thanks!

Hello,

Reading the go.mod has already been implemented since 2021, you just have to let the version field empty.

Using go tool to install golangci-lint is strongly discouraged.

https://golangci-lint.run/welcome/install/#install-from-sources

Is this documented anywhere. I couldn't find it in the main readme. Happy to PR if I'm just missing it

ldez commented

It's not something I want to promote because this implies using the tools pattern.

The tools pattern is worse than go install: this pattern allows users to update dependencies, but the dependencies of golangci-lint should not be updated outside of the official updates.
In the past, this led to problems for linter authors, and golangci-lint.

So, I hope you understand why this is not documented.

Note: the new go tool is worse than the tools pattern because it mixes all dependencies.

I understand the concern. Is there another suggestion for standardizing on versions? Maybe something in the .golangci.yaml file I've missed. Specifying versions in github workflows, aligning developer machine versions, and keeping everything in sync is quite a pain.

ldez commented

My recommendation is to use a fixed version on your CI (ex: v1.64) to have a stable and reproducible environment.

For the local installation, you have to follow the update of the packagers for Linux/macOS/Windows. https://golangci-lint.run/welcome/install/#local-installation
If you do that, all the devs will have the same versions.

When someone works on a project, they can update the CI if needed.

Remember that we maintain only one version of golangci-lint (the latest), so using golangci-lint version per project is a bad idea. Only the latest version should be used.