-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathpost_performance_test_comment.yml
More file actions
122 lines (107 loc) · 4.33 KB
/
Copy pathpost_performance_test_comment.yml
File metadata and controls
122 lines (107 loc) · 4.33 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
name: post_performance_test_comment
# Runs in the base-repo context (NOT the PR's fork context), so GITHUB_TOKEN
# has write access even for fork PRs. We never check out or execute PR code
# here — we only read the benchmark markdown the PR workflow uploaded.
on:
workflow_run:
workflows: [ "run_performance_tests_windows" ]
types: [ completed ]
permissions:
pull-requests: write
issues: write
actions: read
jobs:
post_comment:
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Download benchmark artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: benchmark-results
path: benchmark-artifact
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Post benchmark results to PR
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const fs = require('fs');
const path = require('path');
const artifactRoot = `${process.env.GITHUB_WORKSPACE}/benchmark-artifact`;
const prInfo = JSON.parse(fs.readFileSync(`${artifactRoot}/pr-info.json`, 'utf8'));
const prNumber = prInfo.pr_number;
const headSha = prInfo.head_sha;
if (!prNumber) {
core.setFailed('pr-info.json did not contain pr_number');
return;
}
function readMarkdownReports(dir) {
if (!fs.existsSync(dir)) {
core.info(`Results directory not found: ${dir}`);
return '';
}
const files = fs.readdirSync(dir)
.filter(f => f.endsWith('-report-github.md'))
.sort();
if (files.length === 0) {
core.info(`No *-report-github.md files in ${dir}`);
return '';
}
return files
.map(f => fs.readFileSync(path.join(dir, f), 'utf8').trim())
.join('\n\n');
}
const prMarkdown = readMarkdownReports(`${artifactRoot}/branch-results`);
const mainMarkdown = readMarkdownReports(`${artifactRoot}/main-results`);
if (!prMarkdown) {
core.warning('No PR benchmark markdown found — skipping comment');
return;
}
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${context.payload.workflow_run.id}`;
const sha = (headSha || '').slice(0, 7);
const body = [
'<!-- benchmark-results-marker -->',
'## 📊 Benchmark Results',
'',
`> Commit: \`${sha}\` · [Full run](${runUrl}) · Windows \`windows-latest\``,
'',
'<details open>',
'<summary><b>PR branch</b></summary>',
'',
prMarkdown,
'',
'</details>',
'',
'<details>',
'<summary><b><code>main</code> branch</b></summary>',
'',
mainMarkdown || '_No main branch results available._',
'',
'</details>',
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.body?.includes('<!-- benchmark-results-marker -->'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
core.info(`Updated benchmark comment #${existing.id}`);
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
core.info(`Created benchmark comment on PR #${prNumber}`);
}