Skip to content

Commit

Permalink
feat: benchmark-workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Wu-kung committed Oct 24, 2024
1 parent 532f9b5 commit c7aadee
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/bench.yml
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)
}
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
}
- uses: actions/github-script@v7
id: trigger
with:
github-token: ${{ secrets.GITHUB_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
}
})

0 comments on commit c7aadee

Please sign in to comment.