Skip to content

Commit 7c4ab51

Browse files
authored
chore: trigger ecosystem-ci by comment (#9887)
1 parent 9ac5075 commit 7c4ab51

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: ecosystem-ci trigger
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
trigger:
9+
runs-on: ubuntu-latest
10+
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run')
11+
steps:
12+
- uses: actions/github-script@v6
13+
with:
14+
script: |
15+
const user = context.payload.sender.login
16+
console.log(`Validate user: ${user}`)
17+
18+
const allowedUsers = new Set([
19+
'yyx990803',
20+
'patak-dev',
21+
'antfu',
22+
'sodatea',
23+
'Shinigami92',
24+
'aleclarson',
25+
'bluwy',
26+
'poyoho',
27+
'sapphi-red',
28+
'ygj6',
29+
'Niputi'
30+
])
31+
32+
if (allowedUsers.has(user)) {
33+
console.log('Allowed')
34+
await github.rest.reactions.createForIssueComment({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
comment_id: context.payload.comment.id,
38+
content: '+1',
39+
})
40+
} else {
41+
console.log('Not allowed')
42+
await github.rest.reactions.createForIssueComment({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
comment_id: context.payload.comment.id,
46+
content: '-1',
47+
})
48+
throw new Error('not allowed')
49+
}
50+
- uses: actions/github-script@v6
51+
id: get-pr-data
52+
with:
53+
script: |
54+
console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`)
55+
const { data: pr } = await github.rest.pulls.get({
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
pull_number: context.issue.number
59+
})
60+
return {
61+
num: context.issue.number,
62+
branchName: pr.head.ref,
63+
repo: pr.head.repo.full_name
64+
}
65+
- id: generate-token
66+
uses: tibdex/github-app-token@v1
67+
with:
68+
app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }}
69+
private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}
70+
repository: "${{ github.repository_owner }}/vite-ecosystem-ci"
71+
- uses: actions/github-script@v6
72+
id: trigger
73+
env:
74+
COMMENT: ${{ github.event.comment.body }}
75+
with:
76+
github-token: ${{ steps.generate-token.outputs.token }}
77+
result-encoding: string
78+
script: |
79+
const comment = process.env.COMMENT.trim()
80+
const prData = ${{ steps.get-pr-data.outputs.result }}
81+
82+
const suite = comment.replace(/^\/ecosystem-ci run/, '').trim()
83+
84+
await github.rest.actions.createWorkflowDispatch({
85+
owner: context.repo.owner,
86+
repo: 'vite-ecosystem-ci',
87+
workflow_id: 'ecosystem-ci-from-pr.yml',
88+
ref: 'main',
89+
inputs: {
90+
prNumber: '' + prData.num,
91+
branchName: prData.branchName,
92+
repo: prData.repo,
93+
suite: suite === '' ? '-' : suite
94+
}
95+
})

0 commit comments

Comments
 (0)