Skip to content

Commit c444fba

Browse files
committed
Add an action to run a linter over the code
1 parent 571f31c commit c444fba

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/lint.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Lint
2+
on:
3+
push:
4+
paths:
5+
- "**.go"
6+
- go.mod
7+
- go.sum
8+
pull_request:
9+
paths:
10+
- "**.go"
11+
- go.mod
12+
- go.sum
13+
14+
jobs:
15+
lint:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: 1.17
23+
24+
- name: Check out code
25+
uses: actions/checkout@v2
26+
27+
- name: Verify dependencies
28+
run: |
29+
go mod verify
30+
go mod download
31+
32+
LINT_VERSION=1.43.0
33+
curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v${LINT_VERSION}/golangci-lint-${LINT_VERSION}-linux-amd64.tar.gz | \
34+
tar xz --strip-components 1 --wildcards \*/golangci-lint
35+
mkdir -p bin && mv golangci-lint bin/
36+
37+
- name: Run checks
38+
run: |
39+
STATUS=0
40+
assert-nothing-changed() {
41+
local diff
42+
"$@" >/dev/null || return 1
43+
if ! diff="$(git diff -U1 --color --exit-code)"; then
44+
printf '\e[31mError: running `\e[1m%s\e[22m` results in modifications that you must check into version control:\e[0m\n%s\n\n' "$*" "$diff" >&2
45+
git checkout -- .
46+
STATUS=1
47+
fi
48+
}
49+
50+
assert-nothing-changed go fmt ./...
51+
assert-nothing-changed go mod tidy
52+
53+
bin/golangci-lint run --out-format=github-actions --timeout=3m || STATUS=$?
54+
55+
exit $STATUS

0 commit comments

Comments
 (0)