Skip to content

Commit af26c19

Browse files
committed
add commenting of status into PR
1 parent a083605 commit af26c19

File tree

2 files changed

+140
-2
lines changed

2 files changed

+140
-2
lines changed

.github/workflows/autobahn.yml

+20-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,24 @@ jobs:
4747
run: npm run test:websocket:autobahn
4848
env:
4949
FUZZING_SERVER_URL: ws://fuzzingserver:9001
50-
- name: Report
50+
51+
- name: Report into CI
52+
id: report-ci
5153
run: npm run test:websocket:autobahn:report
54+
55+
- name: Generate Report for PR Comment
56+
if: github.event_name == 'pull_request'
57+
id: report-markdown
58+
run: |
59+
echo "comment<<nEOFn" >> $GITHUB_OUTPUT
60+
node test/autobahn/report.js >> $GITHUB_OUTPUT
61+
echo "nEOFn" >> $GITHUB_OUTPUT
62+
env:
63+
REPORTER: markdown
64+
65+
- name: Comment PR
66+
if: github.event_name == 'pull_request'
67+
uses: thollander/actions-comment-pull-request@v2
68+
with:
69+
message: ${{ steps.report-markdown.outputs.comment }}
70+
comment_tag: autobahn

test/autobahn/report.js

+120-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,41 @@
22

33
const result = require('./reports/clients/index.json').undici
44

5+
const failOnError = process.env.FAIL_ON_ERROR === 'true'
6+
const reporter = process.env.REPORTER || 'table'
7+
let runFailed = false
8+
9+
let okTests = 0
10+
let failedTests = 0
11+
let nonStrictTests = 0
12+
let wrongCodeTests = 0
13+
let uncleanTests = 0
14+
let failedByClientTests = 0
15+
let informationalTests = 0
16+
let unimplementedTests = 0
17+
18+
let totalTests = 0
19+
520
function testCaseIdToWeight (testCaseId) {
621
const [major, minor, sub] = testCaseId.split('.')
722
return sub
823
? parseInt(major, 10) * 10000 + parseInt(minor, 10) * 100 + parseInt(sub, 10)
924
: parseInt(major, 10) * 10000 + parseInt(minor, 10) * 100
1025
}
1126

27+
function isFailedTestCase (testCase) {
28+
return (
29+
testCase.behavior === 'FAILED' ||
30+
testCase.behavior === 'WRONG CODE' ||
31+
testCase.behavior === 'UNCLEAN' ||
32+
testCase.behavior === 'FAILED BY CLIENT' ||
33+
testCase.behaviorClose === 'FAILED' ||
34+
testCase.behaviorClose === 'WRONG CODE' ||
35+
testCase.behaviorClose === 'UNCLEAN' ||
36+
testCase.behaviorClose === 'FAILED BY CLIENT'
37+
)
38+
}
39+
1240
const keys = Object.keys(result).sort((a, b) => {
1341
a = testCaseIdToWeight(a)
1442
b = testCaseIdToWeight(b)
@@ -18,6 +46,97 @@ const keys = Object.keys(result).sort((a, b) => {
1846
const reorderedResult = {}
1947
for (const key of keys) {
2048
reorderedResult[key] = result[key]
49+
delete reorderedResult[key].reportfile
50+
51+
totalTests++
52+
53+
if (
54+
failOnError &&
55+
!runFailed &&
56+
isFailedTestCase(result[key])
57+
) {
58+
runFailed = true
59+
}
60+
61+
switch (result[key].behavior) {
62+
case 'OK':
63+
okTests++
64+
break
65+
case 'FAILED':
66+
failedTests++
67+
break
68+
case 'NON-STRICT':
69+
nonStrictTests++
70+
break
71+
case 'WRONG CODE':
72+
wrongCodeTests++
73+
break
74+
case 'UNCLEAN':
75+
uncleanTests++
76+
break
77+
case 'FAILED BY CLIENT':
78+
failedByClientTests++
79+
break
80+
case 'INFORMATIONAL':
81+
informationalTests++
82+
break
83+
case 'UNIMPLEMENTED':
84+
unimplementedTests++
85+
break
86+
}
87+
}
88+
89+
if (
90+
reporter === 'table'
91+
) {
92+
console.log('Autobahn Test Report\n\nSummary:')
93+
94+
console.table({
95+
OK: okTests,
96+
Failed: failedTests,
97+
'Non-Strict': nonStrictTests,
98+
'Wrong Code': wrongCodeTests,
99+
Unclean: uncleanTests,
100+
'Failed By Client': failedByClientTests,
101+
Informational: informationalTests,
102+
Unimplemented: unimplementedTests,
103+
'Total Tests': totalTests
104+
})
105+
106+
console.log('Details:')
107+
108+
console.table(reorderedResult)
109+
}
110+
111+
if (reporter === 'markdown') {
112+
console.log(`## Autobahn Test Report
113+
114+
### Summary
115+
116+
| Type | Count |
117+
|---|---|
118+
| OK | ${okTests} |
119+
| Failed | ${failedTests} |
120+
| Non-Strict | ${nonStrictTests} |
121+
| Wrong Code | ${wrongCodeTests} |
122+
| Unclean | ${uncleanTests} |
123+
| Failed By Client | ${failedByClientTests} |
124+
| Informational | ${informationalTests} |
125+
| Unimplemented | ${unimplementedTests} |
126+
| Total Tests | ${totalTests} |
127+
128+
<details>
129+
<summary>Details</summary>
130+
131+
| Test Case | Behavior | Close Behavior | Duration | Remote Close Code |
132+
|---|---|---|---|---|
133+
${keys.map(key => {
134+
const testCase = reorderedResult[key]
135+
return `| ${key} | ${testCase.behavior} | ${testCase.behaviorClose} | ${testCase.duration} | ${testCase.remoteCloseCode} |`
136+
}).join('\n')}
137+
138+
</details>
139+
`)
21140
}
22141

23-
console.table(reorderedResult)
142+
process.exit(runFailed ? 1 : 0)

0 commit comments

Comments
 (0)