GitVersion CLI在GitHub工作流中报错‘No base versions determined’求助
GitVersion计算版本失败排查求助
问题背景
测试仓库无历史标签或发布记录,因GitHub Enterprise上GitVersion Actions未获批准,工作流中手动安装并使用CLI版本工具计算SemVer版本。
执行步骤与错误日志
执行以下命令获取版本:
dotnet-gitversion /diag VERSION=$(dotnet-gitversion /output json /showvariable SemVer)
出现错误日志:
INFO [25-06-25 16:50:46:72] Running against branch: ActionsTestingV2 ('d058042' - ) INFO [25-06-25 16:50:46:75] -< Begin: Fetching the base versions for version calculation... >- INFO [25-06-25 16:50:46:76] -< Begin: Finding branches source of 'ActionsTestingV2' >- INFO [25-06-25 16:50:46:77] -< End: Finding branches source of 'ActionsTestingV2' (Took: 7.76ms) >- INFO [25-06-25 16:50:46:77] An orphaned branch 'ActionsTestingV2' has been detected and will be skipped=True. INFO [25-06-25 16:50:46:77] -< End: Fetching the base versions for version calculation... (Took: 23.04ms) >- INFO [25-06-25 16:50:46:77] ------------------------------------------------------- ERROR [25-06-25 16:50:46:79] An unexpected error occurred: GitVersion.GitVersionException: No base versions determined on the current branch.
已尝试操作
- 检出仓库时配置完整深度与标签拉取:
- name: Checkout repo code uses: actions/checkout@v3 with: fetch-depth: 0 fetch-tags: true
- 手动创建首个标签,问题未解决
- 搜索该错误无有效结果
当前仓库仅存在测试分支ActionsTestingV2,工作流与GitVersion配置均在此分支。
GitVersion.yml配置
commit-message-incrementing: Enabled major-version-bump-message: '^.*!:.*' # e.g. "feat!: big change" → major minor-version-bump-message: '^feat(\(.+\))?:' # e.g. "feat: add X" → minor patch-version-bump-message: '^fix(\(.+\))?:' # e.g. "fix: bug Y" → patch branches: main: regex: ^testing-main$ label: '' increment: None is-main-branch: true # Testing branches (any name containing "RCTEST") → "rc" pre-release testing: regex: .*RCTEST.* label: rc increment: Inherit is-main-branch: false # Feature or bugfix branches → "alpha" pre-release other: regex: .* label: alpha increment: Inherit is-main-branch: false ignore: sha: []
原因分析
- 孤儿分支导致基础版本无法获取:当前分支
ActionsTestingV2是仓库唯一分支,无上游分支或关联主分支,被GitVersion标记为孤儿分支,跳过基础版本检索。 - 分支增量策略无继承源:该分支匹配
other规则,increment: Inherit需要从主分支或父分支继承基础版本,但仓库无其他分支,导致无版本可继承。 - 标签未被正确识别:手动创建的标签若不符合GitVersion默认格式(如未加
v前缀),或未关联到当前分支提交历史,无法作为基础版本。
解决方法
方法1:调整分支配置,指定增量策略
修改GitVersion.yml,为ActionsTestingV2添加单独分支规则,或修改other分支的增量策略:
branches: # 为测试分支添加单独规则 actions-test: regex: ^ActionsTestingV2$ label: alpha increment: Minor # 无基础版本时从0.1.0开始增量 is-main-branch: false # 保留原有规则...
或直接修改other分支的增量设置:
other: regex: .* label: alpha increment: Minor # 替换Inherit为Minor/Patch/Major is-main-branch: false
方法2:设置初始版本
在GitVersion.yml中添加next-version字段,强制指定初始版本:
next-version: 1.0.0 # GitVersion会基于此版本进行增量计算
方法3:规范标签格式并关联分支
确保标签带有v前缀(GitVersion默认识别格式),并打在当前分支的提交上:
git tag v1.0.0 d058042 # 替换d058042为当前分支的提交SHA git push origin v1.0.0
方法4:将当前分支设为主分支
修改GitVersion.yml中main分支的正则匹配规则,让ActionsTestingV2被识别为主分支:
branches: main: regex: ^ActionsTestingV2$ # 修改正则匹配当前分支 label: '' increment: None is-main-branch: true
内容的提问来源于stack exchange,提问作者pfinferno
相关产品推荐
相关产品推荐

