Skip to content

Commit

Permalink
ci: add benchmark CI trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Apr 7, 2023
1 parent 44ad321 commit 834a8d4
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/benchmark-ci-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: benchmark-ci trigger

on:
issue_comment:
types: [created]

jobs:
trigger:
runs-on: ubuntu-latest
if: github.repository == 'fi3ework/vite' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/benchmark-ci run')
steps:
- uses: actions/github-script@v6
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@v6
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
}
# - id: generate-token
# uses: tibdex/github-app-token@v1
# with:
# app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }}
# private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}
# repository: "${{ github.repository_owner }}/vite-ecosystem-ci"
- uses: actions/github-script@v6
id: trigger
env:
COMMENT: ${{ github.event.comment.body }}
with:
github-token: ${{ secrets.PAT_FOR_TEST }}
# github-token: ${{ steps.generate-token.outputs.token }}
result-encoding: string
script: |
const comment = process.env.COMMENT.trim()
const prData = ${{ steps.get-pr-data.outputs.result }}
const suite = comment.split('\n')[0].replace(/^\/benchmark-ci run/, '').trim()
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: 'vite-benchmark',
workflow_id: 'pull-request-from-pr.yml',
ref: 'main',
inputs: {
pull_number: '' + prData.num,
repeats: '' + 3,
// branchName: prData.branchName,
// repo: prData.repo,
// suite: suite === '' ? '-' : suite
}
})

0 comments on commit 834a8d4

Please sign in to comment.