-
Notifications
You must be signed in to change notification settings - Fork 3
448 lines (407 loc) · 18.8 KB
/
cloud-e2e-api.yml
File metadata and controls
448 lines (407 loc) · 18.8 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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
name: Cloud E2E API
on:
workflow_dispatch:
inputs:
TEST_TYPE:
description: "The type of API will be tested (e.g. openapi-test|adminapi-test)"
type: string
required: false
default: 'openapi-test|adminapi-test'
CLOUD_ENV_NAME:
description: "The cloud env name of test (e.g. dev) "
type: string
required: false
default: 'dev'
CLOUD_BRANCH:
description: "The cloud branch name (e.g. main) "
type: string
required: false
default: 'main'
APECD_REF:
description: "The branch name of apecloud-cd"
type: string
required: false
default: 'main'
CURRENT_VERSION:
description: "The current release version (e.g. v0.30) "
type: string
required: false
default: ''
workflow_call:
inputs:
TEST_TYPE:
description: "The type of API will be tested (e.g. openapi-test|adminapi-test)"
type: string
required: false
default: 'openapi-test|adminapi-test'
CLOUD_ENV_NAME:
description: "The cloud env name of test (e.g. dev) "
type: string
required: false
default: 'dev'
CLOUD_BRANCH:
description: "The cloud branch name (e.g. main) "
type: string
required: false
default: 'main'
APECD_REF:
description: "The branch name of apecloud-cd"
type: string
required: false
default: 'main'
CURRENT_VERSION:
description: "The current release version (e.g. v0.30) "
type: string
required: false
default: ''
run-name: Cloud E2E API Test on Env:${{ inputs.CLOUD_ENV_NAME }} ${{ inputs.TEST_TYPE }} Ref:${{ inputs.CLOUD_BRANCH }}
env:
ACK_KUBECONFIG_DEV: ${{ secrets.ACK_KUBECONFIG_DEV }}
ACK_KUBECONFIG_DEMO: ${{ secrets.ACK_KUBECONFIG_DEMO }}
IDC_KUBECONFIG: ${{ secrets.IDC_KUBECONFIG }}
IDC_KUBECONFIG_1: ${{ secrets.IDC_KUBECONFIG_1 }}
IDC_KUBECONFIG_2: ${{ secrets.IDC_KUBECONFIG_2 }}
IDC_KUBECONFIG_4: ${{ secrets.IDC_KUBECONFIG_4 }}
ACK_KUBECONFIG_PROD: ${{ secrets.ACK_KUBECONFIG_PROD }}
ACK_KUBECONFIG_INTL_PROD: ${{ secrets.ACK_KUBECONFIG_INTL_PROD }}
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
jobs:
get-test-type:
runs-on: ubuntu-latest
outputs:
test-type: ${{ steps.get_test_type.outputs.test-type }}
cloud-branch: ${{ steps.get_test_type.outputs.cloud-branch }}
cloud-env-name: ${{ steps.get_test_type.outputs.cloud-env-name }}
steps:
- name: Get test type
id: get_test_type
run: |
TEST_TYPES="${{ inputs.TEST_TYPE }}"
test_type=""
for test_type_tmp in $(echo "${TEST_TYPES}" | sed 's/|/ /g' ); do
if [[ -z "${test_type}" ]]; then
test_type="{\"test-type\":\"${test_type_tmp}\"}"
else
test_type="${test_type},{\"test-type\":\"${test_type_tmp}\"}"
fi
done
echo "${test_type}"
echo "test-type={\"include\":[${test_type}]}" >> $GITHUB_OUTPUT
CLOUD_BRANCH="${{ inputs.CLOUD_BRANCH }}"
if [[ -z "$CLOUD_BRANCH" ]]; then
CLOUD_BRANCH="main"
fi
echo cloud-branch="$CLOUD_BRANCH" >> $GITHUB_OUTPUT
CLOUD_ENV_NAME="${{ inputs.CLOUD_ENV_NAME }}"
if [[ -z "$CLOUD_ENV_NAME" ]]; then
CLOUD_ENV_NAME="dev"
fi
echo cloud-env-name="$CLOUD_ENV_NAME" >> $GITHUB_OUTPUT
e2e-api-test:
needs: [ get-test-type ]
name: ${{ matrix.test-type }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.get-test-type.outputs.test-type) }}
outputs:
openapi-test-result: ${{ steps.get_test_result.outputs.openapi-test-result }}
adminapi-test-result: ${{ steps.get_test_result.outputs.adminapi-test-result }}
test-result: ${{ steps.get_test_result.outputs.test-result }}
openapi-summary: ${{ steps.get_test_result.outputs.openapi-summary }}
adminapi-summary: ${{ steps.get_test_result.outputs.adminapi-summary }}
api-summary: ${{ steps.get_test_result.outputs.api-summary }}
test-date: ${{ steps.upload_test_result.outputs.test-date }}
runs-on: ubuntu-latest
steps:
- name: Checkout testinfra Code
uses: actions/checkout@v4
with:
repository: apecloud/testinfra
path: ./
token: ${{ env.GH_TOKEN }}
- name: Checkout apecloud-cd Code
uses: actions/checkout@v4
with:
repository: apecloud/apecloud-cd
path: ./apecloud-cd
ref: ${{ inputs.APECD_REF }}
- name: Checkout apecloud Code
uses: actions/checkout@v4
with:
repository: apecloud/apecloud
path: ./apecloud
token: ${{ env.GH_TOKEN }}
ref: "${{ needs.get-test-type.outputs.cloud-branch }}"
fetch-depth: 0
- name: Configure ACK Context ${{ inputs.CLOUD_ENV_NAME }}
id: cloud_env
run: |
mkdir -p $HOME/.kube
touch $HOME/.kube/config
CLOUD_ENV_NAME="${{ inputs.CLOUD_ENV_NAME }}"
if [[ -z "$CLOUD_ENV_NAME" ]]; then
CLOUD_ENV_NAME="dev"
fi
echo CLOUD_ENV_NAME="$CLOUD_ENV_NAME" >> $GITHUB_ENV
E2E_ENV_VARS=""
case "$CLOUD_ENV_NAME" in
dev)
echo '${{ env.ACK_KUBECONFIG_DEV }}' > $HOME/.kube/config
E2E_ENV_VARS="${{ vars.E2E_ENV_VARS_DEV }}"
;;
demo)
echo '${{ env.ACK_KUBECONFIG_DEMO }}' > $HOME/.kube/config
E2E_ENV_VARS="${{ vars.E2E_ENV_VARS_DEMO }}"
;;
idc)
echo '${{ env.IDC_KUBECONFIG }}' > $HOME/.kube/config
E2E_ENV_VARS="${{ vars.E2E_ENV_VARS_IDC }}"
;;
idc1)
echo '${{ env.IDC_KUBECONFIG_1 }}' > $HOME/.kube/config
E2E_ENV_VARS="${{ vars.E2E_ENV_VARS_IDC1 }}"
;;
idc2)
echo '${{ env.IDC_KUBECONFIG_2 }}' > $HOME/.kube/config
E2E_ENV_VARS="${{ vars.E2E_ENV_VARS_IDC2 }}"
;;
idc4)
echo '${{ env.IDC_KUBECONFIG_4 }}' > $HOME/.kube/config
E2E_ENV_VARS="${{ vars.E2E_ENV_VARS_IDC4 }}"
;;
prod)
echo '${{ env.ACK_KUBECONFIG_PROD }}' > $HOME/.kube/config
E2E_ENV_VARS="${{ vars.E2E_ENV_VARS_PROD }}"
;;
intl_prod)
echo '${{ env.ACK_KUBECONFIG_INTL_PROD }}' > $HOME/.kube/config
E2E_ENV_VARS="${{ vars.E2E_ENV_VARS_INTL_PROD }}"
;;
esac
echo E2E_ENV_VARS="$E2E_ENV_VARS" >> $GITHUB_ENV
- name: install python dateutil
run: |
pip3 install python-dateutil
- name: run ${{ matrix.test-type }}
run: |
run_file_log="run_e2e_test_result.log"
touch ${run_file_log}
for env_vars in $(echo "${E2E_ENV_VARS}" | sed 's/|/ /g'); do
eval_cmd="export $env_vars"
echo "$eval_cmd"
eval "$eval_cmd"
done
export KB_CLOUD_TEST_ENGINES="${{ vars.KB_CLOUD_TEST_ENGINES }}"
TEST_TYPE="${{ matrix.test-type }}"
if [[ -z "$TEST_TYPE" ]]; then
TEST_TYPE="openapi-test"
fi
# run cloud e2e test
bash test/cloud/test_cloud_e2e.sh \
--test-type "${TEST_TYPE}" \
--release-version "${{ needs.get-test-type.outputs.cloud-branch }}" | tee -a ${run_file_log}
CLOUD_E2E_TEST_POD_NAME="$(cat ${run_file_log} | (grep '\[CLOUD-E2E-TEST-POD-NAME\]' || true) )"
if [[ -n "${CLOUD_E2E_TEST_POD_NAME}" && "$CLOUD_E2E_TEST_POD_NAME" == "[CLOUD-E2E-TEST-POD-NAME]"* ]]; then
CLOUD_E2E_TEST_POD_NAME=${CLOUD_E2E_TEST_POD_NAME#*"[CLOUD-E2E-TEST-POD-NAME]"}
fi
echo CLOUD_E2E_TEST_POD_NAME="$CLOUD_E2E_TEST_POD_NAME" >> $GITHUB_ENV
- name: Waiting for Cloud E2E to be Completed
run: |
sleep 10
while true; do
if kubectl get pods -n default | grep "${CLOUD_E2E_TEST_POD_NAME}" | egrep "Completed|Error" ; then
echo "Cloud E2E Test is Done"
break
fi
if kubectl get pods -n default | grep "${CLOUD_E2E_TEST_POD_NAME}" | egrep "Running|Error" ; then
kubectl logs -n default ${CLOUD_E2E_TEST_POD_NAME} --tail=5
else
echo "Waiting for Cloud E2E to be Running..."
fi
sleep 1
done
- name: Get Test Result
if: ${{ always() }}
id: get_test_result
run: |
file_log="test_result.log"
test_file_log_path="${{ github.workspace }}/${file_log}"
touch ${test_file_log_path}
kubectl logs -n default ${CLOUD_E2E_TEST_POD_NAME} > ${test_file_log_path}
kubectl delete pod -n default ${CLOUD_E2E_TEST_POD_NAME} --force
cat ${test_file_log_path}
TEST_TYPE="${{ matrix.test-type }}"
if [[ -z "$TEST_TYPE" ]]; then
TEST_TYPE="openapi-test"
fi
test_ret="$( grep "Test Suite Failed" ${test_file_log_path} || true )"
TEST_RESULT_ALL="$(cat ${test_file_log_path} | (egrep 'SUCCESS!|FAIL!' | grep -- '--' || true))"
echo "test result all:${TEST_RESULT_ALL}"
TEST_RESULT_ALL=$(python3 ${{ github.workspace }}/apecloud-cd/.github/utils/remove_ansi.py --ansi-str "$TEST_RESULT_ALL")
test_result=$(bash ${{ github.workspace }}/apecloud-cd/.github/utils/utils.sh --type 41 --test-result "${TEST_RESULT_ALL}")
echo "test result total:${test_result}"
if [[ -z "$test_result" ]]; then
test_result="$(cat ${test_file_log_path} | (egrep 'SUCCESS!|FAIL!' | grep -- '--' || true) | tail -n 1)"
test_result=$(python3 ${{ github.workspace }}/apecloud-cd/.github/utils/remove_ansi.py --ansi-str "$test_result")
fi
if [[ -z "$test_result" ]]; then
test_result="[PASSED]"
if [[ -n "$test_ret" || -z "${TEST_RESULT_ALL}" ]]; then
test_result="[FAILED]"
fi
fi
coverage_file_log="test_api_coverage_result.log"
coverage_file_log_path="${{ github.workspace }}/${coverage_file_log}"
touch ${coverage_file_log_path}
API_COVERAGE_SUMMARY=""
CLOUD_E2E_HACK_DIR="${{ github.workspace }}/apecloud/e2e/hack"
if [[ -d "${CLOUD_E2E_HACK_DIR}" && "${{ needs.get-test-type.outputs.cloud-branch }}" == "main" ]]; then
cd ${CLOUD_E2E_HACK_DIR}
if [[ -f "${CLOUD_E2E_HACK_DIR}/api-coverage.sh" ]]; then
# api coverage summary
API_TYPE="openapi"
if [[ -n "$TEST_TYPE" && "$TEST_TYPE" == "adminapi"* ]]; then
API_TYPE="adminapi"
fi
bash ./api-coverage.sh --type ${API_TYPE} --log ${test_file_log_path} > ${coverage_file_log_path}
API_COVERAGE_SUMMARY=$(cat ${coverage_file_log_path})
TOTAL_APIS=$(echo "${API_COVERAGE_SUMMARY}" | (grep "Total APIs: " || true))
COVERED_APIS=$(echo "${API_COVERAGE_SUMMARY}" | (grep "Covered APIs: " || true))
COVERAGE=$(echo "${API_COVERAGE_SUMMARY}" | (grep "Coverage: " || true))
DEPRECATED_APIS=$(echo "${API_COVERAGE_SUMMARY}" | (grep "Deprecated APIs: " || true))
TOTAL_APIS=$(echo "$TOTAL_APIS" | (grep -oE '[0-9]+' || true))
COVERED_APIS=$(echo "$COVERED_APIS" | (grep -oE '[0-9]+' || true))
COVERAGE=$(echo "$COVERAGE" | (grep -oE '[0-9]+%' || true))
DEPRECATED_APIS=$(echo "$DEPRECATED_APIS" | (grep -oE '[0-9]+' || true))
echo "Total APIs: $TOTAL_APIS"
echo "Covered APIs: $COVERED_APIS"
echo "Coverage: $COVERAGE"
echo "Deprecated APIs: $DEPRECATED_APIS"
API_COVERAGE_SUMMARY="${TOTAL_APIS}|${COVERED_APIS}|${COVERAGE}|${DEPRECATED_APIS}"
fi
fi
case "$TEST_TYPE" in
openapi-test)
echo openapi-test-result="${test_result}" >> $GITHUB_OUTPUT
echo openapi-summary="${API_COVERAGE_SUMMARY}" >> $GITHUB_OUTPUT
if [[ -d "${CLOUD_E2E_HACK_DIR}" ]]; then
file_log_tmp="test_result_tmp.log"
test_file_log_tmp_path="${{ github.workspace }}/${file_log_tmp}"
check_e2e_log="e2e.log"
check_e2e_log_path="${CLOUD_E2E_HACK_DIR}/${check_e2e_log}"
touch ${test_file_log_tmp_path} ${check_e2e_log_path}
E2E_TEST_RESULT_LOG=$(python3 ${{ github.workspace }}/apecloud-cd/.github/utils/remove_ansi_file.py ${test_file_log_path})
echo "${E2E_TEST_RESULT_LOG}" > ${test_file_log_tmp_path}
cp -r ${test_file_log_tmp_path} ${check_e2e_log_path}
fi
;;
adminapi-test)
echo adminapi-test-result="${test_result}" >> $GITHUB_OUTPUT
echo adminapi-summary="${API_COVERAGE_SUMMARY}" >> $GITHUB_OUTPUT
;;
*)
echo test-result="${test_result}" >> $GITHUB_OUTPUT
echo api-summary="${API_COVERAGE_SUMMARY}" >> $GITHUB_OUTPUT
;;
esac
if [[ -n "$test_ret" ]]; then
exit 1
fi
- name: Get ${{ matrix.test-type }} API Coverage List
if: ${{ always() }}
run: |
coverage_file_log="test_api_coverage_result.log"
coverage_file_log_path="${{ github.workspace }}/${coverage_file_log}"
if [[ -f ${coverage_file_log_path} ]]; then
cat ${coverage_file_log_path}
fi
- name: Check e2e log and create issue
if: ${{ always() && matrix.test-type == 'openapi-test' }}
run: |
CLOUD_E2E_HACK_DIR="${{ github.workspace }}/apecloud/e2e/hack"
if [[ -d "${CLOUD_E2E_HACK_DIR}" && -f "${CLOUD_E2E_HACK_DIR}/log-checker.sh" ]]; then
CI_JOB_URL=$(bash ${{ github.workspace }}/apecloud-cd/.github/utils/utils.sh \
--type 44 \
--github-repo "${{ github.repository }}" \
--github-token "${{ env.GH_TOKEN }}" \
--run-id "$GITHUB_RUN_ID" \
--test-result "openapi-test-dev")
echo ${CI_JOB_URL}
export CI_JOB_URL="${CI_JOB_URL}"
cd ${CLOUD_E2E_HACK_DIR}
check_e2e_log="e2e.log"
check_e2e_log_path="${CLOUD_E2E_HACK_DIR}/${check_e2e_log}"
bash ./log-checker.sh
fi
send-message:
needs: [ get-test-type, e2e-api-test ]
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Checkout apecloud-cd Code
uses: actions/checkout@v4
with:
repository: apecloud/apecloud-cd
ref: ${{ inputs.APECD_REF }}
- name: send test result message
run: |
CLOUD_BRANCH="${{ needs.get-test-type.outputs.cloud-branch }}"
CLOUD_ENV_NAME="${{ needs.get-test-type.outputs.cloud-env-name }}"
TEST_RESULT=""
API_COVERAGE_SUMMARY=""
TEST_TYPES="${{ inputs.TEST_TYPE }}"
for test_type_tmp in $(echo "${TEST_TYPES}" | sed 's/|/ /g' ); do
case "$test_type_tmp" in
openapi-test)
TEST_RESULT="${TEST_RESULT}##${test_type_tmp}|${{ needs.e2e-api-test.outputs.openapi-test-result }}"
if [[ -n "${{ needs.e2e-api-test.outputs.openapi-summary }}" ]]; then
API_COVERAGE_SUMMARY="${API_COVERAGE_SUMMARY}##openapi|${{ needs.e2e-api-test.outputs.openapi-summary }}"
fi
;;
adminapi-test)
TEST_RESULT="${TEST_RESULT}##${test_type_tmp}|${{ needs.e2e-api-test.outputs.adminapi-test-result }}"
if [[ -n "${{ needs.e2e-api-test.outputs.adminapi-summary }}" ]]; then
API_COVERAGE_SUMMARY="${API_COVERAGE_SUMMARY}##adminapi|${{ needs.e2e-api-test.outputs.adminapi-summary }}"
fi
;;
*)
TEST_RESULT="${TEST_RESULT}##${test_type_tmp}|${{ needs.e2e-api-test.outputs.test-result }}"
if [[ -n "${{ needs.e2e-api-test.outputs.api-summary }}" ]]; then
API_COVERAGE_SUMMARY="${API_COVERAGE_SUMMARY}##api|${{ needs.e2e-api-test.outputs.api-summary }}"
fi
;;
esac
done
echo "TEST_RESULT:${TEST_RESULT}"
TEST_RESULT=$( bash .github/utils/utils.sh --type 40 \
--github-repo "${{ github.repository }}" \
--github-token "${{ env.GH_TOKEN }}" \
--test-result "${TEST_RESULT}" \
--run-id "$GITHUB_RUN_ID" )
echo "TEST_RESULT:${TEST_RESULT}"
export TZ='Asia/Shanghai'
date_ret=$(date +%Y-%m-%d-%T)
TEST_TITLE="[${CLOUD_BRANCH}][${CLOUD_ENV_NAME}] Cloud E2E API Test [${date_ret}]"
python3 .github/utils/send_mesage.py \
--send-type ginkgo \
--url "${{ vars.CLOUD_E2E_BOT_WEBHOOK }}" \
--title "$TEST_TITLE" \
--result "$TEST_RESULT"
TEST_TITLE_SUMMARY="[${CLOUD_BRANCH}][${CLOUD_ENV_NAME}] Cloud E2E API Coverage Summary [${date_ret}]"
if [[ -n "${API_COVERAGE_SUMMARY}" && "${{ needs.get-test-type.outputs.cloud-branch }}" == "main" ]]; then
echo "API_COVERAGE_SUMMARY:${API_COVERAGE_SUMMARY}"
API_COVERAGE_SUMMARY_TMP="$(bash .github/utils/utils.sh \
--type 42 \
--test-result "${TEST_RESULT}" \
--coverage-result "${API_COVERAGE_SUMMARY}")"
echo "API_COVERAGE_SUMMARY:${API_COVERAGE_SUMMARY_TMP}"
python3 .github/utils/send_mesage.py \
--send-type summary \
--url "${{ vars.CLOUD_E2E_BOT_WEBHOOK }}" \
--title "$TEST_TITLE_SUMMARY" \
--result "$API_COVERAGE_SUMMARY_TMP"
fi