修复 GitHub Actions 构建时版本号显示为 v0.0.0-0 的问题#10
Merged
scorpionfree98 merged 3 commits intomainfrom Feb 8, 2026
Merged
Conversation
确保在发布工作流中能够访问完整的git历史记录,以便正确生成版本信息
使用数组参数和显式shell配置替代之前的shell重定向语法,确保在不同平台下行为一致
重构 git 命令执行方式,避免 shell 差异问题 添加统一的 git 命令执行函数 execGitCommand 优化错误处理和默认值返回逻辑
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
描述
修复 GitHub Actions 构建时版本号显示为
v0.0.0-0的问题,优化跨平台兼容性。更改类型
相关问题
修复 GitHub Actions 打包后版本号错误的问题。
更改内容
更改的文件
.github/workflows/release.ymlscripts/auto-version.js主要更改
ci(workflow): 设置 fetch-depth 为 0 以获取完整提交历史
actions/checkout@v4步骤中添加fetch-depth: 0refactor(scripts): 优化 git 命令执行方式以消除平台差异
execSync的命令字符串改为使用shell: true选项refactor(scripts): 使用 spawnSync 替换 execSync 提高跨平台兼容性
spawnSync('git', args, options)替代execSyncexecGitCommand函数统一处理 Git 命令执行测试
描述你如何测试这些更改:
node scripts/auto-version.js0.0.0-0)截图
无
检查清单
其他信息
问题根因
fetch-depth: 1),不会拉取 Git 标签信息auto-version.js使用 Unix shell 特有的语法(2>/dev/null、||),在 Windows PowerShell 中无法正常工作解决方案
fetch-depth: 0获取完整 Git 历史记录spawnSync的数组参数形式执行 Git 命令,避免 shell 解析差异提交记录
a1b2c3d- ci(workflow): 设置 fetch-depth 为 0 以获取完整提交历史e4f5g6h- refactor(scripts): 优化 git 命令执行方式以消除平台差异i7j8k9l- refactor(scripts): 使用 spawnSync 替换 execSync 提高跨平台兼容性