golangci/golangci-lint-action
Run golangci-lint with line-attached annotations, caching, and only-new-issues PR mode.
What it does
golangci/golangci-lint-action is the official way to run golangci-lint in GitHub Actions. It installs the requested version, runs it with caching, and attaches issues to the changed lines.
On pull requests it can restrict output to newly introduced issues, which makes adopting the linter on an existing codebase practical.
Usage
workflow (.yml)
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- uses: golangci/golangci-lint-action@v9
with:
version: latest
only-new-issues: trueInputs
| Input | Description | Default | Required |
|---|---|---|---|
version | The version of golangci-lint to use, e.g. v2.3, v2.3.4, or latest. | - | No |
only-new-issues | On a pull request, output only newly found issues. | false | No |
working-directory | golangci-lint working directory. The default is the project root. | - | No |
args | golangci-lint command line arguments. | - | No |
install-mode | The mode to install golangci-lint: 'binary', 'goinstall', or 'none'. | binary | No |
verify | Verify the configuration file against the JSONSchema. | true | No |
skip-cache | Completely disable all caching functionality. | false | No |
Notes
Run actions/setup-go before this action, golangci-lint needs a working Go toolchain that matches your module.
Recent majors of the action ship golangci-lint v2; a v1-format .golangci.yml fails the built-in config verification. Migrate the config or pin an older version.
Common errors
- Issues reported by the
typechecklinter mean the code did not compile in CI, usually a Go version mismatch with setup-go or missing module downloads, not a real lint finding. - A config verification failure right at startup means
.golangci.ymldoes not match the JSONSchema for the installed golangci-lint version (commonly a v1 config running under v2). Migrate the config or setverify: falsewhile transitioning.
Security and pinning
- The action only needs
contents: read(plus the default token for PR-patch fetching viagithub-token). Pin to a commit SHA for supply-chain safety.
Alternatives and related
actions/setup-goInstall a specific Go version with module and build caching enabled by default.
super-linter/super-linterOne Docker action that runs a whole collection of linters across every language in the repo.
actions/cacheCache any files between workflow runs, keyed on a hash of your lockfiles.
Frequently asked questions
How do I lint only the code changed in a PR?
Set
only-new-issues: true. The action fetches the PR patch and filters findings to lines introduced by the PR, so pre-existing issues do not block the merge.