- Notifications
You must be signed in to change notification settings - Fork0
Official GitHub action for golangci-lint from its authors
License
navijation/golangci-lint-action
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
It's the official GitHub action forgolangci-lint from its authors.The action runsgolangci-lint and reports issues from linters.
v3.0.0+requires explicit setup-go installation step prior to using this action:uses: actions/setup-go@v3.Theskip-go-installationoption has been removed.v2.0.0+works withgolangci-lintversion >=v1.28.3v1.2.2is deprecated due to we forgot to change the minimum version ofgolangci-linttov1.28.3(issue)v1.2.1works withgolangci-lintversion >=v1.14.0(issue)
Add.github/workflows/golangci-lint.yml with the following contents:
name:golangci-linton:push:branches: -master -mainpull_request:permissions:contents:read# Optional: allow read access to pull request. Use with `only-new-issues` option.# pull-requests: readjobs:golangci:name:lintruns-on:ubuntu-lateststeps: -uses:actions/checkout@v3 -uses:actions/setup-go@v4with:go-version:'1.21'cache:false -name:golangci-lintuses:golangci/golangci-lint-action@v3with:# Require: The version of golangci-lint to use.# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.version:v1.54# Optional: working directory, useful for monorepos# working-directory: somedir# Optional: golangci-lint command line arguments.## Note: By default, the `.golangci.yml` file should be at the root of the repository.# The location of the configuration file can be changed by using `--config=`# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0# Optional: show only new issues if it's a pull request. The default value is `false`.# only-new-issues: true# Optional: if set to true, then all caching functionality will be completely disabled,# takes precedence over all other caching options.# skip-cache: true# Optional: if set to true, then the action won't cache or restore ~/go/pkg.# skip-pkg-cache: true# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.# skip-build-cache: true# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.# install-mode: "goinstall"
We recommend running this action in a job separate from other jobs (go test, etc)because different jobsrun in parallel.
If you need to run linters for specific operating systems, you will need to usev2 of the action. Here is a sample configuration file:
name:golangci-linton:push:branches: -master -mainpull_request:permissions:contents:read# Optional: allow read access to pull request. Use with `only-new-issues` option.# pull-requests: readjobs:golangci:strategy:matrix:go:['1.21']os:[macos-latest, windows-latest]name:lintruns-on:${{ matrix.os }}steps: -uses:actions/checkout@v3 -uses:actions/setup-go@v4with:go-version:${{ matrix.go }}cache:false -name:golangci-lintuses:golangci/golangci-lint-action@v3with:# Require: The version of golangci-lint to use.# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.version:v1.54# Optional: working directory, useful for monorepos# working-directory: somedir# Optional: golangci-lint command line arguments.## Note: by default the `.golangci.yml` file should be at the root of the repository.# The location of the configuration file can be changed by using `--config=`# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0# Optional: show only new issues if it's a pull request. The default value is `false`.# only-new-issues: true# Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'.# install-mode: "goinstall"
You will also likely need to add the following.gitattributes file to ensure that line endings for windows builds are properly formatted:
*.go text eol=lfCurrently, GitHub parses the action's output and createsannotations.
The restrictions of annotations are the following:
- Currently, they don't support markdown formatting (see thefeature request)
- They aren't shown in list of comments like it was withgolangci.com. If you would like to have comments - please, up-votethe issue.
The action was implemented with performance in mind:
- We cache data by@actions/cache between builds: Go build cache, Go modules cache, golangci-lint analysis cache.
- We don't use Docker because image pulling is slow.
- We do as much as we can in parallel, e.g. we download cache, go and golangci-lint binary in parallel.
For example, in a repository ofgolangci-lint running this action without the cache takes 50s, but with cache takes 14s:
- in parallel:
- 4s to restore 50 MB of cache
- 1s to find and install
golangci-lint
- 1s to run
golangci-lint(it takes 35s without cache)
We use JavaScript-based action. We don't use Docker-based action because:
- docker pulling is slow currently
- it's easier to use caching from@actions/cache
We support different platforms, such asubuntu,macos andwindows withx32 andx64 archs.
Inside our action we perform 3 steps:
- Setup environment running in parallel:
- restorecache of previous analyzes
- fetchaction config and find the latest
golangci-lintpatch versionfor needed version (users of this action can specify only minor version ofgolangci-lint). After that installgolangci-lint using@actions/tool-cache
- Run
golangci-lintwith specified by userargs - Save cache for later builds
- We save and restore the following directories:
~/.cache/golangci-lint,~/.cache/go-build,~/go/pkg. - The primary caching key looks like
golangci-lint.cache-{interval_number}-{go.mod_hash}. Interval number ensures that we periodically invalidateour cache (every 7 days).go.modhash ensures that we invalidate the cache early - as soon as dependencies have changed. - We userestore keys:
golangci-lint.cache-{interval_number}-. GitHub matches keys by prefix if we have no exact match for the primary cache.
This scheme is basic and needs improvements. Pull requests and ideas are welcome.
- Installact
- Make a symlink for
actto work properly:ln -s . golangci-lint-action - Prepare deps once:
npm run prepare-deps - Run
npm run localafter any change to test it
About
Official GitHub action for golangci-lint from its authors
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- TypeScript98.0%
- Go2.0%
