-
Notifications
You must be signed in to change notification settings - Fork 107
Feat/benchmark workflows #1671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/benchmark workflows #1671
Changes from all commits
c7aadee
1bc66cb
41c5c52
dac431f
34beccd
64d649c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,85 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| issue_comment: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| types: [created] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| concurrency: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cancel-in-progress: ${{ github.ref_name != 'master' }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trigger: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if: github.event.issue.pull_request && startsWith(github.event.comment.body, '!bench') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - uses: actions/github-script@v7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const user = context.payload.sender.login | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`Validate user: ${user}`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let hasTriagePermission = false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| owner: context.repo.owner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo: context.repo.repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| username: user, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hasTriagePermission = data.user.permissions.triage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn(e) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议改进错误处理逻辑 当前的错误处理过于简单,建议:
建议修改为: try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: user,
});
hasTriagePermission = data.user.permissions.triage
} catch (e) {
- console.warn(e)
+ console.error(`Failed to check permissions for user ${user}: ${e.message}`);
+ if (e.status === 404) {
+ console.log('User is not a collaborator');
+ } else if (e.status === 403) {
+ console.log('API rate limit exceeded or token scope issue');
+ }
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hasTriagePermission) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('Allowed') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await github.rest.reactions.createForIssueComment({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| owner: context.repo.owner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo: context.repo.repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| comment_id: context.payload.comment.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: '+1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('Not allowed') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await github.rest.reactions.createForIssueComment({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| owner: context.repo.owner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo: context.repo.repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| comment_id: context.payload.comment.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: '-1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error('not allowed') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - uses: actions/github-script@v7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: get-pr-data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data: pr } = await github.rest.pulls.get({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| owner: context.repo.owner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo: context.repo.repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pull_number: context.issue.number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| num: context.issue.number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| branchName: pr.head.ref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo: pr.head.repo.full_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+57
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议增加数据验证 获取 PR 数据时缺少必要的数据验证,建议:
建议添加验证: const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
+if (pr.state !== 'open') {
+ throw new Error('PR must be open to run benchmarks')
+}
+if (!pr.head?.ref || !pr.head?.repo?.full_name) {
+ throw new Error('Invalid PR data structure')
+}
return {
num: context.issue.number,
branchName: pr.head.ref,
repo: pr.head.repo.full_name
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - uses: actions/github-script@v7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: trigger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| github-token: ${{ secrets.MAKO_BOT_ACCESS_TOKEN }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result-encoding: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const prData = ${{ steps.get-pr-data.outputs.result }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await github.rest.actions.createWorkflowDispatch({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| owner: context.repo.owner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo: 'mako-ecosystem-benchmark', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workflow_id: 'bench_mako_pr.yml', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ref: 'main', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputs: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prNumber: '' + prData.num | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
建议增强工作流触发控制
工作流配置基本合理,但建议考虑以下改进:
permissions字段明确声明所需权限cancel-in-progress的判断改为更精确的表达式,比如: