golangci-lint
golangci-lint copied to clipboard
Maybe inline diff tool into golangci-lint
Got a few issues that "diff" isn't installed, especially on windows. We can inline it's code into golangci-lint
That would be nice to have for Windows. However, most Windows developers will have Git installed and adding the "[DRIVE]:\program files\git\usr\bin" to your path fixes the problem since Git bundles a version of diff.
I ran into this while trying to fix the Git Diff problem, which was after a few other problems I had with Gitlab CI / CD pipelines. I wrote some Powershell scripts someone can use to automate this process:
installGolangciLint.ps1
Invoke-WebRequest -Uri https://github.com/golangci/golangci-lint/releases/download/v1.23.6/golangci-lint-1.23.6-windows-amd64.zip -OutFile ".\download.zip"
Expand-Archive .\download.zip -DestinationPath .\download -Force
$p = Resolve-Path .\download\golangci-lint-1.23.6-windows-amd64
$Env:Path += ";$p"
[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
installChoco.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
installGitWithChoco.ps1
choco install git -y -params '"/GitAndUnixToolsOnPath"'
# We must make sure the tools directory is added to PATH. By default this is the correct directory
# And although the above command is supposed to add it to Path, without this line golangci-lint fails
$Env:Path += ";C:\Program Files\Git\usr\bin"
[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
I then run the equivalent of golangci-lint run --fix
and that works. Proof of success is in my CI/CD Job's results:
https://gitlab.com/polyapp-open-source/poly/-/jobs/452889033
The full .gitlab-ci.yml file (Ctrl+F for "poly_demo_lint_windows" which has the right Job) can be found here: https://gitlab.com/polyapp-open-source/poly/-/blob/c7075edc23eb93f765391aa4d00d6aec78b4939c/.gitlab-ci.yml
I hope this helps someone else or better yet golangci-lint offers a better installation process (like using chocolatey) for Windows users. My use-case for running golangci-lint on Windows is that my Go code manipulates paths, and therefore I want to run my CI/CD pipelines on Windows. I also want to support Windows servers for deployment of my app, and this 'proves' the app works the same there as on Linux.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Since it's on the front page of Google, it's a good place to share my experience with https://golangci-lint.run/usage/faq/#how-to-integrate-golangci-lint-into-large-project-with-thousands-of-issues .
Sometimes the command
golangci-lint run --new-from-rev=master
crashes inside the Gitlab CI with the error
level=warning msg="[runner] Can't process result by diff processor: can't prepare diff by revgrep: could not read git repo: error executing git diff \"master\" \"\": exit status 128"
The reason is that GitLab only checkout commits without downloading branches. In order to use the master, you need to download it explicitly
git fetch origin master && git branch master remotes/origin/master