-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (183 loc) · 8.44 KB
/
bench-pr-updated-linter.yml
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Benchmark PR (updated linter)
on:
issues:
types:
- labeled
permissions:
issues: write
jobs:
notify-ack:
if: ${{ github.event.label.name == 'bench-updated-linter' }}
runs-on: ubuntu-latest
steps:
- name: Put a reaction
run: |
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}"
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:CONFUSED}){reaction{content}subject{id}}}" | true
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:ROCKET}){reaction{content}subject{id}}}" | true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_ID: ${{ github.event.issue.node_id }}
bench-job:
needs: notify-ack
if: ${{ github.event.label.name == 'bench-updated-linter' }}
runs-on: ubuntu-latest
env:
HYPERFINE_VERSION: 1.18.0
strategy:
matrix:
target:
- org: golangci
repo: golangci-lint
- org: goreleaser
repo: goreleaser
- org: gohugoio
repo: hugo
- org: go-gitea
repo: gitea
- org: rclone
repo: rclone
- org: kubernetes
repo: kubernetes
- org: hashicorp
repo: terraform
- org: hashicorp
repo: consul
- org: etcd-io
repo: etcd
- org: go-acme
repo: lego
- org: traefik
repo: traefik
- org: spf13
repo: cobra
- org: google
repo: go-github
- org: beego
repo: beego
- org: grpc
repo: grpc-go
- org: go-delve
repo: delve
- org: cilium
repo: cilium
# CGO inside
- org: pact-foundation
repo: pact-go
steps:
- name: Hyperfine installation
run: |
wget https://github.com/sharkdp/hyperfine/releases/download/v${HYPERFINE_VERSION}/hyperfine_${HYPERFINE_VERSION}_amd64.deb
sudo dpkg -i hyperfine_${HYPERFINE_VERSION}_amd64.deb
- uses: actions/checkout@v4
with:
repository: 'golangci/golangci-lint'
- uses: actions/setup-go@v5
with:
go-version: stable
- name: Checkout PR
run: gh pr checkout --detach --repo "golangci/golangci-lint" ${{ fromJson(github.event.issue.body).pr }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build golangci-lint from PR
# use `go build` to set ldflags (it reduces some performance differences with binaries created by goreleaser)
run: |
go build -trimpath -ldflags '-s -w' -o golangci-lint ./cmd/golangci-lint
mv ./golangci-lint $(go env GOPATH)/bin/golangci-lint
- name: Install golangci-lint ${{ fromJson(github.event.issue.body).version }}
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "./temp-${GOLANGCI_LINT_VERSION}" "${GOLANGCI_LINT_VERSION}"
mv "temp-${GOLANGCI_LINT_VERSION}/golangci-lint" "$(go env GOPATH)/bin/golangci-lint-${GOLANGCI_LINT_VERSION}"
rm -rf "temp-${GOLANGCI_LINT_VERSION}"
env:
GOLANGCI_LINT_VERSION: ${{ fromJson(github.event.issue.body).version }}
- name: Clone ${{ matrix.target.org }}/${{ matrix.target.repo }}
run: |
git clone -q --depth 1 --single-branch https://github.com/${{ matrix.target.org }}/${{ matrix.target.repo }}.git /tmp/target
cd /tmp/target
go mod tidy
- name: Simple run of golangci-lint on ${{ matrix.target.org }}/${{ matrix.target.repo }} (without cache)
run: |
mkdir -p /tmp/outputs/${REPO}/
cd /tmp/target
golangci-lint cache clean
golangci-lint run -v --issues-exit-code=0 --timeout=20m --show-stats --out-format colored-line-number,line-number:run.txt --enable-only ${LINTER}
echo "## [${ORG}/${REPO}](${{ github.server_url }}/${ORG}/${REPO})" >> ${REPORT_DEST}
echo >> ${REPORT_DEST}
echo '<details>' >> ${REPORT_DEST}
echo >> ${REPORT_DEST}
echo '```' >> ${REPORT_DEST}
cat run.txt >> ${REPORT_DEST}
echo '```' >> ${REPORT_DEST}
echo >> ${REPORT_DEST}
echo '</details>' >> ${REPORT_DEST}
echo >> ${REPORT_DEST}
env:
LINTER: ${{ fromJson(github.event.issue.body).linter }}
ORG: ${{ matrix.target.org }}
REPO: ${{ matrix.target.repo }}
REPORT_DEST: /tmp/outputs/${{ matrix.target.repo }}/perf.md
- name: Run bench on ${{ matrix.target.org }}/${{ matrix.target.repo }} (without cache)
run: |
cd /tmp/target
hyperfine --export-markdown perf.md --warmup 2 \
-n 'local' --prepare 'golangci-lint cache clean' "golangci-lint run --issues-exit-code=0 --timeout=20m --print-issued-lines=false --enable-only ${LINTER}" \
-n "${GOLANGCI_LINT_VERSION}" --prepare "golangci-lint-${GOLANGCI_LINT_VERSION} cache clean" "golangci-lint-${GOLANGCI_LINT_VERSION} run --issues-exit-code 0 --timeout=20m --print-issued-lines=false --enable-only ${LINTER}"
echo >> ${REPORT_DEST}
cat perf.md >> ${REPORT_DEST}
echo >> ${REPORT_DEST}
env:
GOLANGCI_LINT_VERSION: ${{ fromJson(github.event.issue.body).version }}
LINTER: ${{ fromJson(github.event.issue.body).linter }}
REPORT_DEST: /tmp/outputs/${{ matrix.target.repo }}/perf.md
- uses: actions/upload-artifact@v4
with:
name: outputs-${{ matrix.target.repo }}
path: /tmp/outputs/**/perf.md
notify-job-result:
runs-on: ubuntu-latest
needs: bench-job
if: ${{ github.event.label.name == 'bench-updated-linter' && always() }}
steps:
- name: Load outputs
if: ${{ contains(needs.*.result, 'success') }}
uses: actions/download-artifact@v4
with:
pattern: outputs-*
path: /tmp/outputs/
- name: Notify on Success
if: ${{ contains(needs.*.result, 'success') }}
run: |
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:ROCKET}){reaction{content}subject{id}}}"
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:CONFUSED}){reaction{content}subject{id}}}" | true
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" | true
(
echo "The benchmark is done!"
echo
cat /tmp/outputs/**/**/*.md
echo
echo "You can find the workflow here:"
echo "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
) | \
gh issue comment "${ISSUE_NUMBER}" --repo ${{ github.repository }} -F -
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
NODE_ID: ${{ github.event.issue.node_id }}
- name: Notify on Failure
if: ${{ contains(needs.*.result, 'failure') }}
run: |
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:CONFUSED}){reaction{content}subject{id}}}"
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:ROCKET}){reaction{content}subject{id}}}" | true
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" | true
(
echo "**${{ github.workflow }}**"
echo "**Something went wrong!**"
echo
echo "**Details:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
) | \
gh issue comment "${ISSUE_NUMBER}" --repo ${{ github.repository }} -F -
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
NODE_ID: ${{ github.event.issue.node_id }}