2023-07-20 09:58:58 +00:00
|
|
|
name: ecosystem-ci trigger
|
|
|
|
|
|
|
|
on:
|
|
|
|
issue_comment:
|
|
|
|
types: [created]
|
|
|
|
|
2023-07-20 12:48:38 +00:00
|
|
|
permissions:
|
|
|
|
pull-requests: write
|
|
|
|
|
2023-07-20 09:58:58 +00:00
|
|
|
jobs:
|
|
|
|
trigger:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: github.repository == 'nuxt/nuxt' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run')
|
|
|
|
steps:
|
2023-07-25 14:47:29 +00:00
|
|
|
- uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
|
2023-07-20 09:58:58 +00:00
|
|
|
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')
|
|
|
|
}
|
2023-07-25 14:47:29 +00:00
|
|
|
- uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
|
2023-07-20 09:58:58 +00:00
|
|
|
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
|
2023-09-10 08:56:12 +00:00
|
|
|
uses: tibdex/github-app-token@0914d50df753bbc42180d982a6550f195390069f # v2.0.0
|
2023-07-20 09:58:58 +00:00
|
|
|
with:
|
|
|
|
app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }}
|
|
|
|
private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}
|
|
|
|
repository: "${{ github.repository_owner }}/ecosystem-ci"
|
2023-07-25 14:47:29 +00:00
|
|
|
- uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
|
2023-07-20 09:58:58 +00:00
|
|
|
id: trigger
|
|
|
|
env:
|
|
|
|
COMMENT: ${{ github.event.comment.body }}
|
|
|
|
with:
|
|
|
|
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(/^\/ecosystem-ci run/, '').trim()
|
|
|
|
|
|
|
|
await github.rest.actions.createWorkflowDispatch({
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: 'ecosystem-ci',
|
|
|
|
workflow_id: 'ecosystem-ci-from-pr.yml',
|
|
|
|
ref: 'main',
|
|
|
|
inputs: {
|
|
|
|
prNumber: '' + prData.num,
|
|
|
|
branchName: prData.branchName,
|
|
|
|
repo: prData.repo,
|
|
|
|
suite: suite === '' ? '-' : suite
|
|
|
|
}
|
|
|
|
})
|