|
| 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 == 'vuejs/core' && 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 isVuejsMember = false |
| 19 | + try { |
| 20 | + const { status } = await github.rest.orgs.checkMembershipForUser({ |
| 21 | + org: 'vuejs', |
| 22 | + username: user |
| 23 | + }); |
| 24 | +
|
| 25 | + isVuejsMember = (status === 204) |
| 26 | + } catch (e) {} |
| 27 | +
|
| 28 | + if (isVuejsMember) { |
| 29 | + console.log('Allowed') |
| 30 | + await github.rest.reactions.createForIssueComment({ |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + comment_id: context.payload.comment.id, |
| 34 | + content: '+1', |
| 35 | + }) |
| 36 | + } else { |
| 37 | + console.log('Not allowed') |
| 38 | + await github.rest.reactions.createForIssueComment({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + comment_id: context.payload.comment.id, |
| 42 | + content: '-1', |
| 43 | + }) |
| 44 | + throw new Error('not allowed') |
| 45 | + } |
| 46 | + - uses: actions/github-script@v6 |
| 47 | + id: get-pr-data |
| 48 | + with: |
| 49 | + script: | |
| 50 | + console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`) |
| 51 | + const { data: pr } = await github.rest.pulls.get({ |
| 52 | + owner: context.repo.owner, |
| 53 | + repo: context.repo.repo, |
| 54 | + pull_number: context.issue.number |
| 55 | + }) |
| 56 | + return { |
| 57 | + num: context.issue.number, |
| 58 | + branchName: pr.head.ref, |
| 59 | + repo: pr.head.repo.full_name |
| 60 | + } |
| 61 | + - uses: actions/github-script@v6 |
| 62 | + id: trigger |
| 63 | + env: |
| 64 | + COMMENT: ${{ github.event.comment.body }} |
| 65 | + with: |
| 66 | + github-token: ${{ secrets.ECOSYSTEM_CI_ACCESS_TOKEN }} |
| 67 | + result-encoding: string |
| 68 | + script: | |
| 69 | + const comment = process.env.COMMENT.trim() |
| 70 | + const prData = ${{ steps.get-pr-data.outputs.result }} |
| 71 | +
|
| 72 | + const suite = comment.replace(/^\/ecosystem-ci run/, '').trim() |
| 73 | +
|
| 74 | + await github.rest.actions.createWorkflowDispatch({ |
| 75 | + owner: context.repo.owner, |
| 76 | + repo: 'ecosystem-ci', |
| 77 | + workflow_id: 'ecosystem-ci-from-pr.yml', |
| 78 | + ref: 'main', |
| 79 | + inputs: { |
| 80 | + prNumber: '' + prData.num, |
| 81 | + branchName: prData.branchName, |
| 82 | + repo: prData.repo, |
| 83 | + suite: suite === '' ? '-' : suite |
| 84 | + } |
| 85 | + }) |
0 commit comments