-
Notifications
You must be signed in to change notification settings - Fork 10
209 lines (196 loc) · 8.18 KB
/
cypress.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
name: Cypress Tests
on:
workflow_dispatch:
push:
branches:
- alpha
- beta
- stable
env:
# These two are just for internal use, to wire the container network
MRBEAM_PLUGIN_URL: "http://plugin-address.org:5002/"
MRBEAM_PLUGIN_DOMAIN_NAME: "plugin-address.org"
JIRA_PROJECT_KEY: "SW"
XRAY_JUNIT_IMPORT: "https://xray.cloud.getxray.app/api/v2/import/execution/junit"
TEST_PLAN_KEY: "SW-2354"
jobs:
mrb-docker:
runs-on: ubuntu-latest
outputs:
domain: ${{ env.MRBEAM_PLUGIN_DOMAIN_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and export
uses: docker/build-push-action@v3
with:
push: false
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
file: ./Dockerfile
tags: mrbeam_plugin:latest
outputs: type=docker,dest=/tmp/image.tar
- name: Upload MrBeamPlugin image
uses: actions/upload-artifact@v3
with:
name: mrbeam_plugin
path: /tmp/image.tar
ui-chrome-tests:
runs-on: ubuntu-latest
permissions: write-all
container:
image: cypress/browsers:node16.17.0-chrome106
options: --add-host=${{ needs.mrb-docker.outputs.domain }}:host-gateway
# This is necessary to use the docker daemon from the GitHub actions virtual machine
volumes:
- /var/run/docker.sock:/var/run/docker.sock
needs: mrb-docker
strategy:
fail-fast: false
matrix:
# run copies of the current job in parallel
containers: [ 0, 1, 2, 3, 4 ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download MrBeamPlugin image
uses: actions/download-artifact@v3
with:
name: mrbeam_plugin
path: /tmp
- name: Load Docker image
run: |
apt-get --allow-releaseinfo-change update
apt-get install docker.io -y
docker load --input /tmp/image.tar
docker run --name mrbeam-plugin -d -p5002:5000 mrbeam_plugin
- env:
CYPRESS_TEST_USER_EMAIL: ${{ secrets.CYPRESS_TEST_USER_EMAIL }}
CYPRESS_TEST_USER_PASSWORD: ${{ secrets.CYPRESS_TEST_USER_PASSWORD }}
CYPRESS_TEST_DESIGN_STORE_TOKEN: ${{ secrets.CYPRESS_TEST_DESIGN_STORE_TOKEN }}
run: |
envsubst < ./cypress/fixtures/test-data.template.json > ./cypress/fixtures/test-data.json
envsubst < ./cypress.config-template.js > ./cypress.config.js
- name: Run Cypress e2e - Chrome
uses: cypress-io/github-action@v4
with:
wait-on: ${{ env.MRBEAM_PLUGIN_URL }}
browser: chrome
config-file: cypress.config.js
command: yarn ts-node cypress/scripts/cypress-ci-run.ts
env:
TOTAL_RUNNERS: 5
THIS_RUNNER: ${{ matrix.containers }}
# Recommended: pass the GitHub token lets this action correctly
# determine the unique run id necessary to re-run the checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload JUnit reports
if: always()
uses: actions/upload-artifact@v3
with:
name: report_${{ matrix.containers }}
path: cypress/results
- name: Upload Cypress screenshots
if: always()
uses: actions/upload-artifact@v3
with:
name: screenshots_${{ matrix.containers }}
path: cypress/screenshots
xray-import:
runs-on: ubuntu-latest
needs: ui-chrome-tests
if: always()
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Download JUnit reports
uses: actions/download-artifact@v3
with:
path: cypress/results
- name: Display structure of downloaded files
run: ls -R
working-directory: cypress/results
- name: Merge reports
run: |
npm install --only=dev
npm run merge-reports
- name: Import to Xray
id: xray
run: |
token=$(curl -H "Content-Type: application/json" -X POST --data '{ "client_id": "${{ secrets.JIRA_CLIENT_ID }}","client_secret": "${{ secrets.JIRA_CLIENT_SECRET }}" }' https://xray.cloud.getxray.app/api/v2/authenticate| tr -d '"')
xray_import_response=$(curl -H "Content-Type: text/xml" -X POST -H "Authorization: Bearer $token" --data @"cypress/results/combined.xml" ${{ env.XRAY_JUNIT_IMPORT }}?projectKey=${{ env.JIRA_PROJECT_KEY }}&testPlanKey=${{ env.TEST_PLAN_KEY }})
echo "xray_import_response=$xray_import_response" >> $GITHUB_OUTPUT
- name: Change test execution issue details
id: issue-details
# test_exec_id: extracts the newly created test execution issue url from the previous response
# test_exec_summary: contains the latest commit message. Should be something like "SW-1234 summary"
# tested_issue_id: extracts the "SW-1234" from the commit message, to add it as a link to the text execution issue
# tested_issue_assignee: extracts the accountId of the assignee of the tested ticket
# tested_issue_fix_version: extracts the fixVersion of the tested ticket
run: |
test_exec_url=$(printf '%s\n' '${{ steps.xray.outputs.xray_import_response }}' | jq -r .self)
echo $test_exec_url
echo "test_exec_url=$test_exec_url" >> $GITHUB_OUTPUT
last_commit_message=$(echo $(git log -1 --pretty=format:"%s"))
test_exec_summary=$(echo "Test execution for $last_commit_message" | tr \" " ")
echo $test_exec_summary
tested_issue_id=$(echo $last_commit_message | sed -E -e 's/.*(SW-[0-9]+).*/\1/g')
echo $tested_issue_id
tested_issue_details=$(curl -u ${{ secrets.JIRA_SW_EMAIL }}:${{ secrets.JIRA_SW_API_TOKEN }} -X GET 'https://mr-beam.atlassian.net/rest/api/2/issue/'$tested_issue_id )
tested_issue_assignee=$(printf '%s' $tested_issue_details | jq --raw-output .fields.assignee.accountId)
echo $tested_issue_assignee
tested_issue_fix_version=$(printf '%s' $tested_issue_details | jq -r .fields.fixVersions[].name)
echo $tested_issue_fix_version
echo "tested_issue_fix_version=$tested_issue_fix_version" >> $GITHUB_OUTPUT
curl -D- -u ${{ secrets.JIRA_SW_EMAIL }}:${{ secrets.JIRA_SW_API_TOKEN }} \
-X PUT $test_exec_url -H 'Content-Type: application/json' \
--data \
'{
"fields": {
"summary": "[GitHub:Cypress] '"$test_exec_summary"'",
"assignee": { "accountId": "'"$tested_issue_assignee"'" }
},
"update": {
"issuelinks": [
{
"add": {
"type": {
"name":"Test",
"outward":"tests"
},
"outwardIssue": {
"key": "'"$tested_issue_id"'"
}
}
}
]
}
}'
- name: Add fix version if available
continue-on-error: true
if: ${{ steps.issue-details.outputs.tested_issue_fix_version }}
run: |
curl -D- -u ${{ secrets.JIRA_SW_EMAIL }}:${{ secrets.JIRA_SW_API_TOKEN }} \
-X PUT ${{ steps.issue-details.outputs.test_exec_url }} -H 'Content-Type: application/json' \
--data \
'{
"update": {
"fixVersions": [
{
"add": {"name": "'"${{ steps.issue-details.outputs.tested_issue_fix_version }}"'"}
}
]
}
}'
- name: Move test execution to done
# 21 is the id for the status "Done"
run: |
curl -D- -u ${{ secrets.JIRA_SW_EMAIL }}:${{ secrets.JIRA_SW_API_TOKEN }} \
-X POST ${{ steps.issue-details.outputs.test_exec_url }}'/transitions' -H 'Content-Type: application/json' \
--data '{ "transition": { "id": "21" } }'