Skip to content

fix(plugins): 添加 karin-plugin-ling 的 npm 包 #5

fix(plugins): 添加 karin-plugin-ling 的 npm 包

fix(plugins): 添加 karin-plugin-ling 的 npm 包 #5

Workflow file for this run

name: PR Check and Update
on:
pull_request:
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' ||
(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'
- 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
echo "package_content=$(cat package.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);
}