Skip to content

Commit 20756b1

Browse files
authored
chore: add bench-pr.yml (#115)
1 parent f9c7b04 commit 20756b1

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

.github/workflows/bench-pr.yml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Benchmark PR
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
# cancel previous job runs for the same workflow + pr
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
trigger:
14+
runs-on: ubuntu-latest
15+
if: github.repository == 'web-infra-dev/rslib' && (github.event.issue.pull_request && startsWith(github.event.comment.body, '!bench'))
16+
steps:
17+
- uses: actions/github-script@v7
18+
with:
19+
script: |
20+
const user = context.payload.sender.login
21+
console.log(`Validate user: ${user}`)
22+
23+
let hasTriagePermission = false
24+
try {
25+
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
username: user,
29+
});
30+
hasTriagePermission = data.user.permissions.triage
31+
} catch (e) {
32+
console.warn(e)
33+
}
34+
35+
if (hasTriagePermission) {
36+
console.log('Allowed')
37+
await github.rest.reactions.createForIssueComment({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
comment_id: context.payload.comment.id,
41+
content: '+1',
42+
})
43+
} else {
44+
console.log('Not allowed')
45+
await github.rest.reactions.createForIssueComment({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
comment_id: context.payload.comment.id,
49+
content: '-1',
50+
})
51+
throw new Error('not allowed')
52+
}
53+
- uses: actions/github-script@v7
54+
id: get-pr-data
55+
with:
56+
script: |
57+
console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`)
58+
const { data: pr } = await github.rest.pulls.get({
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
pull_number: context.issue.number
62+
})
63+
return {
64+
num: context.issue.number,
65+
branchName: pr.head.ref,
66+
repo: pr.head.repo.full_name
67+
}
68+
- uses: actions/github-script@v7
69+
id: trigger
70+
with:
71+
github-token: ${{ secrets.REPO_SCOPED_TOKEN }}
72+
result-encoding: string
73+
script: |
74+
const prData = ${{ steps.get-pr-data.outputs.result }}
75+
76+
await github.rest.actions.createWorkflowDispatch({
77+
owner: context.repo.owner,
78+
repo: 'web-infra-QoS',
79+
workflow_id: 'pr-bench.yaml',
80+
ref: 'master',
81+
inputs: {
82+
prNumber: '' + prData.num,
83+
product: 'RSLIB',
84+
repo: 'rslib'
85+
}
86+
})

0 commit comments

Comments
 (0)