|
| 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.repository == 'sveltejs/svelte' && 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 | + let hasTriagePermission = false |
| 19 | + try { |
| 20 | + const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 21 | + owner: context.repo.owner, |
| 22 | + repo: context.repo.repo, |
| 23 | + username: user, |
| 24 | + }); |
| 25 | + hasTriagePermission = data.user.permissions.triage |
| 26 | + } catch (e) { |
| 27 | + console.warn(e) |
| 28 | + } |
| 29 | +
|
| 30 | + if (hasTriagePermission) { |
| 31 | + console.log('Allowed') |
| 32 | + await github.rest.reactions.createForIssueComment({ |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + comment_id: context.payload.comment.id, |
| 36 | + content: '+1', |
| 37 | + }) |
| 38 | + } else { |
| 39 | + console.log('Not allowed') |
| 40 | + await github.rest.reactions.createForIssueComment({ |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + comment_id: context.payload.comment.id, |
| 44 | + content: '-1', |
| 45 | + }) |
| 46 | + throw new Error('not allowed') |
| 47 | + } |
| 48 | + - uses: actions/github-script@v6 |
| 49 | + id: get-pr-data |
| 50 | + with: |
| 51 | + script: | |
| 52 | + console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`) |
| 53 | + const { data: pr } = await github.rest.pulls.get({ |
| 54 | + owner: context.repo.owner, |
| 55 | + repo: context.repo.repo, |
| 56 | + pull_number: context.issue.number |
| 57 | + }) |
| 58 | + return { |
| 59 | + num: context.issue.number, |
| 60 | + branchName: pr.head.ref, |
| 61 | + repo: pr.head.repo.full_name |
| 62 | + } |
| 63 | + - id: generate-token |
| 64 | + uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 #keep pinned for security reasons, currently 1.8.0 |
| 65 | + with: |
| 66 | + app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }} |
| 67 | + private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }} |
| 68 | + repository: "${{ github.repository_owner }}/svelte-ecosystem-ci" |
| 69 | + - uses: actions/github-script@v6 |
| 70 | + id: trigger |
| 71 | + env: |
| 72 | + COMMENT: ${{ github.event.comment.body }} |
| 73 | + with: |
| 74 | + github-token: ${{ steps.generate-token.outputs.token }} |
| 75 | + result-encoding: string |
| 76 | + script: | |
| 77 | + const comment = process.env.COMMENT.trim() |
| 78 | + const prData = ${{ steps.get-pr-data.outputs.result }} |
| 79 | +
|
| 80 | + const suite = comment.split('\n')[0].replace(/^\/ecosystem-ci run/, '').trim() |
| 81 | +
|
| 82 | + await github.rest.actions.createWorkflowDispatch({ |
| 83 | + owner: context.repo.owner, |
| 84 | + repo: 'svelte-ecosystem-ci', |
| 85 | + workflow_id: 'ecosystem-ci-from-pr.yml', |
| 86 | + ref: 'main', |
| 87 | + inputs: { |
| 88 | + prNumber: '' + prData.num, |
| 89 | + branchName: prData.branchName, |
| 90 | + repo: prData.repo, |
| 91 | + suite: suite === '' ? '-' : suite |
| 92 | + } |
| 93 | + }) |
0 commit comments