-
Notifications
You must be signed in to change notification settings - Fork 77
248 lines (224 loc) · 7.16 KB
/
lint-golang.yaml
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
name: Auto Golang Lint And Unittest
on:
pull_request: {}
push:
branches:
- main
- release-*
workflow_dispatch:
inputs:
ref:
description: 'branch, sha, tag'
required: true
default: main
workflow_call:
inputs:
ref:
required: true
type: string
permissions: write-all
# concurrency:
# group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
# cancel-in-progress: true
jobs:
filter_changes:
name: Deduce required tests from code changes
runs-on: ubuntu-latest
outputs:
check: ${{ steps.result.outputs.check }}
ref: ${{ steps.result.outputs.ref }}
steps:
- name: Check Go Code Changes
uses: dorny/[email protected]
if: ${{ github.event_name == 'pull_request' }}
id: filter_pr
with:
base: ${{ github.event.pull_request.base.sha }}
ref: ${{ github.event.pull_request.head.sha }}
filters: |
src:
- .github/workflows/lint-golang.yaml
- '**/*.go'
- 'go.mod'
- 'go.sum'
- 'api/**/openapi.yaml'
- 'charts/**/crds/*.yaml'
- name: Result
id: result
run: |
if ${{ github.event_name == 'push' }} ; then
echo "trigger by push"
echo "::set-output name=check::true"
echo "::set-output name=ref::${{ github.sha }}"
elif ${{ github.event_name == 'pull_request' }} ; then
echo "trigger by pull_request"
flag=${{ steps.filter_pr.outputs.src }}
echo "::set-output name=check::${flag}"
ref=${{ github.event.pull_request.head.sha }}
echo "::set-output name=ref::${ref}"
elif ${{ inputs.ref != '' }} ; then
echo "trigger by workflow_call"
echo "::set-output name=check::true"
echo "::set-output name=ref::${{ inputs.ref }}"
elif ${{ github.event_name == 'workflow_dispatch' }} ; then
echo "trigger by workflow_dispatch"
echo "::set-output name=check::true"
echo "::set-output name=ref::${{ github.event.inputs.ref }}"
else
echo "error, unexpected event "
exit 1
fi
lint-golang:
needs: filter_changes
if: ${{ needs.filter_changes.outputs.check == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.21.4
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ needs.filter_changes.outputs.ref }}
- name: Check module vendoring
run: |
go mod tidy
go mod vendor
if ! test -z "$(git status --porcelain)"; then
echo "please run 'go mod tidy && go mod vendor', and submit your changes"
exit 1
fi
# ================ lint
- name: Run golangci-lint
id: golangci_lint
continue-on-error: true
uses: golangci/golangci-lint-action@v3
with:
version: latest
- name: Check Make lint-golang
id: lintgolang
continue-on-error: true
run: |
make lint-golang
- name: Check TODO Comment
id: comment
continue-on-error: true
run: |
tools/scripts/todocover.sh "check"
- name: Result
run: |
result=${{ steps.golangci_lint.outcome }}
[ "${result}"x == "failure"x ] && echo "step golangci_lint failed" && exit 1
result=${{ steps.lintgolang.outcome }}
[ "${result}"x == "failure"x ] && echo "step lint-golang failed" && exit 2
result=${{ steps.comment.outcome }}
[ "${result}"x == "failure"x ] && echo "step comment failed" && exit 3
echo "all succeed"
exit 0
lint_SDK_and_build:
needs: filter_changes
if: ${{ needs.filter_changes.outputs.check == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.21.4
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ needs.filter_changes.outputs.ref }}
- name: Check SDK
run: |
flag=""
echo "Check Openapi yaml"
if make openapi-validate-spec ; then
echo " pass openapi yaml "
else
echo "error, failed to check openapi yaml "
flag="bad"
fi
echo "Check Openapi SDK"
if make openapi-verify ; then
echo " pass openapi sdk check"
else
echo "error, failed to check openapi sdk "
flag="bad"
fi
echo "Check Kubebuilder SDK and chart"
if make manifests-verify ; then
echo " pass Kubebuilder SDK and yaml"
else
echo "error, failed to check Kubebuilder SDK and yaml"
flag="bad"
fi
echo "Check Code-generator SDK"
if make codegen-verify ; then
echo " pass Code-generator SDK"
else
echo "error, failed to check Code-generator SDK"
flag="bad"
fi
[ -n "$flag" ] && exit 1
exit 0
- name: Build Lint
run: |
make build-bin
unittest:
needs: filter_changes
if: ${{ needs.filter_changes.outputs.check == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.21.4
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ needs.filter_changes.outputs.ref }}
# unittest and e2e, _test.go
- name: Check label of All test go
run: |
make check_test_label
# ================= unittest
- name: Run unittest
id: unittest
continue-on-error: true
run: |
make unittest-tests
- name: Upload Coverage Artifact
if: ${{ steps.unittest.outcome == 'failure' }}
uses: actions/[email protected]
with:
name: coverage.out
path: coverage.out
retention-days: 1
- name: Upload Report Artifact
if: ${{ steps.unittest.outcome == 'failure' }}
uses: actions/[email protected]
with:
name: unittestreport.json
path: unittestreport.json
retention-days: 1
# ============= upload coverage report
- name: Upload to Codecov
if: ${{ steps.unittest.outcome != 'failure' }}
uses: codecov/codecov-action@v4
with:
directory: './'
files: 'coverage.out'
flags: unittests
name: my-codecov-umbrella
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Result
if: ${{ steps.unittest.outcome == 'failure' }}
run: |
echo "unittest failed"
exit 1