|
| 1 | +name: PR_COMMENT_CI |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + check: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + outputs: |
| 11 | + next_action: ${{ steps.get-action.outputs.next_action }} |
| 12 | + if: ${{ github.event.issue.pull_request }} |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 1 |
| 17 | + - uses: actions/github-script@v7 |
| 18 | + id: get-action |
| 19 | + with: |
| 20 | + script: | |
| 21 | + const user = context.payload.comment.user.login |
| 22 | + core.debug(`user: ${user}`) |
| 23 | +
|
| 24 | + const fs = require('fs') |
| 25 | + const CODEOWNERS = fs.readFileSync('.github/CODEOWNERS', 'utf8') |
| 26 | + core.debug(`CODEOWNERS: ${CODEOWNERS}`) |
| 27 | +
|
| 28 | + let isReviewer = false; |
| 29 | + CODEOWNERS.match(/@\w+/g).forEach((owner) => { |
| 30 | + if (owner === `@${user}`) { |
| 31 | + isReviewer = true |
| 32 | + } |
| 33 | + }) |
| 34 | +
|
| 35 | + let next_action = '' |
| 36 | + if (isReviewer) { |
| 37 | + const body = context.payload.comment.body |
| 38 | + core.info(`body: ${body}`) |
| 39 | + if (body.startsWith('/update-common')) { |
| 40 | + next_action='update-common' |
| 41 | + } |
| 42 | + if (body.startsWith('/update-snapshot')) { |
| 43 | + next_action='update-snapshot' |
| 44 | + } |
| 45 | + } else { |
| 46 | + core.warning('You are not collaborator'); |
| 47 | + } |
| 48 | + core.info(`next_action: ${next_action}`) |
| 49 | + core.setOutput('next_action', next_action) |
| 50 | + |
| 51 | + update-common: |
| 52 | + needs: check |
| 53 | + runs-on: ubuntu-latest |
| 54 | + if: ${{ needs.check.outputs.next_action == 'update-common' }} |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + with: |
| 58 | + token: ${{ secrets.PERSONAL_TOKEN }} |
| 59 | + - name: gh checkout pr |
| 60 | + env: |
| 61 | + GH_TOKEN: ${{ secrets.PERSONAL_TOKEN }} |
| 62 | + run: gh pr checkout ${{ github.event.issue.number }} --recurse-submodules |
| 63 | + - run: git submodule update --remote --merge |
| 64 | + - name: Commit Common |
| 65 | + run: | |
| 66 | + git add . |
| 67 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 68 | + git config --local user.name "github-actions[bot]" |
| 69 | + git commit -m "chore: update common" |
| 70 | + git push |
| 71 | + |
| 72 | + update-snapshot: |
| 73 | + needs: check |
| 74 | + runs-on: ubuntu-latest |
| 75 | + if: ${{ needs.check.outputs.next_action == 'update-snapshot' }} |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + with: |
| 79 | + token: ${{ secrets.PERSONAL_TOKEN }} |
| 80 | + - name: gh checkout pr |
| 81 | + env: |
| 82 | + GH_TOKEN: ${{ secrets.PERSONAL_TOKEN }} |
| 83 | + run: gh pr checkout ${{ github.event.issue.number }} --recurse-submodules |
| 84 | + - uses: actions/setup-node@v4 |
| 85 | + with: |
| 86 | + node-version: 18 |
| 87 | + - run: npm install |
| 88 | + - run: npm run test:update |
| 89 | + - name: Commit Snapshot |
| 90 | + run: | |
| 91 | + git add . |
| 92 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 93 | + git config --local user.name "github-actions[bot]" |
| 94 | + git commit -m "chore: update snapshot" |
| 95 | + git push |
0 commit comments