Skip to content

Commit 4f38bce

Browse files
authored
Update version-check.yml
1 parent 2267fc1 commit 4f38bce

File tree

1 file changed

+63
-6
lines changed

1 file changed

+63
-6
lines changed

.github/workflows/version-check.yml

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,41 @@ jobs:
5656
console.log(`Using hardcoded current version: ${currentVersion}`);
5757
}
5858
59-
// 获取允许的版本号列表函数
59+
// 版本比较函数
60+
function compareVersions(version1, version2) {
61+
function parseVersion(versionStr) {
62+
const parts = versionStr.split('-');
63+
const versionParts = parts[0].split('.').map(Number);
64+
return {
65+
major: versionParts[0] || 0,
66+
minor: versionParts[1] || 0,
67+
patch: versionParts[2] || 0,
68+
suffix: parts[1] || '',
69+
full: versionStr
70+
};
71+
}
72+
73+
const v1 = parseVersion(version1);
74+
const v2 = parseVersion(version2);
75+
76+
if (v1.major !== v2.major) return v1.major - v2.major;
77+
if (v1.minor !== v2.minor) return v1.minor - v2.minor;
78+
if (v1.patch !== v2.patch) return v1.patch - v2.patch;
79+
80+
// 处理后缀比较(beta < 正式版)
81+
if (v1.suffix && !v2.suffix) return -1;
82+
if (!v1.suffix && v2.suffix) return 1;
83+
if (v1.suffix && v2.suffix) return v1.suffix.localeCompare(v2.suffix);
84+
85+
return 0;
86+
}
87+
88+
// 检查版本是否比当前版本更新
89+
function isNewerVersion(reportedVer, currentVer) {
90+
return compareVersions(reportedVer, currentVer) > 0;
91+
}
92+
93+
// 获取允许的版本号列表函数(仅用于显示支持的版本)
6094
function getAllowedVersions(currentVer, gap) {
6195
function parseVersion(versionStr) {
6296
const parts = versionStr.split('-');
@@ -108,10 +142,28 @@ jobs:
108142
return allowedVersions;
109143
}
110144
111-
// 格式化允许版本号的列表
145+
// 检查版本是否在允许范围内(包括当前版本、较早版本和更新版本)
146+
function isVersionAllowed(reportedVer, currentVer, gap) {
147+
const allowedVersions = getAllowedVersions(currentVer, gap);
148+
149+
// 检查是否在允许的版本列表中
150+
if (allowedVersions.includes(reportedVer)) {
151+
return true;
152+
}
153+
154+
// 检查是否是更新的版本
155+
if (isNewerVersion(reportedVer, currentVer)) {
156+
console.log(`Version ${reportedVer} is newer than current ${currentVer}, allowing it.`);
157+
return true;
158+
}
159+
160+
return false;
161+
}
162+
163+
// 格式化允许版本号的列表(仅显示支持的版本,不包括未来版本)
112164
const allowedVersions = getAllowedVersions(currentVersion, VERSION_GAP);
113165
const formattedAllowedVersions = allowedVersions.map(v => `\`${v}\``).join(', ');
114-
console.log(`Allowed versions: ${JSON.stringify(allowedVersions)}`);
166+
console.log(`Displayed allowed versions: ${JSON.stringify(allowedVersions)}`);
115167
116168
// 获取所有 bot 之前的评论
117169
const comments = await github.rest.issues.listComments({
@@ -190,8 +242,8 @@ jobs:
190242
const reportedVersion = match[1];
191243
console.log(`Reported version: ${reportedVersion}`);
192244
193-
// 检查版本是否在允许的范围内
194-
if (allowedVersions.includes(reportedVersion)) {
245+
// 检查版本是否在允许的范围内(包括更新版本)
246+
if (isVersionAllowed(reportedVersion, currentVersion, VERSION_GAP)) {
195247
console.log('Version is within allowed range. No action needed.');
196248
197249
// 如果 issue 被标记为过时版本或无效格式,但现在版本正确,移除这些标签并重新打开 issue
@@ -225,11 +277,16 @@ jobs:
225277
state: 'open'
226278
});
227279
280+
// 为更新版本添加特殊提示
281+
const isNewer = isNewerVersion(reportedVersion, currentVersion);
282+
const versionNote = isNewer ?
283+
`\n\n**注意:** 您使用的版本 (\`${reportedVersion}\`) 比当前仓库版本更新,我们已接受此报告。\n\n**Note:** You're using a version (\`${reportedVersion}\`) that's newer than the current repository version, and we've accepted this report.` : '';
284+
228285
await github.rest.issues.createComment({
229286
owner: context.repo.owner,
230287
repo: context.repo.repo,
231288
issue_number: issue.number,
232-
body: `## 版本验证通过,问题已重新打开 / Version Verified, Issue Reopened\n\n非常感谢您更新了问题报告!您现在使用的版本 (\`${reportedVersion}\`) 是受支持的版本,我们已自动重新打开这个问题。我们的团队将尽快查看并处理您的反馈。\n\n感谢您对 GTO 项目的支持与贡献!\n\n---\n\nThank you for updating your report! The version you're using now (\`${reportedVersion}\`) is supported, and we've automatically reopened this issue. Our team will review and address your feedback as soon as possible.\n\nWe appreciate your support and contributions to the GTO project!`
289+
body: `## 版本验证通过,问题已重新打开 / Version Verified, Issue Reopened\n\n非常感谢您更新了问题报告!您现在使用的版本 (\`${reportedVersion}\`) 是受支持的版本,我们已自动重新打开这个问题。我们的团队将尽快查看并处理您的反馈。${versionNote}\n\n感谢您对 GTO 项目的支持与贡献!\n\n---\n\nThank you for updating your report! The version you're using now (\`${reportedVersion}\`) is supported, and we've automatically reopened this issue. Our team will review and address your feedback as soon as possible.${versionNote}\n\nWe appreciate your support and contributions to the GTO project!`
233290
});
234291
}
235292

0 commit comments

Comments
 (0)