Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add pr-comment-ci #3217

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/pr-comment-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: PR_COMMENT_CI

on:
issue_comment:
types: [created]

jobs:
check:
runs-on: ubuntu-latest
outputs:
next_action: ${{ steps.get-action.outputs.next_action }}
if: ${{ github.event.issue.pull_request }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/github-script@v7
id: get-action
with:
script: |
const user = context.payload.comment.user.login
core.debug(`user: ${user}`)

const fs = require('fs')
const CODEOWNERS = fs.readFileSync('.github/CODEOWNERS', 'utf8')
core.debug(`CODEOWNERS: ${CODEOWNERS}`)

let isReviewer = false;
CODEOWNERS.match(/@\w+/g).forEach((owner) => {
if (owner === `@${user}`) {
isReviewer = true
}
})

let next_action = ''
if (isReviewer) {
const body = context.payload.comment.body
core.info(`body: ${body}`)
if (body.startsWith('/update-common')) {
next_action='update-common'
}
if (body.startsWith('/update-snapshot')) {
next_action='update-snapshot'
}
} else {
core.warning('You are not collaborator');
}
core.info(`next_action: ${next_action}`)
core.setOutput('next_action', next_action)

update-common:
needs: check
runs-on: ubuntu-latest
if: ${{ needs.check.outputs.next_action == 'update-common' }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PERSONAL_TOKEN }}
- name: gh checkout pr
env:
GH_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
run: gh pr checkout ${{ github.event.issue.number }} --recurse-submodules
- run: git submodule update --remote --merge
- name: Commit Common
run: |
git add .
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "chore: update common"
git push

update-snapshot:
needs: check
runs-on: ubuntu-latest
if: ${{ needs.check.outputs.next_action == 'update-snapshot' }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PERSONAL_TOKEN }}
- name: gh checkout pr
env:
GH_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
run: gh pr checkout ${{ github.event.issue.number }} --recurse-submodules
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm install
- run: npm run test:update
- name: Commit Snapshot
run: |
git add .
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "chore: update snapshot"
git push
Loading