-
Notifications
You must be signed in to change notification settings - Fork 96
113 lines (100 loc) · 4.22 KB
/
ci-benchmark.yml
File metadata and controls
113 lines (100 loc) · 4.22 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
name: Benchmark Bot
on:
issue_comment:
types: [created]
permissions:
issues: write
pull-requests: write
jobs:
reply-to-benchmark:
if: |
startsWith(github.event.comment.body, '@benchmark') &&
github.event.issue.pull_request &&
(
github.event.comment.user.login == 'tchaton' ||
github.event.comment.user.login == 'lantiga' ||
github.event.comment.user.login == 'justusschock' ||
github.event.comment.user.login == 'Borda' ||
github.event.comment.user.login == 'bhimrazy' ||
github.event.comment.user.login == 'deependujha'
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Extract make args
id: extract
uses: actions/github-script@v9
with:
script: |
const fullComment = context.payload.comment.body;
const parts = fullComment.trim().split(/\s+/);
const makeargs = parts.slice(1).join(' '); // remove "@benchmark" and keep rest
core.setOutput("make_args", makeargs);
- name: Reply to PR comment and save ID
id: comment
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const path = '.github/benchmark/greet.md';
const replyTemplate = fs.readFileSync(path, 'utf8');
const username = context.payload.comment.user.login;
const prNumber = context.payload.issue.number;
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.issue.number,
});
const branch = pr.data.head.ref;
// Replace placeholders
const reply = replyTemplate
.replace(/{{username}}/g, username)
.replace(/{{pr_number}}/g, prNumber);
const response = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: reply
});
core.setOutput("comment_id", response.data.id);
core.setOutput("prNumber", prNumber);
core.setOutput("branch", branch);
core.setOutput("username", username);
- name: run python
run: |
pip install -U lightning-sdk
echo '"pr number: ${{ steps.comment.outputs.prNumber }}"; "branch: ${{ steps.comment.outputs.branch }}"'
echo "make-args: ${{steps.extract.outputs.make_args}}"
python .github/benchmark/benchmark.py \
--pr "${{ steps.comment.outputs.prNumber }}" \
--branch "${{ steps.comment.outputs.branch }}" \
--make-args "${{ steps.extract.outputs.make_args }}" \
2> error.txt || true
env: # the following values are parsed from the repository secrets
LIGHTNING_USER_ID: ${{ secrets.LIGHTNING_USER_ID }}
LIGHTNING_API_KEY: ${{ secrets.LIGHTNING_API_KEY }}
- name: Update the same comment
uses: actions/github-script@v9
env:
COMMENT_ID: ${{ steps.comment.outputs.comment_id }}
USERNAME: ${{ steps.comment.outputs.username }}
with:
script: |
const fs = require('fs');
const comment_id = Number(process.env.COMMENT_ID);
let reply = '';
if (fs.existsSync('result.md')) {
reply = fs.readFileSync('result.md', 'utf8');
} else if (fs.existsSync('error.txt') && fs.readFileSync('error.txt', 'utf8').trim().length > 0) {
const err = fs.readFileSync('error.txt', 'utf8');
reply = `❌ **Benchmark failed**\n\n\`\`\`\n${err}\n\`\`\``;
} else {
reply = '❌ Benchmark completed, but can\'t find `result.md` and `error.txt` file. Something went wrong.';
}
const updated_body = `Hi @${process.env.USERNAME}!\n\n${reply}\n\ncc: @tchaton @deependujha @bhimrazy`;
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment_id,
body: updated_body
});