Skip to content

Commit b030249

Browse files
authored
Merge pull request #4 from golangci/feature/reimplement
reimplement github action in typescript
2 parents 666cc91 + 853ade0 commit b030249

22 files changed

+67641
-49
lines changed

.eslintrc.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"env": { "node": true, "jest": true },
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": { "ecmaVersion": 2020, "sourceType": "module" },
5+
"extends": [
6+
"eslint:recommended",
7+
"plugin:@typescript-eslint/eslint-recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
"plugin:import/errors",
10+
"plugin:import/warnings",
11+
"plugin:import/typescript",
12+
"plugin:prettier/recommended",
13+
"prettier/@typescript-eslint"
14+
],
15+
"plugins": ["@typescript-eslint", "simple-import-sort"],
16+
"rules": {
17+
"import/first": "error",
18+
"import/newline-after-import": "error",
19+
"import/no-duplicates": "error",
20+
"simple-import-sort/sort": "error",
21+
"sort-imports": "off"
22+
}
23+
}

.github/workflows/dockerimage.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/golangci.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "build-test"
2+
on: # rebuild any PRs and main branch changes
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- 'releases/*'
8+
9+
jobs:
10+
build: # make sure build/ci work properly
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
- run: |
15+
npm install
16+
npm run prepare-deps
17+
npm run all
18+
git diff && git diff --cached
19+
test: # make sure the action works on a clean machine without building
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v1
23+
- uses: ./
24+
with:
25+
version: v1.26
26+
args: --issues-exit-code=0 ./sample/...
27+
github-token: ${{ secrets.GOLANGCI_LINT_GITHUB_TOKEN }}

.gitignore

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# symlink for `act`
2+
/golangci-lint-action
3+
4+
__tests__/runner/*
5+
6+
node_modules/
7+
lib/
8+
9+
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
10+
# Logs
11+
logs
12+
*.log
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
lerna-debug.log*
17+
18+
# Diagnostic reports (https://nodejs.org/api/report.html)
19+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
20+
21+
# Runtime data
22+
pids
23+
*.pid
24+
*.seed
25+
*.pid.lock
26+
27+
# Directory for instrumented libs generated by jscoverage/JSCover
28+
lib-cov
29+
30+
# Coverage directory used by tools like istanbul
31+
coverage
32+
*.lcov
33+
34+
# nyc test coverage
35+
.nyc_output
36+
37+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
38+
.grunt
39+
40+
# Bower dependency directory (https://bower.io/)
41+
bower_components
42+
43+
# node-waf configuration
44+
.lock-wscript
45+
46+
# Compiled binary addons (https://nodejs.org/api/addons.html)
47+
build/Release
48+
49+
# Dependency directories
50+
jspm_packages/
51+
52+
# TypeScript v1 declaration files
53+
typings/
54+
55+
# TypeScript cache
56+
*.tsbuildinfo
57+
58+
# Optional npm cache directory
59+
.npm
60+
61+
# Optional eslint cache
62+
.eslintcache
63+
64+
# Optional REPL history
65+
.node_repl_history
66+
67+
# Output of 'npm pack'
68+
*.tgz
69+
70+
# Yarn Integrity file
71+
.yarn-integrity
72+
73+
# dotenv environment variables file
74+
.env
75+
.env.test
76+
77+
# parcel-bundler cache (https://parceljs.org/)
78+
.cache
79+
80+
# next.js build output
81+
.next
82+
83+
# nuxt.js build output
84+
.nuxt
85+
86+
# vuepress build output
87+
.vuepress/dist
88+
89+
# Serverless directories
90+
.serverless/
91+
92+
# FuseBox cache
93+
.fusebox/
94+
95+
# DynamoDB Local files
96+
.dynamodb/
97+
98+
# Text editor files
99+
.vscode/

.prettierrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"endOfLine": "lf",
3+
"semi": false,
4+
"singleQuote": false,
5+
"tabWidth": 2,
6+
"trailingComma": "es5",
7+
"printWidth": 140,
8+
"parser": "typescript"
9+
}

README.md

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,75 @@
11
# golangci-lint-action
22

3-
![docker image](https://github.com/golangci/golangci-lint-action/workflows/docker%20image/badge.svg)
3+
[![Build Status](https://github.com/golangci/golangci-lint-action/workflows/test/badge.svg)](https://github.com/golangci/golangci-lint-action/actions)
44

5-
Action that runs [golangci-lint](https://github.com/golangci/golangci-lint) and reports issues from linters.
5+
![GitHub Annotations](./static/annotations.png)
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:
614

7-
You can put `.github/workflows/lint.yml` with following contents:
815
```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:
1124
jobs:
1225
golangci:
1326
name: lint
1427
runs-on: ubuntu-latest
1528
steps:
16-
- name: Check out code into the Go module directory
17-
uses: actions/checkout@v1
29+
- uses: actions/checkout@v2
1830
- name: golangci-lint
19-
uses: golangci/[email protected]
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 }}
2041
```
2142
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

action.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@ name: 'Run golangci-lint'
33
description: 'Run golangci-lint (WIP)'
44
author: 'golangci'
55
inputs:
6-
github_token:
7-
description: 'GITHUB_TOKEN'
8-
required: false
9-
flags:
10-
description: 'GolangCI command line flags'
11-
required: false
12-
directory:
13-
description: 'Working directory'
14-
required: false
6+
version:
7+
description: 'version of golangci-lint to use in form of v1.2.3'
8+
required: true
9+
args:
10+
description: 'golangci-lint command line arguments'
1511
default: ''
16-
format:
17-
description: 'Output format of issues'
18-
default: 'github-actions'
1912
required: false
20-
13+
github-token:
14+
description: 'GitHub token with scope `repo.public_repo`. Used for fetching a list of releases of golangci-lint.'
15+
required: true
2116

2217
runs:
23-
using: 'docker'
24-
image: 'Dockerfile'
18+
using: 'node12'
19+
main: 'dist/run/index.js'
20+
post: 'dist/post_run/index.js'
2521
branding:
2622
icon: 'check-circle'
2723
color: 'blue'

dist/matchers.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "golangci-lint-action",
5+
"pattern": [
6+
{
7+
"regexp": "^\\s*(\\.{0,2}[\\/\\\\].+\\.go):(?:(\\d+):(\\d+):)? (.*)",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"message": 4
12+
}
13+
]
14+
}
15+
]
16+
}

0 commit comments

Comments
 (0)