-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
92 lines (79 loc) · 2.58 KB
/
post-benchmark-core.yml
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
name: Post Comment for Benchmark - core
on:
workflow_run:
workflows: ["Benchmark - core"]
types:
- completed
jobs:
post-benchmark-core:
name: Post Benchmark Comment on Pull Request
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Download Repository
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v4
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
run-id: ${{ github.event.workflow_run.id }}
name: benchmark-core
path: benchmark-core/
- name: Make pull request comment
run: |
cat - >>comment.txt <<EOF
### Benchmark - core
#### Yew Master
\`\`\`
EOF
cat benchmark-core/yew-master/tools/output.log >>comment.txt
cat - >>comment.txt <<EOF
\`\`\`
#### Pull Request
\`\`\`
EOF
cat benchmark-core/current-pr/tools/output.log >>comment.txt
cat - >>comment.txt <<EOF
\`\`\`
EOF
- name: Read Pull Request ID
run: echo "PR_NUMBER=$(cat benchmark-core/.PR_NUMBER)" >> $GITHUB_ENV
- name: Post Comment
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const commentInfo = {
...context.repo,
issue_number: ${{ env.PR_NUMBER }},
};
const comment = {
...commentInfo,
body: fs.readFileSync("comment.txt", 'utf-8'),
};
function isCommentByBot(comment) {
return comment.user.type === "Bot" && comment.body.includes("### Benchmark - core");
}
let commentId = null;
const comments = (await github.rest.issues.listComments(commentInfo)).data;
for (let i = comments.length; i--; ) {
const c = comments[i];
if (isCommentByBot(c)) {
commentId = c.id;
break;
}
}
if (commentId) {
try {
await github.rest.issues.updateComment({
...context.repo,
comment_id: commentId,
body: comment.body,
});
} catch (e) {
commentId = null;
}
}
if (!commentId) {
await github.rest.issues.createComment(comment);
}