-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathreport-benchmark-result-pr.ts
More file actions
112 lines (97 loc) · 3.03 KB
/
report-benchmark-result-pr.ts
File metadata and controls
112 lines (97 loc) · 3.03 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
import { getOctokit, context } from '@actions/github'
import console from 'console'
import { appendFileSync, readFileSync } from 'fs'
import process from 'process'
import { Item as RegressionItem, collectRegressions } from './benchmark/collect-regressions'
import { SelfBenchmarkCategory, parseSelfBenchmarkCategory } from './benchmark/matrix'
import * as reportFiles from './benchmark/report-files'
import * as env from './lib/env'
import pickRandom from './lib/pick-random'
function loadReport(category: SelfBenchmarkCategory, ext: reportFiles.Extension) {
const { reportName } = parseSelfBenchmarkCategory(category)
const filePath = reportFiles.getFileName(reportName, ext)
return readFileSync(filePath, 'utf-8')
}
function rendered(category: SelfBenchmarkCategory) {
return [
'',
loadReport(category, 'md').trim(),
'',
].join('\n')
}
function codeBlock(category: SelfBenchmarkCategory, summary: string, lang: reportFiles.Format) {
return [
'<details><summary>',
summary,
'</summary>',
'',
'```' + lang,
loadReport(category, reportFiles.MAP[lang]).trim(),
'```',
'',
'</details>',
].join('\n')
}
function regressionReport(item: RegressionItem) {
const { category } = item
const { commandSuffix } = parseSelfBenchmarkCategory(category)
return [
'<details>',
`<summary><strong>${commandSuffix.join(' ')}</strong></summary>`,
'',
rendered(category),
codeBlock(category, 'Logs', 'log'),
codeBlock(category, 'JSON', 'json'),
'',
'</details>',
].join('\n')
}
async function main() {
const commentTitle = '## Performance Regression Reports'
const regressionCollection = [...collectRegressions()]
const randomRegressions = [...pickRandom(regressionCollection, 5)]
const reportBody = randomRegressions.length
? randomRegressions.map(regressionReport).join('\n')
: 'There are no regressions.'
const overallReport = [
commentTitle,
'',
`commit: ${context.issue.owner}/${context.issue.repo}@${context.sha}`,
'',
reportBody,
].join('\n')
const stepSummaryPath = env.load('GITHUB_STEP_SUMMARY', '')
if (stepSummaryPath) {
appendFileSync(stepSummaryPath, overallReport + '\n')
}
const auth = env.load('GITHUB_TOKEN')
const github = getOctokit(auth).rest
const sharedOptions = {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
}
const allComments = await github.issues.listComments(sharedOptions)
const targetComments = allComments
.data
.filter(comment => comment.user?.login === 'github-actions[bot]')
.filter(comment => comment.body?.split('\n').includes(commentTitle))
if (!targetComments.length) {
await github.issues.createComment({
...sharedOptions,
body: overallReport,
})
return
}
await Promise.all(targetComments.map(comment =>
github.issues.updateComment({
...sharedOptions,
comment_id: comment.id,
body: overallReport,
})
))
}
main().catch(error => {
console.error(error)
throw process.exit(1)
})