Giter Club home page Giter Club logo

golangci-lint-action's Introduction

golangci-lint-action

Build Status

It's the official GitHub action for golangci-lint from it's authors. The action runs golangci-lint and reports issues from linters.

GitHub Annotations

How to use

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

name: golangci-lint
on:
  push:
    tags:
      - v*
    branches:
      - master
  pull_request:
jobs:
  golangci:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: golangci-lint
        uses: golangci/golangci-lint-action@v1
        with:
          # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
          version: v1.26
          
          # Optional: working directory, useful for monorepos
          # working-directory: somedir

          # Optional: golangci-lint command line arguments.
          # args: --issues-exit-code=0

          # Optional: show only new issues if it's a pull request. The default value is `false`.
          # only-new-issues: true

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

Comments and Annotations

Currently, GitHub parses the action's output and creates annotations.

The restrictions of annotations are the following:

  1. Currently, they don't support markdown formatting (see the feature request)
  2. They aren't shown in list of comments like it was with golangci.com. If you would like to have comments - please, up-vote the issue.

Performance

The action was implemented with performance in mind:

  1. We cache data by @actions/cache between builds: Go build cache, Go modules cache, 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, go and golangci-lint binary in parallel.

For example, in a repository of golangci-lint running this action without the cache takes 50s, but with cache takes 14s:

  • in parallel:
    • 13s to download Go
    • 4s to restore 50 MB of cache
    • 1s to find and install golangci-lint
  • 1s to run golangci-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

Inside our action we perform 3 steps:

  1. Setup environment running in parallel:
  1. Run golangci-lint with specified by user args
  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 like golangci-lint.cache-{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 use restore keys: golangci-lint.cache-{interval_number}-, golangci-lint.cache-. 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. Install act
  2. Make a symlink for act to work properly: ln -s . golangci-lint-action
  3. Prepare deps once: npm run prepare-deps
  4. Run npm run local after any change to test it

golangci-lint-action's People

Contributors

dependabot[bot] avatar ernado avatar jirfag avatar jwilner avatar rx14 avatar sayboras avatar svilgelm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.