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

strantalis/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

Compatibility

  • 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)

How to use

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@v4      -uses:actions/setup-go@v5with:go-version:'1.21'cache:false      -name:golangci-lintuses:golangci/golangci-lint-action@v5with:# 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.57# 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, caches will not be saved, but they may still be restored,#           subject to other options# skip-save-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.

Multiple OS Support

If you need to run linters for specific operating systems, you will need to use the action>=v2. 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@v4      -uses:actions/setup-go@v5with:go-version:${{ matrix.go }}cache:false      -name:golangci-lintuses:golangci/golangci-lint-action@v4with:# 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=lf

Comments and 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 like it was withgolangci.com. If you would like to have comments - please, up-votethe issue.

To enable annotations, you need to add the `checks' permission to your action.

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# Optional: Allow write access to checks to allow the action to annotate code in the PR.checks:write

Performance

The action was implemented with performance in mind:

  1. We cache data by@actions/cache between builds: golangci-lint analysis 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:
  1. Rungolangci-lint with specified by userargs
  2. Save cache for later builds

Caching internals

  1. We save and restore the following directories:~/.cache/golangci-lint,~/.cache/go-build,~/go/pkg.
  2. The primary caching key looks likegolangci-lint.cache-{interval_number}-{go.mod_hash}. Interval number ensures that we periodically invalidateour 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-{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.

Development of this action

  1. Installact
  2. Make a symlink foract to work properly:ln -s . golangci-lint-action
  3. Prepare deps once:npm run prepare-deps
  4. Runnpm run local after any change to test it

About

Official GitHub action for golangci-lint from its authors

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript98.0%
  • Go2.0%

[8]ページ先頭

©2009-2025 Movatter.jp