如何使用gitversion修正错误后自动增加补丁版本

时间:2019-05-08 08:44:18

标签: git versioning git-flow gitversion

摘要

我正在建立一个新项目,并希望使用GitVersion计算我的应用程序的当前版本。我需要的是使用MAJOR.MINOR.PATCH进行语义版本控制,其中MAJOR和MINOR随发行分支名称而增加,而PATCH在每次错误修正或修补程序合并时都会增加。

目前,我正在尝试将GitFlow实施到我的分支策略中,但我将向您解释我在做什么。

  1. 所有开发都是在 develop 分支上完成的(创建 feature / * 分支并合并回 develop
  2. 当我要创建发行版时,我从 develop
  3. 创建一个 releases / [version] 分支
  4. 当我在发行版中发现错误时,我会创建一个 bugfix / * 分支,并在完成后将其合并回 release / [version] 中。
  5. 如果找不到更多错误,则 releases / [version] 将被合并到master中并用正确的版本标记。

问题位于步骤3中。例如,当我在 releases / 0.1.0 上时,在 bugfix / * 合并后,GitVersion不会增加PATCH版本。它只是停留在0.1.0而不是想要的0.1.1。它确实增加了提交计数!

到目前为止已采取的步骤

目前,我正在使用以下gitversion.yml文件(请参阅下一个标题)。其中包括一个应该增加PATCH的修补程序分支。出于某些原因,在创建 bugfix / * 分支后,当您在bugfix分支上运行GitVersion时,它不会增加PATCH,因此我认为这里缺少一些内容。

唯一有效的方法是在 bugfix / * 分支的最后一次提交上为新版本(0.1.1-test)设置标签。但是由于GitVersion在bugfix分支上计算版本0.1.0,所以我无法自动升级PATCH并在提交上添加所需的0.1.1-test标签。

我还认为,当您合并回发行分支时,GitVersion将增加版本。但是即使我将增量设置为Patch也不会发生。因此,在这里,我还以为我错过了一些东西,或者我只想要GitVersion并非为之准备的东西。

gitversion.yml

assembly-versioning-scheme: MajorMinorPatch
mode: ContinuousDeployment
branches:
  develop:
    tag: ''
  feature:
    tag: ''
  release:
    tag: test
    increment: Patch
    tracks-release-branches: true
    source-branches:
    - develop
    - bugfix
  bugfix:
    tag: ''
    increment: Patch
    prevent-increment-of-merged-branch-version: false
    regex: bugfix(es)?[/-]
    source-branches:
    - release
ignore:
  sha: []

预期结果

当我将 bugfix / * 分支合并回我的 releases / [version] 分支时,我希望增加PATCH。

示例:

7f8ef13 34 minutes ago  (HEAD -> releases/0.1.0) [3]
|\
| * 3363677 34 minutes ago  (bugfix/TE-01) [2]
|/
* ac22ccb 36 minutes ago  (tag: 0.1.0-test, master, develop) [1]

[1]至此,我创建了releases / 0.1.0分支,因此GitVersion应该计算0.1.0(有效!)

[2]这里的版本并不重要,因此可以保留0.1.0-bug

[3]因为我们有一个错误修正合并,因此这里的版本需要增加到0.1.1。 (这没有发生!)。目前,它保持为0.1.0,但确实会增加提交计数。因此它将在[1]和[3]之间从0.1.0-test.0变为0.1.0-test.2。

也许我正在尝试做一些甚至不可能的事情,我真的不知道。因此,如果有任何想法,请随时回复:)

我也知道默认情况下,GitFlow没有错误修正分支。但是我认为直接在发行分支上修复错误是一个奇怪的主意。特别是在较大的团队中工作时。这就是为什么我试图创建一个错误修正流。

完整gitversion -diag输出

C:\Testig gitversion>gitversion -diag
INFO [05/08/19 10:38:53:79] Dumping commit graph:
INFO [05/08/19 10:38:53:90] *   7f8ef13 49 minutes ago  (HEAD -> releases/0.1.0)
|\
| * 3363677 49 minutes ago  (bugfix/TE-01)
|/
* ac22ccb 50 minutes ago  (tag: 0.1.0-test, master, develop)

INFO [05/08/19 10:38:53:90] Working directory: C:\Testig gitversion
INFO [05/08/19 10:38:53:91] IsDynamicGitRepository: False
INFO [05/08/19 10:38:53:93] Returning Project Root from DotGitDirectory: C:\Testig gitversion\.git - C:\Testig gitversion
INFO [05/08/19 10:38:53:94] Running on Windows.
INFO [05/08/19 10:38:53:94] IsDynamicGitRepository: False
INFO [05/08/19 10:38:53:94] Returning Project Root from DotGitDirectory: C:\Testig gitversion\.git - C:\Testig gitversion
INFO [05/08/19 10:38:53:94] Project root is: C:\Testig gitversion
INFO [05/08/19 10:38:53:94] DotGit directory is: C:\Testig gitversion\.git
INFO [05/08/19 10:38:53:95] IsDynamicGitRepository: False
INFO [05/08/19 10:38:53:95] Returning Project Root from DotGitDirectory: C:\Testig gitversion\.git - C:\Testig gitversion
INFO [05/08/19 10:38:53:98] IsDynamicGitRepository: False
INFO [05/08/19 10:38:53:98] Returning Project Root from DotGitDirectory: C:\Testig gitversion\.git - C:\Testig gitversion
INFO [05/08/19 10:38:54:07] Using latest commit on specified branch
INFO [05/08/19 10:38:54:08] Running against branch: releases/0.1.0 (7f8ef13e5f43d3827d30a25f936424210cefb2c8)
INFO [05/08/19 10:38:54:09] Begin: Calculating base versions
  INFO [05/08/19 10:38:54:10] Fallback base version: 0.1.0 with commit count source ac22ccb4dd8937a5ec46ad1504281aee490b4411 (Incremented: None)
  INFO [05/08/19 10:38:54:15] Git tag '0.1.0-test': 0.1.0-test with commit count source ac22ccb4dd8937a5ec46ad1504281aee490b4411 (Incremented: 0.1.0-test)
  INFO [05/08/19 10:38:54:17] Begin: Finding branch source of 'releases/0.1.0'
    INFO [05/08/19 10:38:54:18] Begin: Finding merge base between 'releases/0.1.0' and 'develop'.
      INFO [05/08/19 10:38:54:19] Found merge base of ac22ccb4dd8937a5ec46ad1504281aee490b4411
      INFO [05/08/19 10:38:54:19] Merge base of releases/0.1.0' and 'develop is ac22ccb4dd8937a5ec46ad1504281aee490b4411
    INFO [05/08/19 10:38:54:19] End: Finding merge base between 'releases/0.1.0' and 'develop'. (Took: 5.00ms)
    INFO [05/08/19 10:38:54:19] Begin: Finding merge base between 'releases/0.1.0' and 'master'.
      INFO [05/08/19 10:38:54:19] Found merge base of ac22ccb4dd8937a5ec46ad1504281aee490b4411
      INFO [05/08/19 10:38:54:19] Merge base of releases/0.1.0' and 'master is ac22ccb4dd8937a5ec46ad1504281aee490b4411
    INFO [05/08/19 10:38:54:19] End: Finding merge base between 'releases/0.1.0' and 'master'. (Took: 0.96ms)
    INFO [05/08/19 10:38:54:19] Begin: Finding merge base between 'releases/0.1.0' and 'releases/0.1.0'.
      INFO [05/08/19 10:38:54:19] Found merge base of 7f8ef13e5f43d3827d30a25f936424210cefb2c8
      INFO [05/08/19 10:38:54:19] Merge base of releases/0.1.0' and 'releases/0.1.0 is 7f8ef13e5f43d3827d30a25f936424210cefb2c8
    INFO [05/08/19 10:38:54:19] End: Finding merge base between 'releases/0.1.0' and 'releases/0.1.0'. (Took: 1.00ms)
    INFO [05/08/19 10:38:54:20] Multiple source branches have been found, picking the first one (develop).
This may result in incorrect commit counting.
Options were:
 develop, master
  INFO [05/08/19 10:38:54:25] End: Finding branch source of 'releases/0.1.0' (Took: 85.80ms)
  INFO [05/08/19 10:38:54:33] Version in branch name: 0.1.0 with commit count source ac22ccb4dd8937a5ec46ad1504281aee490b4411 (Incremented: None)
  INFO [05/08/19 10:38:54:35] Begin: Finding merge base between 'releases/0.1.0' and 'releases/0.1.0'.
    INFO [05/08/19 10:38:54:38] Found merge base of 7f8ef13e5f43d3827d30a25f936424210cefb2c8
    INFO [05/08/19 10:38:54:42] Merge base of releases/0.1.0' and 'releases/0.1.0 is 7f8ef13e5f43d3827d30a25f936424210cefb2c8
  INFO [05/08/19 10:38:54:45] End: Finding merge base between 'releases/0.1.0' and 'releases/0.1.0'. (Took: 106.84ms)
  INFO [05/08/19 10:38:54:47] Git tag '0.1.0-test': 0.1.0-test with commit count source ac22ccb4dd8937a5ec46ad1504281aee490b4411 (Incremented: 0.1.0-test)
  INFO [05/08/19 10:38:54:49] Found multiple base versions which will produce the same SemVer (0.1.0), taking oldest source for commit counting (Version in branch name)
  INFO [05/08/19 10:38:54:53] Base version used: Version in branch name: 0.1.0 with commit count source ac22ccb4dd8937a5ec46ad1504281aee490b4411 (Incremented: None)
INFO [05/08/19 10:38:54:53] End: Calculating base versions (Took: 448.82ms)
INFO [05/08/19 10:38:54:58] Skipping version increment
INFO [05/08/19 10:38:54:60] 2 commits found between ac22ccb4dd8937a5ec46ad1504281aee490b4411 and 7f8ef13e5f43d3827d30a25f936424210cefb2c8
INFO [05/08/19 10:38:54:64] Begin: Getting version tags from branch 'refs/heads/releases/0.1.0'.
INFO [05/08/19 10:38:54:68] End: Getting version tags from branch 'refs/heads/releases/0.1.0'. (Took: 46.60ms)

最后,您会看到它正在跳过版本增量。但是我不知道为什么。

1 个答案:

答案 0 :(得分:0)

这可能是由于GitVersion任务中的错误。

我在GitVersion任务v5.0.1中遇到了类似的错误,该任务是Azure DevOps Pipeline中的默认版本。无论我使用master分支做什么,GitVersion每次都给我相同的版本。我的策略是主线

在此任务设置中,我使用了this版的GitVersion,称为UseGitVersion:

# Temporary fix to update GitVersionProperly
- task: UseGitVersion@5
  inputs:
    versionSpec: '0.0.0'

此安装程序安装了GitVersion任务工具的v5.1.2,并且可以产生正确的版本控制,或者至少根据我的期望和对该过程的理解。