forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 2
214 lines (190 loc) · 8.17 KB
/
static_checks_etc.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
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Static Code Checks, Etc.
on:
- pull_request
- push
jobs:
build:
name: Static Code Checks Etc
runs-on:
group: vitess-ubuntu20
steps:
- name: Check if workflow needs to be skipped
id: skip-workflow
run: |
skip='false'
if [[ "${{github.event.pull_request}}" == "" ]] && [[ "${{github.ref}}" != "refs/heads/main" ]] && [[ ! "${{github.ref}}" =~ ^refs/heads/release-[0-9]+\.[0-9]$ ]] && [[ ! "${{github.ref}}" =~ "refs/tags/.*" ]]; then
skip='true'
fi
echo Skip ${skip}
echo "skip-workflow=${skip}" >> $GITHUB_OUTPUT
- name: Checkout code
if: steps.skip-workflow.outputs.skip-workflow == 'false'
uses: actions/checkout@v3
- name: Run FOSSA scan and upload build data
if: steps.skip-workflow.outputs.skip-workflow == 'false'
uses: fossa-contrib/fossa-action@v1
with:
fossa-api-key: 76d7483ea206d530d9452e44bffe7ba8
- name: Check for changes in Go files
if: steps.skip-workflow.outputs.skip-workflow == 'false'
uses: frouioui/paths-filter@main
id: changes
with:
token: ''
filters: |
go_files:
- '**/*.go'
- '*.go'
- 'go.sum'
- 'go.mod'
parser_changes:
- 'go/vt/sqlparser/**'
- 'go.sum'
- 'go.mod'
- 'build.env'
- 'bootstrap.sh'
- 'tools/**'
- '.github/workflows/static_checks_etc.yml'
proto_changes:
- 'bootstrap.sh'
- 'tools/**'
- 'build.env'
- 'go.sum'
- 'go.mod'
- 'Makefile'
- 'go/vt/proto/**'
- 'proto/*.proto'
- '.github/workflows/static_checks_etc.yml'
sizegen:
- 'go/**/*.go'
- 'test.go'
- 'Makefile'
- 'build.env'
- 'go.sum'
- 'go.mod'
- 'tools/**'
- 'bootstrap.sh'
- '.github/workflows/static_checks_etc.yml'
visitor:
- 'go/tools/asthelpergen/**'
- 'go/vt/sqlparser/**'
- 'Makefile'
- 'build.env'
- 'go.sum'
- 'go.mod'
- 'tools/**'
- 'bootstrap.sh'
- 'misc/git/hooks/asthelpers'
- '.github/workflows/static_checks_etc.yml'
docker:
- 'docker/**'
- 'test.go'
- 'Makefile'
- 'bootstrap.sh'
- '.github/workflows/static_checks_etc.yml'
ci_config:
- 'test/config.json'
- '.github/workflows/static_checks_etc.yml'
release_notes:
- 'changelog/**'
- './go/tools/releases/**'
- name: Set up Go
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.go_files == 'true' || steps.changes.outputs.parser_changes == 'true' || steps.changes.outputs.proto_changes == 'true')
uses: actions/setup-go@v3
with:
go-version: 1.18.7
- name: Get dependencies
if: steps.skip-workflow.outputs.skip-workflow == 'false'
run: |
sudo apt-get update
sudo apt-get install -y make unzip g++ etcd curl git wget
sudo service etcd stop
go mod download
- name: Run make minimaltools
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.parser_changes == 'true' || steps.changes.outputs.proto_changes == 'true'
run: |
make minimaltools
- name: Install golangci-lint
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
- name: Install goimports
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.go_files == 'true' || steps.changes.outputs.visitor == 'true')
run: |
go install golang.org/x/tools/cmd/goimports@latest
## Go files
- name: Run go fmt
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: |
gofmt -l . | grep -vF vendor/ && exit 1 || echo "All files formatted correctly"
- name: Run goimports
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: |
out=$(goimports -local vitess.io/vitess -l -w $(find . -name "*.go" | grep -v ".pb.go"))
echo $out | grep go > /dev/null && echo -e "The following files are malformatted:\n$out" && exit 1 || echo "All the files are formatted correctly"
- name: Clean Env
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: $(go env GOPATH)/bin/golangci-lint cache clean
- name: Print linter version
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: $(go env GOPATH)/bin/golangci-lint --version
- name: Run golangci-lint
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: $(go env GOPATH)/bin/golangci-lint run go/... || exit 1
- name: Run go mod tidy
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: |
set -e
go mod tidy
output=$(git status -s)
if [ -z "${output}" ]; then
exit 0
fi
echo 'We wish to maintain a tidy state for go mod. Please run `go mod tidy` on your branch, commit and push again.'
echo 'Running `go mod tidy` on this CI test yields with the following changes:'
echo "$output"
exit 1
## Parser
- name: check_make_parser
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.parser_changes == 'true' || steps.changes.outputs.go_files == 'true')
run: |
tools/check_make_parser.sh || exit 1
## Sizegen
- name: check_make_sizegen
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.sizegen == 'true' || steps.changes.outputs.go_files == 'true')
run: |
tools/check_make_sizegen.sh || exit 1
## Visitor
- name: check_make_visitor
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.visitor == 'true' || steps.changes.outputs.go_files == 'true')
run: |
misc/git/hooks/asthelpers || exit 1
## Docker
- name: run ensure_bootstrap_version
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
run: |
make ensure_bootstrap_version
git status
test -z "$(git diff-index --name-only HEAD --)" || exit 1
## Proto
- name: check_make_proto
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.proto_changes == 'true'
run: |
tools/check_make_proto.sh || exit 1
- name: Check test/config.json
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.go_files == 'true' || steps.changes.outputs.ci_config == 'true')
run: |
go run ./go/tools/ci-config/main.go || exit 1
- name: Check changelog
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.release_notes == 'true'
run: |
set -e
go run ./go/tools/releases/releases.go
output=$(git status -s)
if [ -z "${output}" ]; then
exit 0
fi
echo 'We wish to maintain a consistent changelog directory, please run `go run ./go/tools/releases/releases.go`, commit and push again.'
echo 'Running `go run ./go/tools/releases/releases.go` on CI yields the following changes:'
echo "$output"
echo ""