GitVersion配置未递增

8
我正在尝试设置 GitVersion 来处理我们项目的语义版本(GitFlow),但它没有按照我期望的方式自动递增。我还在努力阅读该项目的文档,但它不是很易于理解。
基本上,我们希望建立一个主次修订号的版本系统,其中我们手动递增主要版本号,在发布分支合并到主分支时自动递增次要版本号,在功能分支合并到开发分支时自动递增修订号。
这是我的当前 GitVersion.yml 文件:
mode: ContinuousDeployment
branches:
  feature:
    increment: Patch
    regex: feature?[/-]
  release:
    increment: Minor
    regex: release?[/-]
  develop:
    regex: develop$
  master:
    regex: master$
ignore:
  sha: []

我写了一个小的 Ruby 脚本来加速这个繁琐的过程,以测试它。我把它包含进来只是为了确保我正在按照预期的方式使用 GitVersion 和 GitFlow。

require "git"

def new_feature_branch i
  g = Git.open(Dir.pwd)

  branch_name = "feature/number-#{i}"
  g.checkout("develop")
  g.branch(branch_name).checkout

  open('README.md', 'a') do |f|
    f.puts "\r#{i}"
  end

  g.add("README.md")
  g.commit("##{i}")

  g.branch("develop").checkout
  g.merge(branch_name)
  g.branch(branch_name).delete

  print(`gitversion`)
end


new_feature_branch(ARGV[0])

gitversion 的输出结果

{
  "Major":1,
  "Minor":1,
  "Patch":0,
  "PreReleaseTag":"alpha.39",
  "PreReleaseTagWithDash":"-alpha.39",
  "PreReleaseLabel":"alpha",
  "PreReleaseNumber":39,
  "WeightedPreReleaseNumber":39,
  "BuildMetaData":"",
  "BuildMetaDataPadded":"",
  "FullBuildMetaData":"Branch.develop.Sha.57a536a5c6b6abb4313a2067468413447cb49c86",
  "MajorMinorPatch":"1.1.0",
  "SemVer":"1.1.0-alpha.39",
  "LegacySemVer":"1.1.0-alpha39",
  "LegacySemVerPadded":"1.1.0-alpha0039",
  "AssemblySemVer":"1.1.0.0",
  "AssemblySemFileVer":"1.1.0.0",
  "FullSemVer":"1.1.0-alpha.39",
  "InformationalVersion":"1.1.0-alpha.39+Branch.develop.Sha.57a536a5c6b6abb4313a2067468413447cb49c86",
  "BranchName":"develop",
  "Sha":"57a536a5c6b6abb4313a2067468413447cb49c86",
  "ShortSha":"57a536a",
  "NuGetVersionV2":"1.1.0-alpha0039",
  "NuGetVersion":"1.1.0-alpha0039",
  "NuGetPreReleaseTagV2":"alpha0039",
  "NuGetPreReleaseTag":"alpha0039",
  "VersionSourceSha":"27938c50fc6f364eff52bccec8dbc10297bce87b",
  "CommitsSinceVersionSource":39,
  "CommitsSinceVersionSourcePadded":"0039",
  "CommitDate":"2019-10-28"
}

我预期每次将一个功能分支合并到develop分支时,修补程序号都会增加,但事实并非如此。


版本号写在哪里?我猜应该是在某个文件里吧?你用的是哪种语言? - Christoph
我不确定我理解了,你是指 gitversion /version 的输出还是仅指 gitversion 的输出。我编辑了问题以包括后者。 - Ryan Grush
1
你检查过你的有效设置了吗? gitversion /showconfig 我猜想develop:increment可能不是你期望的(补丁)。 - 8DH
1
@8DH 谢谢,我已经根据 OP 更新了配置设置。我的回答下面有当前配置文件,它的工作效果更加符合预期。 - Ryan Grush
2个回答

3

还有一些小问题,但是这个配置设置现在实现的效果更符合我的期望。

mode: Mainline
tag-prefix: '[vV]'
commit-message-incrementing: MergeMessageOnly
branches:
  feature:
    regex: feature?[/-]
    source-branches: ['develop']
  release:
    increment: Minor
    regex: release?[/-]
  develop:
    is-mainline: true
    increment: Patch
    regex: develop$
  master:
    regex: master$

1
a) 这些小问题是什么? b) 我在文档中找不到“MergeMessageOnly” - 你是怎么知道的? - sommmen

1

这并不是一个真正的答案,因为您想要使用gitversion,但也许它展示了一种处理您的问题的不同方式,而且评论区太短了:

  • 将一个名为"pre-commit"的文件放入/.git/hooks/目录下,并包含以下内容
  • 在我们的情况下,我们正在使用R,版本号被“跟踪”在一个名为“DESCRIPTION”的文件中,该文件位于软件包的文件夹中(这就是我要求文件及其名称的原因)。

如果您提交,则补丁会增加+1,次要/主要版本必须手动设置为x+1.0.-1的方式(变成x+1.0.0)。我想您应该能够根据自己的需要调整脚本。

希望这有所帮助。

#!C:/R/R-3.3.0/bin/x64/Rscript

# License: CC0 (just be nice and point others to where you got this)
# Author: Robert M Flight <rflight79@gmail.com>, github.com/rmflight
#
# This is a pre-commit hook that checks that there are files to be committed, and if there are, increments the package version
# in the DESCRIPTION file.
#
# To install it, simply copy this into the ".git/hooks/pre-commit" file of your git repo, change /path/2/Rscript, and make it
# executable. Note that /path/2/Rscript is the same as your /path/2/R/bin/R, or may be in /usr/bin/Rscript depending on your
# installation. This has been tested on both Linux and Windows installations.
#
# In instances where you do NOT want the version incremented, add the environment variable inc=FALSE to your git call.
# eg "inc=FALSE git commit -m "commit message".
# This is useful when you change the major version number for example.

inc <- TRUE # default

# get the environment variable and modify if necessary
tmpEnv <- as.logical(Sys.getenv("inc"))
if (!is.na(tmpEnv)) {
  inc <- tmpEnv
}

# check that there are files that will be committed, don't want to increment version if there won't be a commit
fileDiff <- system("git diff HEAD --name-only", intern = TRUE)

if ((length(fileDiff) > 0) && inc) {

  currDir <- getwd() # this should be the top level directory of the git repo
  currDCF <- read.dcf("DESCRIPTION")
  currVersion <- currDCF[1,"Version"]
  splitVersion <- strsplit(currVersion, ".", fixed = TRUE)[[1]]
  nVer <- length(splitVersion)
  currEndVersion <- as.integer(splitVersion[nVer])
  newEndVersion <- as.character(currEndVersion + 1)
  splitVersion[nVer] <- newEndVersion
  newVersion <- paste(splitVersion, collapse = ".")
  currDCF[1,"Version"] <- newVersion
  currDCF[1, "Date"] <- strftime(as.POSIXlt(Sys.Date()), "%Y-%m-%d")
  write.dcf(currDCF, "DESCRIPTION")
  system("git add DESCRIPTION")
  cat("Incremented package version and added to commit!\n")
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接