-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (49 loc) · 1.17 KB
/
pre-commit.yml
File metadata and controls
56 lines (49 loc) · 1.17 KB
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
name: pre-commit
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- "v[0-9]+*"
workflow_dispatch:
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: "."
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
cache: true
- name: Run gofmt
run: |
if [ -n "$(gofmt -l .)" ]; then
echo "Go code is not formatted. Run 'gofmt -w .' to fix."
gofmt -d .
exit 1
fi
- name: Run go vet
run: go vet ./...
- name: Run go mod verify
run: go mod verify
- name: Run go mod tidy check
run: |
go mod tidy
# Check if go.mod has changed (go.sum may not exist if no dependencies)
if ! git diff --exit-code go.mod; then
echo "go.mod is not tidy. Run 'go mod tidy' to fix."
exit 1
fi
# Check go.sum only if it exists
if [ -f go.sum ]; then
if ! git diff --exit-code go.sum; then
echo "go.sum is not tidy. Run 'go mod tidy' to fix."
exit 1
fi
fi