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

Add basic CI checks #2

Merged
merged 1 commit into from
Jan 13, 2022
Merged

Add basic CI checks #2

merged 1 commit into from
Jan 13, 2022

Conversation

simonswine
Copy link
Collaborator

  • golangci-lint
  • misspell
  • go test

@simonswine simonswine force-pushed the 20220113_test-lint branch 2 times, most recently from 72f17ed to 51eb738 Compare January 13, 2022 10:33
Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left some questions.

Makefile Show resolved Hide resolved
go run github.com/client9/misspell/cmd/misspell@v0.3.4 -error README.md LICENSE

# Configured via .golangci.yml.
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0 run
Copy link
Contributor

@aknuds1 aknuds1 Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good idea to run golangci-lint from source? They specifically say to install a binary:

Note: such go get installation aren't guaranteed to work. We recommend using binary installation.

I think Grafana uses bingo to pin the golangci-lint version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too sure what we should aim for. The nice thing with go run is that you don't need to trust/validate binaries and they work on any supported os/architecture. I would rather have that benefit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonswine WDYT think of using bingo or Docker?

Copy link
Contributor

@aknuds1 aknuds1 Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having thought a bit more, golangci-lint recommends using their own GitHub Action for CI, and locally Docker might be the best option. I'm frankly unsure if bingo installs from source, which would return us to the original problem.

The most worrying issue with installing golangci-lint from source that I can see would be:

go.mod replacement directive doesn't apply. It means a user will be using patched version of golangci-lint if we use such replacements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is all theoretical problem as there are no replaces in the version of golangci-lint: https://github.com/golangci/golangci-lint/blob/v1.43.0/go.mod

I still think the go run is the most slim and still correct approach.

With a github action, how could I make sure the right version is used locally when I run make lint?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Their point is they might add replaces in a future version though, and we probably won't think to check when upgrading.

With a github action, how could I make sure the right version is used locally when I run make lint?

Use their GitHub Action in CI, and use the recommended Docker command in Makefile.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still very skeptical about the docker approach. It will have to download the image once and then potentially all the go modules everytime running the container. This takes quite a while:

# First run (docker image pull)
$ time docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.43.0 golangci-lint run -v                                                                                                                                                                                   
0.10s user 0.03s system 0% cpu 1:14.54 total
# Second run
 0.04s user 0.01s system 0% cpu 21.918 total

Compared to go run:

# First run (go build cache empty)
$ time go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0 run
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0 run  90.59s user 7.87s system 591% cpu 16.634 total
# Second run
$ time go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0 run
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0 run  4.66s user 1.37s system 246% cpu 2.443 total

I think both of the runs with the container take significantly longer (and require the modules to be fetched on every run of golangci-lint). Also by using docker and the github action I need to have the version used specified twice (once in the workflow file and once the in the Makefile).

I think overall this is a worse approach than using go run and have potential problem when using an upgrade that replaced dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonswine personally I prefer correctness/robustness (wrt. potential breakage when upgrading golangci-lint) over speed, especially when it comes to CI. I understand that this comes down to the opinion of those involved though. What do e.g. @pracucci and @pstibrany think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference is to build only our software, and leverage on existing builds when possible, mostly because it seems like waste of resources. But it's just a preference, not a hard rule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't care much. I wouldn't block on this. It's something we can revisit anytime.

scenario_test.go Show resolved Hide resolved
service_test.go Show resolved Hide resolved
Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock, but would be good to hear what others think about how to fetch golangci-lint (Docker/GH Action vs running from source).

go run github.com/client9/misspell/cmd/misspell@v0.3.4 -error README.md LICENSE

# Configured via .golangci.yml.
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0 run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't care much. I wouldn't block on this. It's something we can revisit anytime.

@pracucci pracucci merged commit bc8aeeb into main Jan 13, 2022
@pracucci pracucci deleted the 20220113_test-lint branch January 13, 2022 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants