-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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 golangci-lint issues reported on different OS #7776
Conversation
613e72c
to
7a20313
Compare
Do you think we should run golangci-lint on windows/macOS too? Actually I don't think we need to as this seems to work GOOS=windows golangci-lint run ./... We can probably wedge that into the |
Maybe we could.. However the running time maybe an issue? At least if we end up running it once for each of the supported GOOS values... PR checks already takes some 15-20 minutes, which is considerable. The linting something above 40s of that it seems, and of that again e.g. 11s for installing golangci-lint in the runner and 31s for running it. Running it multiple times in the same agent will hopefully run faster, assuming its clever enough to reuse cached results. Worth a little experiment, yes. |
I also noticed the following golangci-options while digging a bit into it earlier today, if it slows the checks down too much it could perhaps be an option to configure it to only check actual changed code when triggered by PRs? I haven't tested how it works, though.
|
I've been thinking, some of the issues may not be from golangci-lint, actually. I ran it from within VSCode at one point, and then it reports some issues from gopls as well, so I can look into that and revert - if some of them looks closer to false positives. |
The checks run in parallel so as long as we don't make the lint step take more that say 10 mins it won't affect the total running time. I think the lint runs quite quickly so I don't think we'll need to enable the diff check. You can always try the golangci lint binary from the command line to see if it matches vscode |
7a20313
to
d5a41af
Compare
I took a step back and re-ran the linting, and removed most of the fixes which were not from golangci-lint. Left a few of them, though, as I found they were quite unquestionable, as well as the go mod tidy commit. The removed gopls reported issues was mainly unusedparams issues like this: -func lChtimes(_ string, _ time.Time, _ time.Time) error {
+func lChtimes(name string, atime time.Time, mtime time.Time) error {
// Does nothing
return nil
} I assume golangci-lint would have reported them as well, if we hadn't had this configuration: Lines 91 to 92 in c09426b
Mainly because there would be a lot of such issues reported, probably. |
6139474
to
ad97dc8
Compare
Nice! What is up with netbsd and solaris I wonder?
Can you get vscode to use the the golangci-lint config that we supply in the root of the rclone source repo? I didn't enable unusedparams as in a project like rclone we implement the same interface many, many times and I think it is actually useful to keep the function definitions constant rather than change some of them to have |
Yes it does that. VSCode with go extension uses gopls for various language features and staticcheck specifically for linting by default, and its a simple setting to switch from staticcheck to golangci-lint. However the gopls, used for intellisense and a lot of things, also seem to do some lint-like checks. So its that gopls check that reports the unusedparams I mentioned. If I explicitely run the linting feature of VSCode it comes reports no issues. But when the gopls checks kick in they report additional issues, and all are mixed in a single "Problems" panel, thats why I "blamed" it on golangci-lint at first. I may look into the gopls vs lint settings at some point, but I think I'll just live with it for now..
Yes, I concluded on that too, that parameter names may indeed add relevant information even if not used. |
I don't know.. 😕 I suspect something to do with caching. In addition to the separate module cache step, which I suggest removing with #7779, the setup-go action has caching of modules and build output, and the golangci-lint action has caching of modules, build output - and lint results. Edit: In the build logs (also existing builds) there are from time to time a lot of "Cannot open: File exists" entries which is related to caching as well. Many discussions on similar things over at https://github.com/golangci/golangci-lint-action. Edit: I also added setup-go action to the lint job. The golangci-lint-action docs states:
But it obviously worked without it as well... 🤔 |
ad97dc8
to
3205d85
Compare
3205d85
to
f993b15
Compare
I wonder if golangci-lint is coping with caching results for different architectures OK? You can set cache keys for github runs but not sure that is relevant here since everything is in one run.
Can try
Odd! But your change sounds correct :-) |
I just added a commit which I think fixes the issues by some small adjustments to build tags in a couple of tests etc. Seems that fixed it actually, so maybe not caching after all. Unfortunately I also added linting on dragonfly, so that introduced a lot of errors again.. 😆 But not too hard to fix I think, with some more adjustments to build tags. But I don't know for which GOOS we do want to run the linting? All we have build tags for in code (linux, windows, darwin, freebsd, netbsd, openbsd, dragonfly, plan9, js, solaris)? All that we build during the PR checks (linux, darwin, windows)? All that we have builds for on download page (linux, windows, darwin, freebsd, netbsd, openbsd, plan9, solaris - but not dragonfly or js)? |
ad2b0c1
to
4b42add
Compare
All green in https://github.com/rclone/rclone/actions/runs/8737234254, with goos linux, windows, darwin, freebsd, netbsd, openbsd, dragonfly, plan9, solaris, but skipped js as that fails with "Running error: context loading failed: no go files to analyze: running But that run was with all cache hits on golangci-lint-action caches. I have manually deleted the caches now, and re-running it to see how that behaves.. |
4b42add
to
3af9396
Compare
That worked too: https://github.com/rclone/rclone/actions/runs/8737533920/job/23974720264 However, in the automatic Post processing steps, where the cache saving happens, the first post-step that runs, which is for the last lint step that ran, "Post Code quality test (Solaris)", saves the cache:
While the rest of the post steps does nothing - because all have the same cache key:
Next I'm running yet another build: https://github.com/rclone/rclone/actions/runs/8738200411/job/23976751398
And when done, the post steps does nothing:
And this will be done again for each of the lint steps, downloading the same cache, extracting over the existing identical one. So to conclude:
Maybe there is a trick to force use of individual caches, however as long as this works we save cache storage (which is under pressure: "Approaching total cache storage limit (14.47 GB of 10 GB Used)", and some time (for cache upload at least, but it already repeats the cache restores so no change there). So I think the remaining question is for which GOOS we should do the linting? |
The current approach, repeating golangci-lint-action steps with different GOOS, is based on: |
:-)
:-(
Good question. I think So if we can afford the runtime for 5 linters If we only have 4 then I'd choose Will this stop on the first lint failure? The reason I ask that is that the lint action also puts comments on the PRs so if the user makes a normal sort of dev mistake then all the linters will pick it up and there will be N comments on the PR. So I think it should probably stop on the first linter to fail. |
Sounds good.
No. I intended it not to.
But that is a good point. Maybe I can push a build error to see, but you're probably right, and then I agree it should abort on first linter. |
3b4e79a
to
2b57193
Compare
Done:
Unfortunately: I just noticed that it seems the golangci-lint executions always takes about the same time now, like 1 minute or so, even when it reports it found a cache - in which case it previously executed like 5 seconds. Probably the changing of GOOS invalidates the cache in the sense that it needs to rebuild regardless. Not sure how easy that is to fix, I fear some custom caching hacks is needed, like completely disabling the automatic caching from both setup-go and golangci-lint-action and adding an explicit cache action step for each of the golangci-lint-action steps. The alternative is to run without cache, just disable it if it is true it does not have any real effect, and accept it being a bit slow as long as it is not limiting the entire build. Would be unfortunate, but exactly how much and how acceptable that would be I don't know? I will investigate this cache topic later, like tomorrow. |
f795392
to
6115dcf
Compare
… Go 1.18: Use SyscallN instead.
5985a60
to
bc05614
Compare
bc05614
to
b1e07c9
Compare
I think I've solved the last caching issue of the lint job. To test I manually deleted relevant caches, and forced a build which did the entire lint job in about 6m (1m35s on each lint step), which includes saving a new cache. Then forced another build, and the entire lint job now took 46s (2s on each lint step). I think the current solution should be solid. Note that there may be some strange effects as long as this PR does the lint job differently than master and other PRs, because they may generate same cache keys and end up reusing each others caches, with unexpected content. @ncw Let me know what you think of it now. |
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 perfect now - thank you for all your hard work on this.
Please merge :-)
What is the purpose of this change?
Fixes the following issues from running golangci-lint on Windows, as well as a couple of more:
Was the change discussed in an issue or in the forum before?
Checklist