-
Notifications
You must be signed in to change notification settings - Fork 109
108 lines (100 loc) · 2.95 KB
/
go-validate.yml
File metadata and controls
108 lines (100 loc) · 2.95 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
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
---
# This workflow runs basic linting and formatting checks.
name: Go Validate
on:
push:
branches:
- main
pull_request:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
check-mod-tidy:
runs-on: ubuntu-latest
name: Go Mod Tidy Check
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Run go mod tidy
run: go mod tidy
- name: Verify go.mod/go.sum are tidy
shell: bash
run: |
if ! git diff --exit-code; then
echo "go.mod/go.sum are not tidy."
echo "Run: go mod tidy"
exit 1
fi
check-lint:
runs-on: ubuntu-latest
name: Go Lint Check
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
with:
version: latest
only-new-issues: true
check-fmt:
runs-on: ubuntu-latest
name: Go Format Check
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Run gofmt
shell: bash
run: |
files="$(gofmt -l .)"
if [[ -n "$files" ]]; then
echo "Found files that are not gofmt'ed:"
echo "$files"
echo
echo "Run: gofmt -w ."
exit 1
fi
check-generate:
runs-on: ubuntu-latest
name: Go Generate Check
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Run make generate
run: |
export PATH=$PATH:$(go env GOPATH)/bin
make generate
uncommitted="$(git status -s)"
if [[ -z "$uncommitted" ]]; then
echo "OK"
else
echo "Generated files have changed but are not committed."
echo "Run: make generate"
echo "Generated but uncommitted files:"
echo "$uncommitted"
exit 1
fi