-
Notifications
You must be signed in to change notification settings - Fork 2
107 lines (90 loc) · 3.96 KB
/
Copy pathupdate-benchmarks.yml
File metadata and controls
107 lines (90 loc) · 3.96 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
name: Update Benchmarks
on:
issues:
types: [opened, labeled]
jobs:
update:
if: contains(github.event.issue.labels.*.name, 'benchmark-result')
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- uses: actions/checkout@v4
- name: Parse benchmark data and append row
id: parse
uses: actions/github-script@v7
with:
script: |
const body = context.payload.issue.body || '';
// Extract JSON from <!-- benchmark-data ... --> comment
const match = body.match(/<!--\s*benchmark-data\s*\n([\s\S]*?)\n-->/);
if (!match) {
core.setFailed('No benchmark-data block found in issue body.');
return;
}
let data;
try {
data = JSON.parse(match[1].trim());
} catch (e) {
core.setFailed(`Failed to parse benchmark JSON: ${e.message}`);
return;
}
const s = data.system || {};
const cpu = (s.cpu || 'unknown').replace(/\|/g, '/').substring(0, 40);
const gpu = s.cuda ? (s.gpu || 'GPU').replace(/\|/g, '/').substring(0, 30) : 'CPU only';
const os = s.os || '—';
const date = data.date || '—';
const getField = (results, model, field, fallback = '—') => {
const r = (results || []).find(x => x.model === model);
return r && !r.error ? String(r[field]) + (field === 'rtf' ? 'x' : 's') : fallback;
};
const tinyRtf = getField(data.results, 'tiny', 'rtf');
const smallRtf = getField(data.results, 'small', 'rtf');
const mediumRtf = getField(data.results, 'medium', 'rtf');
const row = `| ${date} | ${cpu} | ${gpu} | ${os} | ${tinyRtf} | ${smallRtf} | ${mediumRtf} |`;
core.setOutput('row', row);
core.setOutput('issue_number', String(context.payload.issue.number));
- name: Write row to BENCHMARKS.md
run: |
ROW="${{ steps.parse.outputs.row }}"
# Replace the placeholder "no results" lines and insert the new row before the footer
python3 - <<'PYEOF'
import re, os
row = os.environ['ROW']
path = 'BENCHMARKS.md'
content = open(path).read()
# Remove placeholder row if present
content = re.sub(r'\| — \| — \| — \| — \| — \| — \| — \|\n\n\*No results yet.*\*\n', '', content)
# Insert new row after the table header separator
header_sep = '|------|-----|-----|----|----------|-----------|------------|'
if header_sep in content:
content = content.replace(header_sep, header_sep + '\n' + row, 1)
open(path, 'w').write(content)
print('Row inserted.')
PYEOF
env:
ROW: ${{ steps.parse.outputs.row }}
- name: Commit updated BENCHMARKS.md
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add BENCHMARKS.md
git diff --cached --quiet || git commit -m "benchmarks: add result from issue #${{ steps.parse.outputs.issue_number }}"
git push
- name: Close issue with comment
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt('${{ steps.parse.outputs.issue_number }}'),
body: '✅ Your benchmark result has been added to [BENCHMARKS.md](../blob/main/BENCHMARKS.md). Thank you!'
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt('${{ steps.parse.outputs.issue_number }}'),
state: 'closed'
});