Enhance release workflow with auto-release on merge and PR validation

Co-authored-by: Fu-Jie <33599649+Fu-Jie@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-31 12:06:31 +00:00
parent 10bddd2026
commit 5b8750c438
4 changed files with 457 additions and 196 deletions

View File

@@ -7,7 +7,9 @@
# What it does:
# 1. Compares plugin versions between base and head branches
# 2. Generates a summary of version changes
# 3. Comments on the PR with the changes (optional)
# 3. Comments on the PR with the changes
# 4. FAILS the check if plugin files are modified but no version update is detected
# (enforces version bump requirement for plugin changes)
name: Plugin Version Check / 插件版本检查
@@ -82,16 +84,54 @@ jobs:
echo 'EOF'
} >> $GITHUB_OUTPUT
- name: Comment on PR
- name: Check PR description for update notes
id: check_description
if: steps.compare.outputs.has_changes == 'true'
uses: actions/github-script@v7
with:
script: |
const prBody = context.payload.pull_request.body || '';
// Check if PR has meaningful description (at least 20 characters, excluding whitespace)
// Use [\s\S]*? for multiline HTML comment matching (compatible across JS engines)
const cleanBody = prBody.replace(/\s+/g, '').replace(/<!--[\s\S]*?-->/g, '');
const hasDescription = cleanBody.length >= 20;
console.log(`PR body length (cleaned): ${cleanBody.length}`);
console.log(`Has meaningful description: ${hasDescription}`);
core.setOutput('has_description', hasDescription.toString());
return hasDescription;
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const hasChanges = '${{ steps.compare.outputs.has_changes }}' === 'true';
const hasDescription = '${{ steps.check_description.outputs.has_description }}' === 'true';
const changes = `${{ steps.compare.outputs.changes }}`;
const body = `## 🔍 Plugin Version Changes / 插件版本变化
let statusIcon = '';
let statusMessage = '';
${changes}
if (hasChanges && hasDescription) {
statusIcon = '✅';
statusMessage = '版本更新检测通过PR 包含版本变化和更新说明。\n\nVersion check passed! PR contains version changes and update description.';
} else if (hasChanges && !hasDescription) {
statusIcon = '⚠️';
statusMessage = '检测到版本更新,但 PR 描述过短。请在 PR 描述中添加更新说明(至少 20 个字符)。\n\nVersion update detected, but PR description is too short. Please add update notes in PR description (at least 20 characters).';
} else {
statusIcon = '❌';
statusMessage = '未检测到版本更新!修改插件文件时必须更新版本号。\n\nNo version update detected! You must update the version number when modifying plugin files.';
}
const body = `## ${statusIcon} Plugin Version Check / 插件版本检查
${statusMessage}
---
${hasChanges ? `### 版本变化 / Version Changes\n\n${changes}` : ''}
---
*This comment was generated automatically. / 此评论由自动生成。*
@@ -106,11 +146,10 @@ jobs:
const botComment = comments.find(comment =>
(comment.user.login === 'github-actions[bot]' || comment.user.type === 'Bot') &&
comment.body.includes('Plugin Version Changes')
comment.body.includes('Plugin Version Check')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
@@ -118,7 +157,6 @@ jobs:
body: body,
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
@@ -127,6 +165,36 @@ jobs:
});
}
- name: Enforce version update requirement
if: steps.compare.outputs.has_changes == 'false'
run: |
echo "::error::❌ 未检测到版本更新!修改插件文件时必须更新版本号。"
echo "::error::No version update detected! You must update the version number when modifying plugin files."
echo ""
echo "请在插件文件的 docstring 中更新版本号:"
echo "Please update the version in your plugin's docstring:"
echo ""
echo '"""'
echo 'title: Your Plugin'
echo 'version: 0.2.0 # <- 更新此处 / Update this'
echo '...'
echo '"""'
exit 1
- name: Enforce PR description requirement
if: steps.compare.outputs.has_changes == 'true' && steps.check_description.outputs.has_description == 'false'
run: |
echo "::error::⚠️ PR 描述过短!请添加更新说明。"
echo "::error::PR description is too short! Please add update notes."
echo ""
echo "请在 PR 描述中添加以下内容:"
echo "Please add the following to your PR description:"
echo ""
echo "- 更新了哪些功能 / What features were updated"
echo "- 修复了哪些问题 / What issues were fixed"
echo "- 其他重要变更 / Other important changes"
exit 1
- name: Summary
run: |
echo "## 🔍 Plugin Version Check Results" >> $GITHUB_STEP_SUMMARY
@@ -136,6 +204,11 @@ jobs:
echo "✅ **Version changes detected!**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cat changes.md >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check_description.outputs.has_description }}" = "true" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ **PR description check passed!**" >> $GITHUB_STEP_SUMMARY
fi
else
echo " **No version changes detected.**" >> $GITHUB_STEP_SUMMARY
echo " **No version changes detected - check failed!**" >> $GITHUB_STEP_SUMMARY
fi