37
37
e2e_tests :
38
38
name : Playwright Tests
39
39
runs-on : ubuntu-latest
40
+ permissions :
41
+ contents : write
42
+ pull-requests : write
43
+ pages : write
40
44
41
45
services :
42
46
backend :
@@ -50,16 +54,144 @@ jobs:
50
54
- uses : actions/checkout@v4
51
55
with :
52
56
fetch-depth : 0
53
- - uses : actions/setup-node@v4
57
+
58
+ - name : Setup Node.js
59
+ uses : actions/setup-node@v4
54
60
with :
55
61
node-version : 18
56
62
cache : npm
57
63
58
64
- name : Install dependencies
59
65
run : npm ci
60
66
61
- - name : Install Plawright deps
67
+ - name : Install Playwright deps
62
68
run : npm run test:e2e:install
63
69
64
70
- name : Run Playwright tests
71
+ id : run_tests
65
72
run : npm run test:e2e
73
+ env :
74
+ CI : true
75
+ PLAYWRIGHT_VIDEO : ' on'
76
+
77
+ - name : Upload Playwright artifacts
78
+ if : always()
79
+ uses : actions/upload-artifact@v3
80
+ with :
81
+ name : playwright-artifacts
82
+ path : playwright-artifacts
83
+ retention-days : 5
84
+
85
+ - name : Setup Pages
86
+ if : always()
87
+ uses : actions/configure-pages@v3
88
+
89
+ - name : Deploy report to GitHub Pages
90
+ if : always()
91
+ uses : peaceiris/actions-gh-pages@v3
92
+ with :
93
+ github_token : ${{ secrets.GITHUB_TOKEN }}
94
+ publish_dir : ./playwright-artifacts/playwright-report
95
+ destination_dir : ${{ github.event.pull_request.number }}
96
+
97
+ - name : Get test results
98
+ if : always()
99
+ id : test-results
100
+ run : |
101
+ echo "Current directory: $(pwd)"
102
+ echo "Listing playwright-artifacts directory:"
103
+ ls -R playwright-artifacts
104
+
105
+ if [ -f "playwright-artifacts/test-results.json" ]; then
106
+ echo "Parsing JSON file:"
107
+ total=$(jq '.stats.expected + .stats.unexpected + .stats.skipped' playwright-artifacts/test-results.json)
108
+ passed=$(jq '.stats.expected' playwright-artifacts/test-results.json)
109
+ failed=$(jq '.stats.unexpected' playwright-artifacts/test-results.json)
110
+ skipped=$(jq '.stats.skipped' playwright-artifacts/test-results.json)
111
+
112
+ echo "Parsed values:"
113
+ echo "Total: $total"
114
+ echo "Passed: $passed"
115
+ echo "Failed: $failed"
116
+ echo "Skipped: $skipped"
117
+ else
118
+ echo "test-results.json file not found"
119
+ total=0
120
+ passed=0
121
+ failed=0
122
+ skipped=0
123
+ fi
124
+
125
+ echo "total=$total" >> $GITHUB_OUTPUT
126
+ echo "passed=$passed" >> $GITHUB_OUTPUT
127
+ echo "failed=$failed" >> $GITHUB_OUTPUT
128
+ echo "skipped=$skipped" >> $GITHUB_OUTPUT
129
+
130
+ - name : Update PR description
131
+ if : always()
132
+ uses : actions/github-script@v6
133
+ with :
134
+ github-token : ${{secrets.GITHUB_TOKEN}}
135
+ script : |
136
+ const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/${context.issue.number}/`;
137
+ const testResults = {
138
+ total: ${{ steps.test-results.outputs.total || 0 }},
139
+ passed: ${{ steps.test-results.outputs.passed || 0 }},
140
+ failed: ${{ steps.test-results.outputs.failed || 0 }},
141
+ skipped: ${{ steps.test-results.outputs.skipped || 0 }}
142
+ };
143
+ const status = testResults.failed > 0 ? '❌ FAILED' : '✅ PASSED';
144
+ const statusColor = testResults.failed > 0 ? 'red' : 'green';
145
+
146
+ const testResultsSection = `## Playwright Test Results
147
+
148
+ **Status**: <span style="color: ${statusColor}; font-weight: bold;">${status}</span>
149
+
150
+ | Total | Passed | Failed | Skipped |
151
+ |-------|--------|--------|---------|
152
+ | ${testResults.total} | ${testResults.passed} | ${testResults.failed} | ${testResults.skipped} |
153
+
154
+ ### 📊 Test Report
155
+
156
+ For detailed results, please check the [Playwright Report](${reportUrl})
157
+
158
+ ### 🎥 Test Recordings
159
+
160
+ Video recordings of failed tests (if any) are available in the report.
161
+
162
+ ---
163
+
164
+ <details>
165
+ <summary>ℹ️ How to use this report</summary>
166
+
167
+ 1. Click on the "Playwright Report" link above to view the full test results.
168
+ 2. In the report, you can see a breakdown of all tests, including any failures.
169
+ 3. For failed tests, you can view screenshots and video recordings to help debug the issues.
170
+ 4. Use the filters in the report to focus on specific test statuses or suites.
171
+
172
+ </details>`;
173
+
174
+ const { data: pullRequest } = await github.rest.pulls.get({
175
+ owner: context.repo.owner,
176
+ repo: context.repo.repo,
177
+ pull_number: context.issue.number,
178
+ });
179
+
180
+ const currentBody = pullRequest.body || '';
181
+ const testResultsRegex = /## Playwright Test Results[\s\S]*?(?=\n## |$)/;
182
+
183
+ let newBody;
184
+ if (testResultsRegex.test(currentBody)) {
185
+ // If the section exists, replace it
186
+ newBody = currentBody.replace(testResultsRegex, testResultsSection);
187
+ } else {
188
+ // If the section doesn't exist, add it to the end
189
+ newBody = currentBody + '\n\n' + testResultsSection;
190
+ }
191
+
192
+ await github.rest.pulls.update({
193
+ owner: context.repo.owner,
194
+ repo: context.repo.repo,
195
+ pull_number: context.issue.number,
196
+ body: newBody,
197
+ });
0 commit comments