Skip to content

Commit ce0830a

Browse files
kyle-ssgclaude
andcommitted
Add HTML report upload to Slack notifications
Restore the uploadFile function that was removed during refactoring. Now when tests fail, the script will: 1. Send a Slack notification with the failure count 2. Upload the zipped HTML report to Slack for easy access Added a CI step to zip the playwright-report before sending the Slack notification. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 091f968 commit ce0830a

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

.github/workflows/.reusable-docker-e2e-tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ jobs:
117117
run: |
118118
echo "url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts" >> $GITHUB_OUTPUT
119119
120+
- name: Zip HTML report for Slack upload
121+
if: failure()
122+
working-directory: frontend
123+
run: |
124+
cd e2e
125+
zip -r playwright-report.zip playwright-report/ || echo "Failed to zip report"
126+
120127
- name: Send Slack notification on failure
121128
if: failure()
122129
working-directory: frontend

frontend/e2e/slack-e2e-reporter.ts

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,38 @@ import { WebClient } from '@slack/web-api';
44

55
const SLACK_TOKEN = process.env.SLACK_TOKEN;
66
const CHANNEL_ID = 'C0102JZRG3G'; // infra_tests channel ID
7+
const failedJsonPath = path.join(__dirname, 'test-results', 'failed.json');
8+
const failedData = JSON.parse(fs.readFileSync(failedJsonPath, 'utf-8'));
9+
const failedCount = failedData.failedTests?.length || 0;
10+
11+
async function uploadFile(filePath: string): Promise<void> {
12+
if (!SLACK_TOKEN) {
13+
console.log('Slack token not specified, skipping upload');
14+
return;
15+
}
16+
17+
const epoch = Date.now();
18+
const ext = path.extname(filePath);
19+
const basename = path.basename(filePath);
20+
21+
const isPlaywrightReport = basename === 'playwright-report.zip';
22+
const filename = isPlaywrightReport
23+
? `playwright-report-${epoch}.zip`
24+
: `e2e-artifact-${epoch}${ext}`;
25+
const comment = isPlaywrightReport
26+
? `📊 Playwright HTML Report ${process.env.GITHUB_ACTION_URL || ''}`
27+
: `✖ Test Run ${process.env.GITHUB_ACTION_URL || ''}`;
28+
29+
console.log(`Uploading ${filePath}`);
30+
31+
const slackClient = new WebClient(SLACK_TOKEN);
32+
await slackClient.files.uploadV2({
33+
channel_id: CHANNEL_ID,
34+
file: fs.createReadStream(filePath),
35+
filename,
36+
initial_comment: comment,
37+
});
38+
}
739

840
function postMessage(message: string): Promise<unknown> {
941
if (!SLACK_TOKEN) {
@@ -29,27 +61,32 @@ function notifyFailure(failedCount: number): Promise<unknown> {
2961
return postMessage(message);
3062
}
3163

32-
const failedJsonPath = path.join(__dirname, 'test-results', 'failed.json');
33-
3464
if (!fs.existsSync(failedJsonPath)) {
3565
console.log('No failed.json found, skipping Slack notification');
3666
process.exit(0);
3767
}
3868

39-
const failedData = JSON.parse(fs.readFileSync(failedJsonPath, 'utf-8'));
40-
const failedCount = failedData.failedTests?.length || 0;
41-
4269
if (failedCount === 0) {
4370
console.log('No failed tests, skipping Slack notification');
4471
process.exit(0);
4572
}
4673

47-
console.log(`Sending Slack notification for ${failedCount} failed test(s)...`);
48-
notifyFailure(failedCount)
49-
.then(() => {
50-
console.log('Slack notification sent successfully');
51-
process.exit(0);
52-
})
74+
async function main() {
75+
console.log(`Sending Slack notification for ${failedCount} failed test(s)...`);
76+
await notifyFailure(failedCount);
77+
console.log('Slack notification sent successfully');
78+
79+
// Upload HTML report if zip file exists
80+
const reportZipPath = path.join(__dirname, 'playwright-report.zip');
81+
if (fs.existsSync(reportZipPath)) {
82+
console.log('Uploading HTML report...');
83+
await uploadFile(reportZipPath);
84+
console.log('HTML report uploaded successfully');
85+
}
86+
}
87+
88+
main()
89+
.then(() => process.exit(0))
5390
.catch((error) => {
5491
console.error('Failed to send Slack notification:', error);
5592
process.exit(1);

0 commit comments

Comments
 (0)