-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (110 loc) · 4.61 KB
/
test-reporter.yml
File metadata and controls
131 lines (110 loc) · 4.61 KB
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
name: Test Failure Bug Report Generator
on:
workflow_run:
workflows: ["*"]
types:
- completed
jobs:
create-bug-reports:
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
runs-on: ubuntu-latest
steps:
- name: Download workflow artifacts
uses: actions/github-script@v7
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const testResults = artifacts.data.artifacts.find(
artifact => artifact.name === "test-results"
);
if (testResults) {
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: testResults.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('test-results.zip', Buffer.from(download.data));
}
- name: Process test results
id: process-results
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const AdmZip = require('adm-zip');
const zip = new AdmZip('test-results.zip');
const results = JSON.parse(zip.readAsText('test-results.json'));
const failureGroups = {};
results.failures.forEach(failure => {
const suite = failure.suite || 'Unknown Suite';
if (!failureGroups[suite]) {
failureGroups[suite] = [];
}
failureGroups[suite].push(failure);
});
return failureGroups;
- name: Create bug reports
uses: actions/github-script@v7
with:
script: |
const failureGroups = ${{ steps.process-results.outputs.result }};
for (const [suite, failures] of Object.entries(failureGroups)) {
const existingIssues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['test-failure', suite]
});
if (existingIssues.data.length === 0) {
const body = `
# Test Failures in ${suite}
## Workflow Information
- Workflow: ${context.payload.workflow_run.name}
- Run ID: ${context.payload.workflow_run.id}
- Triggered by: ${context.payload.workflow_run.head_commit.message}
- Commit: ${context.payload.workflow_run.head_commit.id}
## Failures
${failures.map(failure => `
### ${failure.test}
\`\`\`
${failure.message}
\`\`\`
**Stack trace:**
\`\`\`
${failure.stack}
\`\`\`
**Context:**
- File: ${failure.file}
- Line: ${failure.line}
- Column: ${failure.column}
`).join('\n')}
## Additional Context
- [Link to workflow run](${context.payload.workflow_run.html_url})
- [Link to commit](${context.payload.workflow_run.head_commit.url})
`;
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `🐛 Test Failures: ${suite}`,
body: body,
labels: ['bug', 'test-failure', suite, 'automated-report']
});
} else {
const existingIssue = existingIssues.data[0];
const updatedBody = existingIssue.body + '\n\n' +
`## New Failures (${new Date().toISOString()})\n\n` +
failures.map(f => `- ${f.test}: ${f.message}`).join('\n');
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: existingIssue.number,
body: updatedBody
});
}
}