Skip to content

A better way to install and run golangci-lint in a single command #1657

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

Open
ysmood opened this issue Jan 18, 2021 · 9 comments
Open

A better way to install and run golangci-lint in a single command #1657

ysmood opened this issue Jan 18, 2021 · 9 comments
Labels
no decision No decision to fix or not proposal

Comments

@ysmood
Copy link

ysmood commented Jan 18, 2021

Currently, the major way to install golangci-lint requires extra dependencies like sh, curl, tar, etc. It's not cross-platform and not user friendly to maintain.

Since any user use this tool will have golang installed, why not just use golang to do the automation job? So that there will be zero dependencies and assumptions for users' environment.

Here's my demo solution project: https://github.com/ysmood/golangci-lint
The demo project has zero dependencies and fast to download, build, and run.

How about we fork the project to a namespace like golangci/golangci-linter and document it here

So that we don't have to maintain Brew or MacPorts binary anymore.

@ysmood ysmood added the enhancement New feature or improvement label Jan 18, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Jan 18, 2021

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@sfllaw
Copy link

sfllaw commented Apr 1, 2021

This reminds me of go get golang.org/dl/go1.xx.x, which is how you can install multiple versions of Go: https://golang.org/doc/manage-install

@ysmood
Copy link
Author

ysmood commented Apr 2, 2021

This reminds me of go get golang.org/dl/go1.xx.x, which is how you can install multiple versions of Go: https://golang.org/doc/manage-install

Yes, I borrowed some ideas from it.

@pellared
Copy link

pellared commented May 12, 2021

What about installing golangci-lint using the new go install syntax like this:

go install github.com/golangci/golangci-lint/cmd/[email protected]

This way is (I believe) truly cross-platform and can be used e.g. like this: https://github.com/pellared/goyek-demo/blob/e51b9211be1155cbf1cca40d8f1eb392e6dda592/build/build.go#L41-L46

It does not have some of the disadvantages that go get has. Also installing via go get may be removed in Go 1.17: golang/go#43684

References

From: https://golang.org/ref/mod

Since Go 1.16, go install is the recommended command for building and installing programs. When used with a version suffix (like @latest or @v1.4.6), go install builds packages in module-aware mode, ignoring the go.mod file in the current directory or any parent directory, if there is one.

More:

@ysmood
Copy link
Author

ysmood commented May 12, 2021

@pellared The problem is to build the golangci-lint might consume a lot of network bandwidth and CPU, and it has its own Makefile which is outside the Go ecosystem, which means if you don't use their Makefile, they can't guarantee it will work properly.

I tested with bare docker container, it will be significantly slower to use go install vs downloading the binary directly:

With go install

$ docker run --rm -it golang bash
$ time go install github.com/golangci/golangci-lint/cmd/[email protected]
real    0m46.282s

With my solution

$ docker run --rm -it golang bash
$ time go install github.com/ysmood/golangci-lint@latest
real    0m7.769s
$ time golangci-lint
real    0m1.330s

As you can see the go install is 5 times slower. If I use a faster machine, the difference can be 10 times.

@pellared
Copy link

@ysmood It is cool. Personally, I would add an option to add a checksum validation for additional integrity checking. Supply chain attacks are becoming more and more frequent.

@ysmood
Copy link
Author

ysmood commented May 12, 2021

@pellared Good idea, please feel free to make a PR. Currently, this project is just a proof of concept, welcomes all kinds of ideas.

@photoszzt
Copy link

The current recommended approach is also documenting the tool used in a file called tools.go. https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md

@ysmood
Copy link
Author

ysmood commented Jan 12, 2022

@photoszzt I think it has the same issue because internally go install uses a similar build process as go get:

image

@ldez ldez added no decision No decision to fix or not proposal and removed enhancement New feature or improvement labels Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no decision No decision to fix or not proposal
Projects
None yet
Development

No branches or pull requests

5 participants