-
Notifications
You must be signed in to change notification settings - Fork 11
214 lines (181 loc) · 8.25 KB
/
plugin-version-check.yml
File metadata and controls
214 lines (181 loc) · 8.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# GitHub Actions Workflow for Plugin Version Change Detection
# 插件版本变化检测工作流
#
# This workflow detects version changes in plugins when PRs are created or updated.
# 此工作流在创建或更新 PR 时检测插件的版本变化。
#
# 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
# 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 / 插件版本检查
on:
pull_request:
branches:
- main
paths:
- 'plugins/**/*.py'
permissions:
contents: read
pull-requests: write
jobs:
check-versions:
runs-on: ubuntu-latest
steps:
- name: Checkout PR head
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
path: head
- name: Checkout base branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Extract and compare versions
id: compare
run: |
# Extract base versions
cd base
if [ -f scripts/extract_plugin_versions.py ]; then
python scripts/extract_plugin_versions.py --json --output ../base_versions.json
else
# Fallback if script doesn't exist in base
echo "[]" > ../base_versions.json
fi
cd ..
# Extract head versions
cd head
python scripts/extract_plugin_versions.py --json --output ../head_versions.json
# Compare versions
python scripts/extract_plugin_versions.py --compare ../base_versions.json --output ../changes.md
cd ..
echo "=== Version Changes ==="
cat changes.md
# Check if there are any changes
if grep -q "No changes detected" changes.md; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
# Store changes for comment
{
echo 'changes<<EOF'
cat changes.md
echo 'EOF'
} >> $GITHUB_OUTPUT
- 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 }}`;
let statusIcon = '';
let statusMessage = '';
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. / 此评论由自动生成。*
`;
// Find existing comment from github-actions bot
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
(comment.user.login === 'github-actions[bot]' || comment.user.type === 'Bot') &&
comment.body.includes('Plugin Version Check')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body,
});
}
- 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
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.compare.outputs.has_changes }}" = "true" ]; then
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 - check failed!**" >> $GITHUB_STEP_SUMMARY
fi