Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Migrate to go mod and golangci-lint #51

Merged
merged 4 commits into from
Jan 9, 2020
Merged

Migrate to go mod and golangci-lint #51

merged 4 commits into from
Jan 9, 2020

Conversation

magi345
Copy link

@magi345 magi345 commented Dec 19, 2019

Deprecated

  • dep
  • gpmetalinter

Migrated to

  • go mod
  • golangci-lint

@magi345
Copy link
Author

magi345 commented Dec 19, 2019

Copy link

@yangru yangru left a comment

Choose a reason for hiding this comment

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

LGTM

@magi345
Copy link
Author

magi345 commented Dec 24, 2019

@chrishajas @khuddlefish @pf-qiu @fanfuxiaoran @dsharp-pivotal
I have this PR to do housekeeping for gp-common-go-libs, please review if these changes ok to your projects.
I will hold merge until 2020-01-07. Please comment if any concerns or impacts.

  • Hao

@pf-qiu
Copy link

pf-qiu commented Dec 24, 2019

We don't use master branch so shouldn't be a problem for us.

@magi345
Copy link
Author

magi345 commented Dec 24, 2019

We don't use master branch so shouldn't be a problem for us.

Maybe separate issue, just curious why needs to maintain your code in another branch?
Is there any conflict with anybody if merge your contribution to master?

go get golang.org/x/tools/cmd/goimports
go get github.com/onsi/ginkgo/ginkgo
go mod vendor
go mod tidy
Copy link
Contributor

Choose a reason for hiding this comment

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

This also seems unnecessary. It could cause unexpected diffs.

Copy link

Choose a reason for hiding this comment

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

Hi, @dsharp-pivotal
From the best practise, It's always recommended to run go mod tidy after go install or go build.

Here's some explanation from golang repo:
golang/go#27633

The reason is that go mod tidy is agnostic of GOOS/GOARCH or build tags; go build is lazy and only does the minimal amount of work required for the current GOOS/GOARCH and build tags.

cc @bcmills - I wonder whether we should update the documentation for go mod tidy to include some note about this operation being agnostic of GOOS/GOARCH and build tags:
...
Because one reading of the documentation is that go build and go mod tidy should leave go.mod in the same state.

Copy link
Author

Choose a reason for hiding this comment

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

I kept the go mod tidy statement according to above explanation from yangru

@cd vendor/golang.org/x/tools/cmd/goimports; go install .
@cd vendor/github.com/onsi/ginkgo/ginkgo; go install .
go get golang.org/x/tools/cmd/goimports
go get github.com/onsi/ginkgo/ginkgo
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be go install?

Copy link
Author

Choose a reason for hiding this comment

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

go get github.com/onsi/ginkgo/ginkgo will install the binary executable into $GOPATH/bin/ so don't need to run go install.
The same with goimports.

Makefile Outdated
@@ -12,8 +12,7 @@ GOFLAGS :=
.PHONY : coverage

dependencies :
go get github.com/alecthomas/gometalinter
gometalinter --install
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.21.0
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, we install with go install -i github.com/golangci/golangci-lint/cmd/golangci-lint

Copy link
Author

Choose a reason for hiding this comment

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

According to the readme of golangci-lint https://github.com/golangci/golangci-lint#binary, it suggests use curl to install.
It says Please, do not install golangci-lint by go get:

1. go.mod replacement directive doesn't apply. It means you will be using patched version of golangci-lint.
2. it's much slower than binary installation
3. its stability depends on your Go version (e.g. on this compiler Go <= 1.12 bug).
4. it's not guaranteed to work: e.g. we've encountered a lot of issues with Go modules hashes.
5. it allows installation from master branch which can't be considered stable.

I think go install is the same with with go get, it will pollute the go.mod/go.sum files.

@magi345 magi345 merged commit fdbcf7e into master Jan 9, 2020
@magi345 magi345 deleted the gomod branch January 9, 2020 09:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants