Skip to content

fix: switch GitVersion to ContinuousDelivery mode

Placeholder Copilot requested to merge copilot/update-gitversion-mode into main

ContinuousDeployment + tag: '' causes GitVersion to emit a clean version (e.g. 1.2.5) on every untagged main commit, making it impossible to distinguish released from unreleased builds.

Change

# GitVersion.yml
mode: ContinuousDelivery  # was: ContinuousDeployment

ContinuousDelivery mode preserves tag: '' semantics while appending build metadata to untagged commits:

State Before After
Untagged commit on main 1.2.5 ❌ 1.2.5+3 → Docker: 1.2.5-3 ✅
Tagged commit (v1.2.5) 1.2.5 ✅ 1.2.5 ✅
Original prompt

Problem

Currently GitVersion.yml uses mode: ContinuousDeployment with tag: '' on the main branch. This causes GitVersion to produce a clean version like 1.2.5 even when the 1.2.5 tag has not been created yet (the latest tag is 1.2.4). The expected behavior is that untagged commits should produce a version with build metadata like 1.2.5+3, and only produce a clean 1.2.5 when the tag is actually created.

Fix

In GitVersion.yml, change mode from ContinuousDeployment to ContinuousDelivery. Everything else stays the same.

Before:

mode: ContinuousDeployment
tag-prefix: '[vV]?'
branches:
  main:
    regex: ^main$
    tag: ''
    increment: Patch

After:

mode: ContinuousDelivery
tag-prefix: '[vV]?'
branches:
  main:
    regex: ^main$
    tag: ''
    increment: Patch

This single-line change ensures:

  • Untagged commits on main produce versions like 1.2.5+3 (with build metadata)
  • Only when the 1.2.5 tag is actually created will GitVersion output a clean 1.2.5

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: 目前gitversion產生了是1.2.5,但是目前還沒tag 1.2.5,应该错的。分析一下,应该是1.2.5-xxx之類的才對。

Assistant:

Let me look at the failing job logs and understand the GitVersion configuration.

Assistant: 找到根本原因了。問題出在你的 GitVersion.yml 配置。

問題分析

你目前最新的 tag 是 1.2.4(發佈於 2026-04-13),還沒有 1.2.5 tag。當 main 上有新 commit(在 1.2.4 之後),GitVersion 應該產生類似 1.2.5-ci.3 這樣的 pre-release 版號,但它卻直接產生了 1.2.5。

根因:tag: ''(空字串)

mode: ContinuousDeployment
tag-prefix: '[vV]?'
branches:
  main:
    regex: ^main$
    tag: ''
    increment: Patch

在 GitVersion 中,tag: ''(空字串)的意思是:不加任何 pre-release 標籤。這代表 GitVersion 在 main 分支上會直接產出乾淨的 1.2.5,即便還沒有這個 tag 存在。

這是 ContinuousDeployment mode 的特性——它會自動遞增版號。搭配 tag: '',就等於告訴 GitVersion:「main 上的每個 commit 都是正式版本」,所以 1.2.4 之後的下一個 commit 直接變成 1.2.5。

修正方式

如果你希望在 tag 1.2.5 真正打上去之前,版號帶有 pre-release 後綴(如 1.2.5-ci.3),有兩種做法:

方案 A:改 tag 為非空字串(推薦)

mode: ContinuousDeployment
tag-prefix: '[vV]?'
branches:
  main:
    regex: ^main$
    tag: ci
    increment: Patch

這樣 GitVersion 會產生:1.2.5-ci.1、1.2.5-ci.2、1.2.5-ci.3...
直到你真正打了 1.2.5 tag 時,才會輸出乾淨的 1.2.5。

方案 B:改用 ContinuousDelivery mode

mode: ContinuousDelivery
tag-prefix: '[vV]?'
branches:
  main:
    regex: ^main$
    tag: ''
    increment: Patch

在 ContinuousDelivery 模式下,即便 tag: '',GitVersion 也會在未打 tag 的 commit 上產生帶有 +N metadata 的版號(如 1.2.5+3),不過 + 在 Docker tag 中會被你的 workflow 替換成 -,變成 1.2.5-3。

兩種模式的差異

ContinuousDeployment ContinuousDelivery
理念 每個 commit 都可能直接部署 版本由人工打 tag 決定
tag: '' 行為 直接給乾淨版號(1.2.5)← 你目前的問題 給帶 metadata 的版號(1.2.5+3)
tag: 'ci' 行為 給 1.2.5-ci.3 給 1.2.5-ci.3

建議

如果你的流程是「先合併到 main → CI 產 Docker image → 確認沒問題後手動打 tag 做正式 release」,那 方案 A(tag: ci)最符合你的需求。這樣 Docker image 會被標記為 1.2.5-ci.3,等到你打了 1.2.5 tag 後再觸發一次 CI,才會產生真正的 1.2.5 image。

需要我幫你開一個 PR 來修正這個 GitVersion.yml 嗎?

User: 流程是你说的对的。但是我想这种格式:給帶 metadata 的版號(1.2.5+3)

Assistant:

所以你想要的是:

  • 未打 tag 時:1.2.5+3(Docker tag 會變成 1.2.5-3)
  • 打了 tag 時:乾淨的 1.2.5

那就是 方案 B:改用 ContinuousDelivery mode,保持 tag: '' 不變。

mode: ContinuousDelivery
tag-prefix: '[vV]?'
branches:
  main:
    regex: ^main$
    tag: ''
    increment: Patch

唯一的改動就是 mode: ContinuousDeployment → mode: ContinuousDelivery。

需要我幫你開 PR 嗎?

User: 需要

Assistant:

Let me first check the failing job to understand the current state, then create the PR.

Assistant: We're waiting for your confirmation to proceed with creating the pull request. Please accept or reject the pending tool call to continue.

This pull request was created from Copilot chat.

Merge request reports

Loading