|
1 | 1 | # golangci-lint-action
|
2 | 2 |
|
3 |
| - |
| 3 | +[](https://github.com/golangci/golangci-lint-action/actions) |
4 | 4 |
|
5 |
| -Action that runs [golangci-lint](https://github.com/golangci/golangci-lint) and reports issues from linters. |
| 5 | + |
| 6 | + |
| 7 | +The action that runs [golangci-lint](https://github.com/golangci/golangci-lint) and reports issues from linters. |
| 8 | + |
| 9 | +## How to use |
| 10 | + |
| 11 | +1. Create a [GitHub token](https://github.com/settings/tokens/new) with scope `repo.public_repo`. |
| 12 | +2. Add it to a [repository secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets): repository -> `Settings` -> `Secrets`. |
| 13 | +3. Add `.github/workflows/golangci-lint.yml` with the following contents: |
6 | 14 |
|
7 |
| -You can put `.github/workflows/lint.yml` with following contents: |
8 | 15 | ```yaml
|
9 |
| -name: golangci |
10 |
| -on: [push] |
| 16 | +name: golangci-lint |
| 17 | +on: |
| 18 | + push: |
| 19 | + tags: |
| 20 | + - v* |
| 21 | + branches: |
| 22 | + - master |
| 23 | + pull_request: |
11 | 24 | jobs:
|
12 | 25 | golangci:
|
13 | 26 | name: lint
|
14 | 27 | runs-on: ubuntu-latest
|
15 | 28 | steps:
|
16 |
| - - name: Check out code into the Go module directory |
17 |
| - uses: actions/checkout@v1 |
| 29 | + - uses: actions/checkout@v2 |
18 | 30 | - name: golangci-lint
|
19 |
| - |
| 31 | + uses: golangci/golangci-lint-action@v1 |
| 32 | + with: |
| 33 | + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. |
| 34 | + version: v1.26 |
| 35 | + |
| 36 | + # Optional: golangci-lint command line arguments. |
| 37 | + # args: ./the-only-dir-to-analyze/... |
| 38 | + |
| 39 | + # Required: GitHub token with scope `repo.public_repo`. Used for fetching a list of releases of golangci-lint. |
| 40 | + github-token: ${{ secrets.GOLANGCI_LINT_GITHUB_TOKEN }} |
20 | 41 | ```
|
21 | 42 |
|
22 |
| -Based on [reviewdog action](https://github.com/reviewdog/action-golangci-lint). |
| 43 | +## Comments and Annotations |
| 44 | +
|
| 45 | +Currently, GitHub parses the action's output and creates [annotations](https://github.community/t5/GitHub-Actions/What-are-annotations/td-p/30770). |
| 46 | +
|
| 47 | +The restrictions of annotations are the following: |
| 48 | +
|
| 49 | +1. Currently, they don't support markdown formatting (see the [feature request](https://github.community/t5/GitHub-API-Development-and/Checks-Ability-to-include-Markdown-in-line-annotations/m-p/56704)) |
| 50 | +2. They aren't shown in list of comments like it was with [golangci.com](https://golangci.com). If you would like to have comments - please, up-vote [the issue](https://github.com/golangci/golangci-lint-action/issues/5). |
| 51 | +
|
| 52 | +## Internals |
| 53 | +
|
| 54 | +We use JavaScript-based action. We don't use Docker-based action because: |
| 55 | +
|
| 56 | +1. docker pulling is slow currently |
| 57 | +2. it's easier to use caching from [@actions/cache](https://github.com/actions/cache) until GitHub team hasn't supported reusing actions from actions |
| 58 | +
|
| 59 | +Inside our action we perform 3 steps: |
| 60 | +
|
| 61 | +1. Setup environment running in parallel: |
| 62 | + * restore [cache](https://github.com/actions/cache) of previous analyzes into `$HOME/.cache/golangci-lint` |
| 63 | + * list [releases of golangci-lint](https://github.com/golangci/golangci-lint/releases) and find the latest patch version |
| 64 | + for needed version (users of this action can specify only minor version). After that install [golangci-lint](https://github.com/golangci/golangci-lint) using [@actions/tool-cache](https://github.com/actions/toolkit/tree/master/packages/tool-cache) |
| 65 | + * install the latest Go 1.x version using [@actions/setup-go](https://github.com/actions/setup-go) |
| 66 | +2. Run `golangci-lint` with specified by user `args` |
| 67 | +3. Save cache from `$HOME/.cache/golangci-lint` for later builds |
| 68 | + |
| 69 | +## Development of this action |
| 70 | + |
| 71 | +1. Install [act](https://github.com/nektos/act#installation) |
| 72 | +2. Make a symlink for `act` to work properly: `ln -s . golangci-lint-action` |
| 73 | +3. Get a [GitHub token](https://github.com/settings/tokens/new) with the scope `repo.public_repo`. Export it by `export GITHUB_TOKEN=YOUR_TOKEN`. |
| 74 | +4. Prepare deps once: `npm run prepare-deps` |
| 75 | +5. Run `npm run local` after any change to test it |
0 commit comments