Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Official GitHub Action for golangci-lint from its authors

License

NotificationsYou must be signed in to change notification settings

figma/actions-golangci-lint-action

 
 

Repository files navigation

Build Status

It's the official GitHub action forgolangci-lint from its authors.

The action runsgolangci-lint and reports issues from linters.

GitHub Annotations

Logs

Supporting Us

Open Collective backers and sponsorsLinter Authors

golangci-lint is a free and open-source project built by volunteers.

If you value it, consider supporting us, we appreciate it! ❤️

How to use

We recommend running this action in a job separate from other jobs (go test, etc.)because different jobsrun in parallel.

Add.github/workflows/golangci-lint.yml with the following contents:

Simple Example
name:golangci-linton:push:branches:      -main      -masterpull_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@v4      -uses:actions/setup-go@v5with:go-version:stable      -name:golangci-lintuses:golangci/golangci-lint-action@v7with:version:v2.0
Multiple OS Example
name:golangci-linton:push:branches:      -main      -masterpull_request:permissions:contents:read# Optional: allow read access to pull request. Use with `only-new-issues` option.# pull-requests: readjobs:golangci:strategy:matrix:go:[stable]os:[ubuntu-latest, macos-latest, windows-latest]name:lintruns-on:${{ matrix.os }}steps:      -uses:actions/checkout@v4      -uses:actions/setup-go@v5with:go-version:${{ matrix.go }}      -name:golangci-lintuses:golangci/golangci-lint-action@v7with:version:v2.0

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-linton:pull_request:push:branches:      -main      -masterenv:GO_VERSION:stableGOLANGCI_LINT_VERSION:v2.0jobs:detect-modules:runs-on:ubuntu-latestoutputs:modules:${{ steps.set-modules.outputs.modules }}steps:      -uses:actions/checkout@v4      -uses:actions/setup-go@v5with:go-version:${{ env.GO_VERSION }}      -id:set-modulesrun:echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUTgolangci-lint:needs:detect-modulesruns-on:ubuntu-lateststrategy:matrix:modules:${{ fromJSON(needs.detect-modules.outputs.modules) }}steps:      -uses:actions/checkout@v4      -uses:actions/setup-go@v5with:go-version:${{ env.GO_VERSION }}      -name:golangci-lint ${{ matrix.modules }}uses:golangci/golangci-lint-action@v7with:version:${{ env.GOLANGCI_LINT_VERSION }}working-directory:${{ matrix.modules }}
Go Workspace Example (Multiple OS)
# ./.github/workflows/golangci-lint.ymlname:golangci-lint (multi OS)on:pull_request:push:branches:      -main      -masterjobs:golangci-lint:strategy:matrix:go-version:[ stable, oldstable ]os:[ubuntu-latest, macos-latest, windows-latest]uses:./.github/workflows/.golangci-lint-reusable.ymlwith:os:${{ matrix.os }}go-version:${{ matrix.go-version }}golangci-lint-version:v2.0
# ./.github/workflows/.golangci-lint-reusable.ymlname:golangci-lint-reusableon:workflow_call:inputs:os:description:'OS'required:truetype:stringgo-version:description:'Go version'required:truetype:stringdefault:stablegolangci-lint-version:description:'Golangci-lint version'type:stringdefault:'v2.0'jobs:detect-modules:runs-on:${{ inputs.os }}outputs:modules:${{ steps.set-modules.outputs.modules }}steps:      -uses:actions/checkout@v4      -uses:actions/setup-go@v5with:go-version:${{ inputs.go-version }}      -id:set-modulesshell:bash# require for Windows to be able to use $GITHUB_OUTPUT https://github.com/actions/runner/issues/2224run:echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUTgolangci-lint:needs:detect-modulesruns-on:${{ inputs.os }}strategy:matrix:modules:${{ fromJSON(needs.detect-modules.outputs.modules) }}steps:      -uses:actions/checkout@v4      -uses:actions/setup-go@v5with:go-version:${{ inputs.go-version }}      -name:golangci-lint ${{ matrix.modules }}uses:golangci/golangci-lint-action@v7with: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

Compatibility

  • v7.0.0 supports golangci-lint v2 only.
  • 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)

Options

version

(optional)

The version of golangci-lint to use.

Wheninstall-mode is:

  • binary (default): the value can be v2.3 or v2.3.4 orlatest to use the latest version.
  • goinstall: the value can be v2.3.4,latest, or the hash of a commit.
  • none: the value is ignored.
Example
uses:golangci/golangci-lint-action@v7with:version:v2.0# ...

install-mode

(optional)

The mode to install golangci-lint: it can bebinary,goinstall, ornone.

The default value isbinary.

Example
uses:golangci/golangci-lint-action@v7with:install-mode:"goinstall"# ...

github-token

(optional)

When usingonly-new-issues option, the GitHub API is used, so a token is required.

By default, it uses thegithub.token from the action.

Example
uses:golangci/golangci-lint-action@v7with:github-token:xxx# ...

verify

(optional)

This option istrue by default.

If the GitHub Action detects configuration file the validation will be performed unless this option is set tofalse.If there is no configuration file, the validation is skipped.

The JSONSchema used to validate the configuration depends on the version of golangci-lint you are using.

Example
uses:golangci/golangci-lint-action@v7with:verify:false# ...

only-new-issues

(optional)

Show only new issues.

The default value isfalse.

  • pull_request andpull_request_target: the action gets the diff of the PR content from theGitHub 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 theGitHub 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@v7with:only-new-issues:true# ...

working-directory

(optional)

Working directory, useful for monorepos.

Example
uses:golangci/golangci-lint-action@v7with:working-directory:somedir# ...

args

(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@v7with:args:--config=/my/path/.golangci.yml --issues-exit-code=0# ...

problem-matchers

(optional)

Force the usage of the embedded problem matchers.

By default, theproblem matcher of Go (actions/setup-go) already handles the default golangci-lint output (text).

Works only withcolored-line-number (the golangci-lint default).

https://golangci-lint.run/usage/configuration/#output-configuration

The default value isfalse.

Example
uses:golangci/golangci-lint-action@v7with:problem-matchers:true# ...

skip-cache

(optional)

If set totrue, then all caching functionality will be completely disabled,takes precedence over all other caching options.

The default value isfalse.

Example
uses:golangci/golangci-lint-action@v7with:skip-cache:true# ...

skip-save-cache

(optional)

If set totrue, caches will not be saved, but they may still be restored, requiredskip-cache: false.

The default value isfalse.

Example
uses:golangci/golangci-lint-action@v7with:skip-save-cache:true# ...

cache-invalidation-interval

(optional)

Periodically invalidate the cache everycache-invalidation-interval days to ensure that outdated data is removed and fresh data is loaded.

The default value is7.

If set the number is<= 0, the cache will be always invalidate (Not recommended).

Example
uses:golangci/golangci-lint-action@v7with:cache-invalidation-interval:15# ...

Annotations

Currently, GitHub parses the action's output and createsannotations.

The restrictions of annotations are the following:

  1. Currently, they don't support Markdown formatting (see thefeature request)
  2. They aren't shown in the list of comments.If you would like to have comments - please, up-votethe issue.
  3. The number of annotations islimited.

Permissions required:

permissions:# Required: allow read access to the content for analysis.contents:read# Optional: allow read access to pull request. Use with `only-new-issues` option.pull-requests:read

For annotations to work use the default format output (text) and either useactions/setup-go in the job or enable the internalproblem matchers.

Performance

The action was implemented with performance in mind:

  1. We cache data from golangci-lint analysis between builds by using@actions/cache.
  2. We don't use Docker because image pulling is slow.
  3. We do as much as we can in parallel, e.g. we download cache, 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 installgolangci-lint
  • 1s to rungolangci-lint (it takes 35s without cache)

Internals

We use JavaScript-based action.We don't use Docker-based action because:

  1. Docker pulling is slow currently
  2. 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:

  1. Setup environment running in parallel:
  2. Rungolangci-lint with specified by userargs
  3. Save cache for later builds

Caching internals

  1. We save and restore the following directory:~/.cache/golangci-lint.
  2. The primary caching key looks likegolangci-lint.cache-{runner_os}-{working_directory}-{interval_number}-{go.mod_hash}.Interval number ensures that we periodically invalidate our cache (every 7 days).go.mod hash ensures that we invalidate the cache early - as soon as dependencies have changed.
  3. We userestore keys:golangci-lint.cache-{runner_os}-{working_directory}-{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.

About

Official GitHub Action for golangci-lint from its authors

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript97.0%
  • Go3.0%

[8]ページ先頭

©2009-2025 Movatter.jp