-
-
Notifications
You must be signed in to change notification settings - Fork 594
102 lines (94 loc) · 3.68 KB
/
ecosystem-ci-trigger.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: ecosystem-ci trigger
# TODO: switch to workflow_dispatch
# on:
jobs:
trigger:
runs-on: ubuntu-latest
if: github.repository == 'web-infra-dev/rspack' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!eco-ci')
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
env:
COMMENT: ${{ github.event.comment.body }}
with:
github-token: ${{ secrets.RSPACK_ACCESS_TOKEN }}
result-encoding: string
script: |
const comment = process.env.COMMENT.trim()
const command = comment.split('\n')[0]
const prData = ${{ steps.get-pr-data.outputs.result }}
const [suite, suiteRefType, suiteRef] = command.replace(/^!eco-ci/, '').trim().split(' ')
const allSuites = suite === '' || suite === '-'
function normalizeSuiteRefType(suiteRefType) {
const prefix = '--suite-'
if (allSuites || suiteRefType === undefined || !suiteRefType.startsWith(prefix)) {
return 'precoded'
}
return suiteRefType.slice(prefix.length)
}
function normalizeSuiteRef(suiteRef) {
return (allSuites || suiteRef === undefined) ? 'precoded' : suiteRef
}
await github.rest.actions.createWorkflowDispatch({
owner: 'rspack-contrib',
repo: 'rspack-ecosystem-ci',
workflow_id: 'ecosystem-ci-from-pr.yml',
ref: 'main',
inputs: {
prNumber: '' + prData.num,
branchName: prData.branchName,
repo: prData.repo,
suite: allSuites ? '-' : suite,
suiteRefType: normalizeSuiteRefType(suiteRefType),
suiteRef: normalizeSuiteRef(suiteRef),
}
})