-
Notifications
You must be signed in to change notification settings - Fork 196
150 lines (121 loc) · 5.37 KB
/
sdk-e2e-test.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
name: SDK E2E test
on:
workflow_dispatch:
schedule:
- cron: "0 5 * * *"
push:
branches:
- renovate/**
jobs:
setup:
runs-on: ubuntu-latest
permissions:
actions: read
env:
SDK_INTEGRATION_TEST_SQL: ${{ secrets.SDK_INTEGRATION_TEST_SQL }}
SDK_INTEGRATION_TEST_ACCOUNT: ${{ secrets.SDK_INTEGRATION_TEST_ACCOUNT }}
SDK_INTEGRATION_TEST_AAD: ${{ secrets.SDK_INTEGRATION_TEST_AAD }}
SDK_INTEGRATION_TEST_API_CERTPROVIDER: ${{ secrets.SDK_INTEGRATION_TEST_API_CERTPROVIDER }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: setup project
uses: ./.github/actions/setup-project
- name: setup python
uses: actions/setup-python@v3
- name: install xq
run: |
pip install yq
- name: run test - node
if: ${{ always() }}
working-directory: packages/sdk
run: |
npm run test:e2e:node
- name: run test - browser
if: ${{ always() }}
working-directory: packages/sdk
run: |
npm run test:e2e:browser
- name: get job id
id: get-job-id
if: ${{ always() }}
uses: ayachensiyuan/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
job-name: "setup"
- name: List jobs
if: ${{ always() }}
id: list-jobs
working-directory: packages/sdk
run: |
lists=""
total_node=`cat test-results.node.xml | xq '.testsuite| ."@tests"' | sed -e 's/"//g'`
total_browser=`cat test-results.browser.xml | xq '.testsuite| ."@tests"' | sed -e 's/"//g'`
total=$((total_node+total_browser))
error_node=`cat test-results.node.xml | xq '.testsuite| ."@errors"' | sed -e 's/"//g'`
error_browser=`cat test-results.browser.xml | xq '.testsuite| ."@errors"' | sed -e 's/"//g'`
failed=$((error_node+error_browser))
passed=$((total-failed))
emails="[email protected]"
case_node=`cat test-results.node.xml | xq '.testsuite | .testcase'`
case_browser=`cat test-results.browser.xml | xq '.testsuite | .testcase'`
for case in $(jq --slurp 'add' <(echo "$case_node ") <(echo "$case_browser") | jq -r '.[] | @base64'); do
_jq() {
echo "${case}" | base64 --decode | jq -r "${1}"
}
if [ -z "$case" ]; then
continue
fi
suite=$(_jq '."@classname"' | sed -e 's/"/\\"/g')
name=$(_jq '."@name"' | sed -e 's/"/\\"/g')
duration=$(_jq '."@time"'| sed -e 's/"/\\"/g')
failure=$(_jq '.failure'| sed -e 's/"/\\"/g')
email="[email protected]"
author="<a href=\\\"mailto:$email\\\"><span>$email</span></a>"
label=""
if [ "$failure" == "null" ]; then
label="<span style=\\\"background-color:#2aa198;color:white;font-weight:bold;\\\">PASSED</span>"
else
label="<span style=\\\"background-color:#dc322f;color:white;font-weight:bold;\\\">FAILED</span>"
fi
if [[ ! -z "$email" && ! "$emails" == *"$email"* && "$failure" ]]; then
emails="$emails;$email"
fi
row="<tr> <td style=\\\"text-align: left;\\\">$suite</td> <td style=\\\"text-align: left;\\\">$name</td> <td style=\\\"text-align: center;\\\">$label</td> <td style=\\\"text-align: center;\\\">$author</td> <td>$duration sec</td> </tr>"
if [[ -z "$failure" ]]; then
lists="$lists $row"
else
lists="$row $lists"
fi
done
body="<table class=\\\"w3-table w3-striped w3-bordered\\\"> <tr> <th>Suite</th> <th>Case</th> <th>Status</th> <th>Author</th> <th>Duration</th> </tr> $lists </table> <br /> The detail can be found here: <a> https://github.com/OfficeDev/TeamsFx/actions/runs/${{ github.run_id }}</a>"
subject="SDK E2E Test Report ($passed/$total Passed)"
if [ $failed -gt 0 ]; then
subject="[FAILED] $subject"
else
subject="[PASSED] $subject"
fi
echo "body=$body" >> $GITHUB_OUTPUT
echo "to=$emails" >> $GITHUB_OUTPUT
echo "subject=$subject" >> $GITHUB_OUTPUT
- name: Rerun
if: ${{ github.event_name == 'schedule' && failure() && github.run_attempt < 5 }}
run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/rerun.yml/dispatches \
-d '{"ref":"${{ github.ref_name }}","inputs":{"run_id":"${{ github.run_id }}", "max_attempts":"5"}}'
- name: Report result
if: ${{ github.event_name == 'schedule' && (success() || (failure() && github.run_attempt >= 5)) }}
uses: ./.github/actions/send-email-report
env:
TO: ${{ steps.list-jobs.outputs.to }}
BODY: '"${{ steps.list-jobs.outputs.body }}"'
SUBJECT: ${{ steps.list-jobs.outputs.subject }}
MAIL_CLIENT_ID: ${{ secrets.TEST_CLEAN_CLIENT_ID }}
MAIL_CLIENT_SECRET: ${{ secrets.TEST_CLEAN_CLIENT_SECRET }}
MAIL_TENANT_ID: ${{ secrets.TEST_CLEAN_TENANT_ID }}