GitVersion配置未递增
我正在尝试设置以处理项目的语义版本控制(GitFlow),但它并没有像我预期的那样自动递增。我还在努力阅读项目的文档,这不是最容易理解的 基本上,我们希望用Major.Minor.Patch约定建立一个版本控制系统,在这里我们手动增加Major,在发布分支合并到master时自动增加Minor,在功能分支合并到develope时自动增加Patch 这是我当前的GitVersion配置未递增,git,git-flow,semantic-versioning,gitversion,Git,Git Flow,Semantic Versioning,Gitversion,我正在尝试设置以处理项目的语义版本控制(GitFlow),但它并没有像我预期的那样自动递增。我还在努力阅读项目的文档,这不是最容易理解的 基本上,我们希望用Major.Minor.Patch约定建立一个版本控制系统,在这里我们手动增加Major,在发布分支合并到master时自动增加Minor,在功能分支合并到develope时自动增加Patch 这是我当前的GitVersion.yml mode: ContinuousDeployment branches: feature: in
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时,补丁号都会增加,但这并没有发生。这并不是一个真正的答案,因为您想使用gitversion,但它可能显示了一种不同的方法来处理您的问题,而且它太长,无法发表评论:
- 在
/.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")
}
#!C:/R/R-3.3.0/bin/x64/Rscript
#许可证:CC0(友好一点,告诉别人你从哪里得到这个)
#作者:Robert M Flight,github.com/rmflight
#
#这是一个预提交钩子,用于检查是否有要提交的文件,如果有,则增加包版本
#在描述文件中。
#
#要安装它,只需将其复制到git repo的“.git/hooks/pre-commit”文件中,更改/path/2/Rscript,并使其生效
#可执行文件。请注意,/path/2/Rscript与/path/2/R/bin/R相同,或者可能位于/usr/bin/Rscript中,具体取决于您的
#安装。这已经在Linux和Windows安装上进行了测试。
#
#在不希望版本增加的情况下,将环境变量inc=FALSE添加到git调用中。
#例如“inc=FALSE git commit-m”commit message。
#例如,当您更改主版本号时,这非常有用。
inc仍然存在一些小问题,但此配置设置的工作效果比我预期的要好得多
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$
版本号写在哪里?我猜它在某个文件中?你使用哪种语言?我不确定我是否理解,你是指gitversion/version
的输出还是仅指gitversion
的输出。我编辑了问题以包括后者。你检查了有效设置了吗?gitversion/showconfig
我很抱歉essing the develop:increment可能不是您所期望的(补丁)。@8DH谢谢,我已经更新了配置设置,因为OP。我下面的答案是当前的配置文件,比预期的工作得更多。