-
Notifications
You must be signed in to change notification settings - Fork 471
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 some linting failures and configure golangci-lint #922
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this, l wonder if CI should run make lint
to be consistent with local dev story.
For example, this PR is currently passing the golangci-lint, but failing Travis do to the gofmt check. Ideally, GitHub actions would catch both.
system/service_systemd.go
Outdated
@@ -73,7 +77,9 @@ func (s *ServiceSystemd) Running() (bool, error) { | |||
return false, nil | |||
} | |||
cmd := util.NewCommand("systemctl", "-q", "is-active", s.service) | |||
cmd.Run() | |||
if err := cmd.Run(); err != nil { | |||
return false, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should probably bubble up the error:
return false, err
golangci-lint: | ||
$(info INFO: Starting build $@) | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
golangci-lint run --timeout 5m $(pkgs) | ||
|
||
lint: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we change this to also run golangci-lint.
lint: golangci-lint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think golint
does not exist anymore and golint
can be replaced by golangci-lint
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, didn't even notice that, yeah.. we can replace golint
in the lint
target with golangci-lint
that makes more sense.
So much has changed in the go ecosystem since Goss was originally written.
I have added fmt to pipeline. goss/.github/workflows/golangci-lint.yaml Line 27 in 7ca5459
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, small comment on golint and make targets.
The travis-ci is failing because cmd.Run() will return an error on non-zero exit status. So would need to either:
- Ignore the errors and skip linting those calls
- Add a check for ExitError and ignore it
- Refactor cmd.Run() to ignore ExitError and the consumer code has to do a check for Status if they care.
golangci-lint: | ||
$(info INFO: Starting build $@) | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
golangci-lint run --timeout 5m $(pkgs) | ||
|
||
lint: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, didn't even notice that, yeah.. we can replace golint
in the lint
target with golangci-lint
that makes more sense.
So much has changed in the go ecosystem since Goss was originally written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can promote this out of draft.
At some point, I'll run a golangci-lint run
and fix all the findings.
curious, what are the pros/cons of using golangci-lint-action vs just running make lint
in a github action?
I assume the former provides some unique benefits/flags, but requires making sure the local make lint
and the job are in sync, (same version, same flags, etc.).
Anyways, correct me if I'm wrong, but putting everything behind make should make it easier to move off of github if that ends up being another transition in the future?
ctx := context.WithValue(context.Background(), "id", a.ID()) | ||
ctx := context.WithValue(context.Background(), idKey{}, a.ID()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue was:
resource/addr.go:54:49: SA1029: should not use built-in type string as key for value; define your own type to avoid collisions (staticcheck)
ctx := context.WithValue(context.Background(), "id", a.ID())
I have decided to "Ignore the errors and skip linting those calls" |
I think the github actions are actively developed further and certainly optimised for performance and caching. For this you have to maintain makefile and action twice. The github action also runs without problems on forked branches. With the makefile, each developer has to make sure that it works, which hopefully it does out of the box.
I think so, too. |
Sorry, the PR has become a little more complicated than planned. In the end, the currently configured linting has now been fully implemented and the pipeline no longer only needs to check the diff ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. I assume this is ready to merge.
I can enable some of the commented out lintes and fix some of the issues as follow up PRs.
marked this as approved, if you're ready for this to be merged just post a comment here and I'll merge it.
Minor question:
Why does |
Yes, is ready for merging. |
I think I was thinking too much. The crucial point is that the Travis CI only runs when you create a PR. Otherwise you would have to have your own Travis account. But for development it would also be good to run the CI beforehand creating a PR. For example, I sometimes develop directly in GitHub without a computer that has |
Checklist
make test-all
(UNIX) passes. CI will also test thisDescription of change
Fix some linting failures and add new go linting to makefile.
I am not a go expert. Please have a deeper look inside.
See a list of lint failures at: