It's the official GitHub action for golangci-lint from its authors.
The action runs golangci-lint and reports issues from linters.
golangci-lint
is a free and open-source project built by volunteers.
If you value it, consider supporting us, we appreciate it! ❤️
We recommend running this action in a job separate from other jobs (go test
, etc.)
because different jobs run in parallel.
Add .github/workflows/golangci-lint.yml
with the following contents:
Simple Example
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
Multiple OS Example
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
strategy:
matrix:
go: [stable]
os: [ubuntu-latest, macos-latest, windows-latest]
name: lint
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
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=lf
Go Workspace Example
name: golangci-lint
on:
pull_request:
push:
branches:
- main
- master
env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.60
jobs:
detect-modules:
runs-on: ubuntu-latest
outputs:
modules: ${{ steps.set-modules.outputs.modules }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- id: set-modules
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
golangci-lint:
needs: detect-modules
runs-on: ubuntu-latest
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: golangci-lint ${{ matrix.modules }}
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
working-directory: ${{ matrix.modules }}
Go Workspace Example (Multiple OS)
# ./.github/workflows/golangci-lint.yml
name: golangci-lint (multi OS)
on:
pull_request:
push:
branches:
- main
- master
jobs:
golangci-lint:
strategy:
matrix:
go-version: [ stable, oldstable ]
os: [ubuntu-latest, macos-latest, windows-latest]
uses: ./.github/workflows/.golangci-lint-reusable.yml
with:
os: ${{ matrix.os }}
go-version: ${{ matrix.go-version }}
golangci-lint-version: v1.60
# ./.github/workflows/.golangci-lint-reusable.yml
name: golangci-lint-reusable
on:
workflow_call:
inputs:
os:
description: 'OS'
required: true
type: string
go-version:
description: 'Go version'
required: true
type: string
default: stable
golangci-lint-version:
description: 'Golangci-lint version'
type: string
default: 'v1.60'
jobs:
detect-modules:
runs-on: ${{ inputs.os }}
outputs:
modules: ${{ steps.set-modules.outputs.modules }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- id: set-modules
shell: bash # require for Windows to be able to use $GITHUB_OUTPUT https://github.com/actions/runner/issues/2224
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
golangci-lint:
needs: detect-modules
runs-on: ${{ inputs.os }}
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- name: golangci-lint ${{ matrix.modules }}
uses: golangci/golangci-lint-action@v6
with:
version: ${{ inputs.golangci-lint-version }}
working-directory: ${{ matrix.modules }}
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=lf
v6.0.0+
removesannotations
option, removes the default output format (github-actions
).v5.0.0+
removesskip-pkg-cache
andskip-build-cache
because the cache related to Go itself is already handled byactions/setup-go
.v4.0.0+
requires an explicitactions/setup-go
installation step before using this action:uses: actions/setup-go@v5
. Theskip-go-installation
option has been removed.v2.0.0+
works withgolangci-lint
version >=v1.28.3
v1.2.2
is deprecated due to we forgot to change the minimum version ofgolangci-lint
tov1.28.3
(issue)v1.2.1
works withgolangci-lint
version >=v1.14.0
(issue)
(optional)
The version of golangci-lint to use.
When install-mode
is:
binary
(default): the value can be v1.2 or v1.2.3 orlatest
to use the latest version.goinstall
: the value can be v1.2.3,latest
, or the hash of a commit.none
: the value is ignored.
Example
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
# ...
(optional)
The mode to install golangci-lint: it can be binary
, goinstall
, or none
.
The default value is binary
.
Example
uses: golangci/golangci-lint-action@v6
with:
install-mode: "goinstall"
# ...
(optional)
When using only-new-issues
option, the GitHub API is used, so a token is required.
By default, it uses the github.token
from the action.
Example
uses: golangci/golangci-lint-action@v6
with:
github-token: xxx
# ...
(optional)
Show only new issues.
The default value is false
.
pull_request
andpull_request_target
: the action gets the diff of the PR content from the GitHub API and use it with--new-from-patch
.push
: the action gets the diff of the push content (difference between commits before and after the push) from the GitHub API and use it with--new-from-patch
.merge_group
: the action gets the diff by using--new-from-rev
option (relies on git). You should add the optionfetch-depth: 0
toactions/checkout
step.
Example
uses: golangci/golangci-lint-action@v6
with:
only-new-issues: true
# ...
(optional)
Working directory, useful for monorepos.
Example
uses: golangci/golangci-lint-action@v6
with:
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=
Example
uses: golangci/golangci-lint-action@v6
with:
args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
# ...