forked from spidernet-io/spiderpool
-
Notifications
You must be signed in to change notification settings - Fork 0
266 lines (250 loc) · 10.4 KB
/
auto-pr-ci.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
name: Auto PR E2E CI
permissions: write-all
on:
pull_request_target:
types:
- opened
- synchronize
- reopened
workflow_dispatch:
inputs:
ref:
description: 'sha, tag, branch'
required: true
default: main
e2e_labels:
description: 'e2e labels(if not set, ginkgo will run all test, multi labels separated by commas)'
required: false
type: string
ipfamily:
description: 'IP family for the e2e test'
required: true
type: choice
default: 'dual'
options:
- ipv4
- ipv6
- dual
- all
jobs:
get_ref:
runs-on: ubuntu-latest
outputs:
ref: ${{ env.RUN_REF }}
e2e_labels: ${{ env.RUN_E2E_LABELS }}
unittest_enabled: ${{ env.RUN_UNITTEST_ENABLED }}
e2e_enabled: ${{ env.RUN_E2E_ENABLED }}
ipfamily_ipv4only_e2e: ${{ env.RUN_E2E_IPV4_ONLY }}
ipfamily_ipv6only_e2e: ${{ env.RUN_E2E_IPV6_ONLY }}
ipfamily_dual_e2e: ${{ env.RUN_E2E_DUAL_STACK }}
steps:
- name: Check Code Changes
uses: dorny/[email protected]
if: ${{ github.event_name == 'pull_request_target' }}
id: filter_pr
with:
base: ${{ github.event.pull_request.base.sha }}
ref: ${{ github.event.pull_request.head.sha }}
filters: |
run_e2e:
- '**/*.sh'
- '**/*.go'
- 'go.mod'
- 'go.sum'
- 'charts/**'
- 'Makefile*'
- '**/Makefile*'
- '**/Dockerfile'
all_e2e:
- 'test/**'
- 'vendor/github.com/spidernet-io/**/*.go'
- name: Get Ref
id: get_ref
run: |
if ${{ github.event_name == 'workflow_dispatch' }} ; then
echo "call by self workflow_dispatch"
echo "RUN_UNITTEST_ENABLED=true" >> $GITHUB_ENV
echo "RUN_E2E_ENABLED=true" >> $GITHUB_ENV
echo "RUN_E2E_LABELS=${{ github.event.inputs.e2e_labels }}" >> $GITHUB_ENV
echo "RUN_TAG=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
if ${{ github.event.inputs.ipfamily == 'ipv4' }}; then
echo "RUN_E2E_IPV4_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=false" >> $GITHUB_ENV
elif ${{ github.event.inputs.ipfamily == 'ipv6' }}; then
echo "RUN_E2E_IPV4_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=false" >> $GITHUB_ENV
elif ${{ github.event.inputs.ipfamily == 'dual' }}; then
echo "RUN_E2E_IPV4_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=true" >> $GITHUB_ENV
elif ${{ github.event.inputs.ipfamily == 'all' }}; then
echo "RUN_E2E_IPV4_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=true" >> $GITHUB_ENV
else
echo "error, unknown input ipfamily: ${{ github.event.inputs.ipfamily }} "
exit 1
fi
elif ${{ github.event_name == 'push' }} ; then
echo "trigger by push"
echo "RUN_TAG=${{ github.sha }}" >> $GITHUB_ENV
echo "RUN_E2E_LABELS=smoke" >> $GITHUB_ENV
echo "RUN_E2E_ENABLED=true" >> $GITHUB_ENV
# do it in another workflow
echo "RUN_UNITTEST_ENABLED=false" >> $GITHUB_ENV
echo "RUN_E2E_IPV4_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=true" >> $GITHUB_ENV
elif ${{ github.event_name == 'pull_request_target' }} ; then
echo "trigger by pull_request_target"
echo "RUN_TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
if ${{ steps.filter_pr.outputs.all_e2e == 'true' }} ; then
# run all e2e
echo "RUN_E2E_LABEL=" >> $GITHUB_ENV
echo "RUN_E2E_IPV4_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=true" >> $GITHUB_ENV
else
echo "RUN_E2E_LABEL=smoke" >> $GITHUB_ENV
echo "RUN_E2E_IPV4_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=true" >> $GITHUB_ENV
fi
echo "RUN_E2E_ENABLED=${{ steps.filter_pr.outputs.run_e2e }}" >> $GITHUB_ENV
# do it in another workflow
echo "RUN_UNITTEST_ENABLED=false" >> $GITHUB_ENV
else
# call by auto-nightly-ci, the event is schedule or its workflow_dispatch
# use main sha for ci image tag
echo "trigger by workflow_call"
echo "RUN_TAG=main" >> $GITHUB_ENV
echo "RUN_E2E_LABEL=" >> $GITHUB_ENV
echo "RUN_E2E_ENABLED=true" >> $GITHUB_ENV
echo "RUN_UNITTEST_ENABLED=true" >> $GITHUB_ENV
if ${{ inputs.ipfamily == 'ipv4' }}; then
echo "RUN_E2E_IPV4_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=false" >> $GITHUB_ENV
elif ${{ inputs.ipfamily == 'ipv6' }}; then
echo "RUN_E2E_IPV4_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=false" >> $GITHUB_ENV
elif ${{ inputs.ipfamily == 'dual' }}; then
echo "RUN_E2E_IPV4_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=false" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=true" >> $GITHUB_ENV
elif ${{ inputs.ipfamily == 'all' }}; then
echo "RUN_E2E_IPV4_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=true" >> $GITHUB_ENV
else
echo "RUN_E2E_IPV4_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_IPV6_ONLY=true" >> $GITHUB_ENV
echo "RUN_E2E_DUAL_STACK=true" >> $GITHUB_ENV
fi
fi
# some event, the tag is not sha, so checkout it and get sha
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ env.RUN_TAG }}
- name: Result Ref
id: result
run: |
ref=$( git show -s --format='format:%H')
echo "RUN_REF=${ref}" >> $GITHUB_ENV
call_unittest:
needs: get_ref
if: ${{ needs.get_ref.outputs.unittest_enabled == 'true' }}
# forbid to specify version for local workflow, GITHUB_REF Same as the caller workflow
uses: ./.github/workflows/lint-golang.yaml
with:
ref: ${{ needs.get_ref.outputs.ref }}
secrets: inherit
call_build_ci_image:
needs: [get_ref]
if: ${{ needs.get_ref.outputs.e2e_enabled == 'true' }}
# get image:${{ needs.get_ref.outputs.ref }} and image-ci:${{ needs.get_ref.outputs.ref }}
uses: ./.github/workflows/build-image-ci.yaml
with:
ref: ${{ needs.get_ref.outputs.ref }}
push: false
secrets: inherit
lint_chart_against_release_image:
needs: get_ref
if: ${{ needs.get_ref.outputs.e2e_enabled == 'true' }}
# forbid to specify version for local workflow, GITHUB_REF Same as the caller workflow
uses: ./.github/workflows/call-lint-chart.yaml
with:
ref: ${{ needs.get_ref.outputs.ref }}
secrets: inherit
call_release_chart:
needs: [get_ref]
if: ${{ needs.get_ref.outputs.e2e_enabled == 'true' }}
uses: ./.github/workflows/call-release-chart.yaml
with:
ref: ${{ needs.get_ref.outputs.ref }}
submit: false
secrets: inherit
trivy_scan_images:
needs: [call_build_ci_image, get_ref, call_release_chart]
uses: ./.github/workflows/trivy-scan-image.yaml
with:
image_tag: ${{ needs.call_build_ci_image.outputs.imageTag }}
ref: ${{ needs.get_ref.outputs.ref }}
secrets: inherit
e2e_dual_latest:
needs: [call_build_ci_image, get_ref, call_release_chart]
if: ${{ needs.get_ref.outputs.e2e_enabled == 'true' && needs.get_ref.outputs.ipfamily_dual_e2e == 'true' }}
uses: ./.github/workflows/e2e-init.yaml
with:
ip_family: dual
image_tag: ${{ needs.call_build_ci_image.outputs.imageTag }}
ref: ${{ needs.get_ref.outputs.ref }}
e2e_labels: ${{ needs.get_ref.outputs.e2e_labels }}
secrets: inherit
e2e_ipv4_latest:
needs: [call_build_ci_image, get_ref, call_release_chart]
if: ${{ needs.get_ref.outputs.e2e_enabled == 'true' && needs.get_ref.outputs.ipfamily_ipv4only_e2e == 'true' }}
uses: ./.github/workflows/e2e-init.yaml
with:
ip_family: ipv4
image_tag: ${{ needs.call_build_ci_image.outputs.imageTag }}
ref: ${{ needs.get_ref.outputs.ref }}
e2e_labels: ${{ needs.get_ref.outputs.e2e_labels }}
secrets: inherit
e2e_ipv6_latest:
needs: [call_build_ci_image, get_ref, call_release_chart]
if: ${{ needs.get_ref.outputs.e2e_enabled == 'true' && needs.get_ref.outputs.ipfamily_ipv6only_e2e == 'true' }}
uses: ./.github/workflows/e2e-init.yaml
with:
ip_family: ipv6
image_tag: ${{ needs.call_build_ci_image.outputs.imageTag }}
ref: ${{ needs.get_ref.outputs.ref }}
e2e_labels: ${{ needs.get_ref.outputs.e2e_labels }}
secrets: inherit
e2e_dual_ubuntu_20:
needs: [call_build_ci_image, get_ref, call_release_chart]
if: ${{ needs.get_ref.outputs.e2e_enabled == 'true' && needs.get_ref.outputs.ipfamily_dual_e2e == 'true' }}
uses: ./.github/workflows/e2e-init.yaml
with:
os: ubuntu-20.04
ip_family: dual
image_tag: ${{ needs.call_build_ci_image.outputs.imageTag }}
ref: ${{ needs.get_ref.outputs.ref }}
e2e_labels: ${{ needs.get_ref.outputs.e2e_labels }}
secrets: inherit
e2e_dual_k8s_12:
needs: [call_build_ci_image, get_ref, call_release_chart]
if: ${{ needs.get_ref.outputs.e2e_enabled == 'true' && needs.get_ref.outputs.ipfamily_dual_e2e == 'true' }}
uses: ./.github/workflows/e2e-init.yaml
with:
ip_family: dual
image_tag: ${{ needs.call_build_ci_image.outputs.imageTag }}
ref: ${{ needs.get_ref.outputs.ref }}
e2e_labels: ${{ needs.get_ref.outputs.e2e_labels }}
k8s_version: v1.27.1
secrets: inherit