-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (108 loc) · 4 KB
/
golangci.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: GolangCI
on:
workflow_call:
inputs:
main_branch:
default: "main"
type: string
go:
type: string
default: "1.17"
jobs:
golangci:
runs-on: ubuntu-latest
steps:
- name: Git - checkout master
uses: actions/checkout@v3
with:
ref: ${{ inputs.main_branch }}
fetch-depth: 1
- name: Git - checkout current ref
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
~\AppData\Local\go-build
~/.cache/golangci-lint
~/Library/Caches/golangci-lint
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download template
run: |
curl 'https://raw.githubusercontent.com/TykTechnologies/github-actions/main/.github/workflows/.golangci.tmpl.yaml' -o .golangci.yaml
- name: Render template
id: render_template
uses: chuhlomin/[email protected]
with:
template: .golangci.yaml
result_path: .golangci.yaml
vars: |
main_branch: ${{ inputs.main_branch }}
goimports: ''
build_tags: []
skip_dirs: []
go_version: ${{ inputs.go }}
- name: Apply template
run: |
cp .golangci.yaml /tmp/.golangci.yaml
if [[ `git status --porcelain` ]]; then
export ref=$(git rev-parse HEAD)
git checkout ${{ inputs.main_branch }}
git pull --rebase
git config --global user.name 'Bender'
git config --global user.email '[email protected]'
git add -A
git commit -a -m 'Update Golangci config'
git push origin ${{ inputs.main_branch }}
git checkout $ref
fi
cp /tmp/.golangci.yaml .golangci.yaml
- uses: actions/setup-go@v3
with:
go-version: ${{ inputs.go }}
- name: Fetch modules
run: |
go mod download
- name: Download golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- name: golangci-lint
if: ${{ github.event_name == 'pull_request' }}
run: |
$(go env GOPATH)/bin/golangci-lint run --verbose --out-format 'checkstyle:golangci_lint.xml' --timeout=300s --max-same-issues 50 --fix --new=true --new-from-rev=origin/${{ github.base_ref }} ./...
- name: golangci-lint
if: ${{ github.event_name == 'push' }}
run: |
$(go env GOPATH)/bin/golangci-lint run --verbose --out-format 'checkstyle:golangci_lint.xml' --timeout=300s --new=false --new-from-rev= ./...
- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: golangci-report
path: "*xml"
- uses: reviewdog/action-setup@v1
if: ${{ always() }}
with:
reviewdog_version: latest # Optional. [latest,nightly,v.X.Y.Z]
- name: Run reviewdog
if: ${{ github.event_name == 'pull_request' }}
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
go install golang.org/x/tools/cmd/goimports@latest
goimports -w .
cat golangci_lint.xml | reviewdog -f=checkstyle -name="Linter" -reporter=github-pr-review
TMPFILE=$(mktemp)
git diff >"${TMPFILE}"
git diff
git status
git stash -u && git stash drop
reviewdog -f=diff -f.diff.strip=1 -name="Linter" -reporter=github-pr-review < "${TMPFILE}"
# cat golangci_lint.xml | reviewdog -f=checkstyle -name="Linter" -reporter=github-pr-check