Skip to content

Commit 5f8a852

Browse files
authored
feat: move test reports (#1106)
1 parent d38f0f0 commit 5f8a852

File tree

1 file changed

+50
-24
lines changed

1 file changed

+50
-24
lines changed

.github/workflows/ci.yml

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ jobs:
3838
name: Playwright Tests
3939
runs-on: ubuntu-latest
4040
permissions:
41-
contents: write
42-
pull-requests: write
43-
pages: write
41+
contents: read
4442

4543
services:
4644
backend:
@@ -82,18 +80,6 @@ jobs:
8280
path: playwright-artifacts
8381
retention-days: 5
8482

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-
9783
- name: Get test results
9884
if: always()
9985
id: test-results
@@ -102,13 +88,13 @@ jobs:
10288
echo "Listing playwright-artifacts directory:"
10389
ls -R playwright-artifacts
10490
105-
if [ -f "playwright-artifacts/test-results.json" ]; then
91+
if [ -f "playwright-artifacts/test-results.json" ]; then
10692
echo "Parsing JSON file:"
10793
total=$(jq '.stats.expected + .stats.unexpected + .stats.skipped' playwright-artifacts/test-results.json)
10894
passed=$(jq '.stats.expected' playwright-artifacts/test-results.json)
10995
failed=$(jq '.stats.unexpected' playwright-artifacts/test-results.json)
11096
skipped=$(jq '.stats.skipped' playwright-artifacts/test-results.json)
111-
97+
11298
echo "Parsed values:"
11399
echo "Total: $total"
114100
echo "Passed: $passed"
@@ -127,19 +113,59 @@ jobs:
127113
echo "failed=$failed" >> $GITHUB_OUTPUT
128114
echo "skipped=$skipped" >> $GITHUB_OUTPUT
129115
116+
deploy_and_update:
117+
name: Deploy and Update PR
118+
needs: e2e_tests
119+
runs-on: ubuntu-latest
120+
if: github.event.pull_request.head.repo.full_name == github.repository
121+
permissions:
122+
contents: write
123+
pages: write
124+
pull-requests: write
125+
126+
steps:
127+
- uses: actions/checkout@v4
128+
129+
- name: Download artifacts
130+
uses: actions/download-artifact@v3
131+
with:
132+
name: playwright-artifacts
133+
path: playwright-artifacts
134+
135+
- name: Setup Pages
136+
uses: actions/configure-pages@v3
137+
138+
- name: Deploy report to GitHub Pages
139+
uses: peaceiris/actions-gh-pages@v3
140+
with:
141+
github_token: ${{ secrets.GITHUB_TOKEN }}
142+
publish_dir: ./playwright-artifacts/playwright-report
143+
destination_dir: ${{ github.event.pull_request.number }}
144+
130145
- name: Update PR description
131-
if: always()
132146
uses: actions/github-script@v6
133147
with:
134148
github-token: ${{secrets.GITHUB_TOKEN}}
135149
script: |
150+
const fs = require('fs');
151+
const testResultsPath = 'playwright-artifacts/test-results.json';
152+
let testResults;
153+
154+
if (fs.existsSync(testResultsPath)) {
155+
const rawData = fs.readFileSync(testResultsPath);
156+
const data = JSON.parse(rawData);
157+
testResults = {
158+
total: data.stats.expected + data.stats.unexpected + data.stats.skipped,
159+
passed: data.stats.expected,
160+
failed: data.stats.unexpected,
161+
skipped: data.stats.skipped
162+
};
163+
} else {
164+
console.log('Test results file not found');
165+
testResults = { total: 0, passed: 0, failed: 0, skipped: 0 };
166+
}
167+
136168
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-
};
143169
const status = testResults.failed > 0 ? '❌ FAILED' : '✅ PASSED';
144170
const statusColor = testResults.failed > 0 ? 'red' : 'green';
145171

0 commit comments

Comments
 (0)