feat: karin-plugin-orchid and karin-plugin-chaite #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Check and Update | |
| on: | |
| pull_request_target: | |
| types: [opened, synchronize] | |
| branches: | |
| - main | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| validate-and-update: | |
| if: | | |
| github.event_name == 'pull_request_target' || | |
| (github.event_name == 'issue_comment' && | |
| contains(github.event.comment.body, '/check') && | |
| github.event.issue.pull_request) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| if: github.event_name == 'issue_comment' | |
| with: | |
| ref: ${{ github.event.comment.pull_request.head.sha }} | |
| - uses: actions/checkout@v4 | |
| if: github.event_name == 'pull_request_target' | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Run validation | |
| id: validate | |
| run: | | |
| npm run validate > validate_output.txt 2>&1 || echo "validate_failed=true" >> $GITHUB_OUTPUT | |
| - name: Copy and update package.json | |
| if: success() | |
| id: copy | |
| run: | | |
| npm run cp | |
| sleep 1 | |
| cat package.json > temp.json | |
| echo "package_content=$(cat temp.json | base64 -w 0)" >> $GITHUB_ENV | |
| - name: Comment results | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const validateOutput = fs.readFileSync('validate_output.txt', 'utf8'); | |
| const validateFailed = '${{ steps.validate.outputs.validate_failed }}' === 'true'; | |
| const header = validateFailed ? '❌ 验证失败' : '✅ 验证通过'; | |
| const triggerType = '${{ github.event_name }}' === 'issue_comment' ? '(通过评论触发)' : '(自动触发)'; | |
| let body = `### ${header} ${triggerType}\n\n<details><summary>验证输出</summary>\n\n\`\`\`\n${validateOutput}\n\`\`\`\n\n</details>`; | |
| if (!validateFailed) { | |
| const packageContent = Buffer.from(process.env.package_content, 'base64').toString('utf-8'); | |
| body += `\n\n### 📦 更新后的 package.json\n\n<details><summary>点击查看内容</summary>\n\n\`\`\`json\n${packageContent}\n\`\`\`\n\n</details>`; | |
| } | |
| await github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }); | |
| if (validateFailed) { | |
| process.exit(1); | |
| } |