fix: 修复生成发布说明包含了未打标签提交的问题

This commit is contained in:
augushong
2025-03-29 09:59:05 +08:00
parent c1867d5759
commit 09f6e35793

View File

@@ -223,13 +223,36 @@ class VersionBase extends Command
{
$output = $this->output;
// 如果没有指定起始版本则获取最近的tag
// 获取所有tags按时间倒序排列
$tags = explode("\n", trim(shell_exec('git tag --sort=-creatordate')));
// 如果没有指定起始版本则获取倒数第二个tag
if (empty($fromTag)) {
$fromTag = shell_exec('git describe --tags --abbrev=0');
$fromTag = trim($fromTag);
$output->info('未指定起始版本使用最近的tag: ' . $fromTag);
if (count($tags) < 2) {
$output->error('没有足够的tag来生成发布说明');
return;
}
$fromTag = $tags[1]; // 倒数第二个tag
$toTag = $tags[0]; // 最新的tag
$output->info('未指定起始版本使用倒数第二个tag: ' . $fromTag);
$output->info('到最新tag: ' . $toTag);
} else {
// 如果指定了fromTag找到比fromTag新的最近的tag
$toTag = null;
foreach ($tags as $tag) {
if (version_compare($tag, $fromTag, '>')) {
$toTag = $tag;
break;
}
}
if ($toTag === null) {
$output->error('没有找到比 ' . $fromTag . ' 更新的tag');
return;
}
$output->info('从指定版本开始生成发布说明: ' . $fromTag);
$output->info('到最新tag: ' . $toTag);
}
// 获取当前版本
@@ -238,12 +261,11 @@ class VersionBase extends Command
$currentVersion = static::PRODUCT_VERSION;
}
// 获取从指定tag到现在的所有提交,包含提交哈希和提交日期
$commits = shell_exec("git log {$fromTag}..HEAD --pretty=format:\"%h %ad %s\" --date=short");
// 获取从指定tag到目标tag的所有提交,包含提交哈希和提交日期
$commits = shell_exec("git log {$fromTag}..{$toTag} --pretty=format:\"%h %ad %s\" --date=short");
if (empty($commits)) {
$output->warning('从 ' . $fromTag . ' 到现在没有任何提交');
$output->warning('从 ' . $fromTag . ' 到 ' . $toTag . ' 没有任何提交');
return;
}