-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for customizing tag formats #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,14 @@ | |
in a previous build in a GitInfo.cache for | ||
performance reasons. | ||
Defaults to empty value (no ignoring). | ||
|
||
$(GitTagRegex): Regular Experssion used with git describe to find the BaseTag | ||
Defaults to * (all) | ||
|
||
$(GitBaseVersionExpr): Regular Experssion used with git describe to find the BaseTag | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The versions are semver2, I don't think we need to make the regex customizable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're referring to making the GitBaseVersionExpr public instead of private, I do think you should allow user customization. As written, the _GitBaseVersionExpr catches any tag with a semver2 version embedded. Customizing it would allow us to be more specific about the format of the actual tag that we would consider as a "valid" version tag. |
||
Defaults to '^v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^(?<LABEL>[\dA-Za-z\-\.]+)\-v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)$' | ||
|
||
|
||
|
||
============================================================== | ||
--> | ||
|
@@ -82,6 +90,8 @@ | |
<SkipWriteGitCache Condition="'$(SkipWriteGitCache)' == ''">$(GitSkipCache)</SkipWriteGitCache> | ||
|
||
<GitMinVersion>2.5.0</GitMinVersion> | ||
<GitBaseVersionExpr Condition="'$(GitBaseVersionExpr)' == ''">^v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^(?<LABEL>[\dA-Za-z\-\.]+)\-v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)$</GitBaseVersionExpr> | ||
<GitTagRegex Condition="'$(GitTagRegex)' == ''">*</GitTagRegex> | ||
</PropertyGroup> | ||
|
||
<!-- Private properties --> | ||
|
@@ -93,8 +103,6 @@ | |
GitInfoReport; | ||
$(CoreCompileDependsOn) | ||
</CoreCompileDependsOn> | ||
|
||
<_GitBaseVersionExpr Condition="'$(_GitBaseVersionExpr)' == ''">^v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^(?<LABEL>[\dA-Za-z\-\.]+)\-v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)$</_GitBaseVersionExpr> | ||
<!-- Cache file used to avoid running all git commands. Only GitRoot will be retrieved to determine the path of this cache file. --> | ||
<_GitInfoFile>$(IntermediateOutputPath)GitInfo.cache</_GitInfoFile> | ||
</PropertyGroup> | ||
|
@@ -440,12 +448,12 @@ | |
<GitBaseVersion>$([System.IO.File]::ReadAllText('$(GitVersionFile)'))</GitBaseVersion> | ||
<GitBaseVersion>$(GitBaseVersion.Trim())</GitBaseVersion> | ||
<IsValidGitBaseVersion> | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBaseVersion), $(_GitBaseVersionExpr))) | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBaseVersion), $(GitBaseVersionExpr))) | ||
</IsValidGitBaseVersion> | ||
<IsValidGitBaseVersion>$(IsValidGitBaseVersion.Trim())</IsValidGitBaseVersion> | ||
</PropertyGroup> | ||
|
||
<Error Text="$(GitVersionFile) does not contain a valid base version (found '$(GitBaseVersion)', regex: $(_GitBaseVersionExpr))." | ||
<Error Text="$(GitVersionFile) does not contain a valid base version (found '$(GitBaseVersion)', regex: $(GitBaseVersionExpr))." | ||
Condition="'$(IsValidGitBaseVersion)' == 'False'" /> | ||
|
||
<PropertyGroup> | ||
|
@@ -524,7 +532,7 @@ | |
|
||
<PropertyGroup> | ||
<IsValidGitBaseVersion> | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBranch), $(_GitBaseVersionExpr))) | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBranch), $(GitBaseVersionExpr))) | ||
</IsValidGitBaseVersion> | ||
<IsValidGitBaseVersion>$(IsValidGitBaseVersion.Trim())</IsValidGitBaseVersion> | ||
</PropertyGroup> | ||
|
@@ -579,7 +587,7 @@ | |
DependsOnTargets="_GitBranch;_GitCommit" | ||
Condition="'$(GitBaseVersion)' == '' And '$(GitIgnoreTagVersion)' != 'true' "> | ||
|
||
<Exec Command='$(GitExe) describe --tags --abbrev=0' | ||
<Exec Command='$(GitExe) describe --tags --match=$(GitTagRegex) --abbrev=0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The answer is, I really don't know for sure (I don't really have a good way to test on my side). I suspect it does. This question was the impetus behind adding a second regex rather than just using the _GitBaseVersionExpr. |
||
EchoOff='true' | ||
StandardErrorImportance="low" | ||
StandardOutputImportance="low" | ||
|
@@ -608,7 +616,7 @@ | |
Condition="'$(GitBaseVersion)' == '' And '$(GitIgnoreTagVersion)' != 'true' And '$(GitBaseTag)' != ''"> | ||
|
||
<!-- At this point, we now there is a base tag already we can leverage --> | ||
<Exec Command='$(GitExe) describe --tags' | ||
<Exec Command='$(GitExe) describe --match=$(GitTagRegex) --tags' | ||
EchoOff='true' | ||
StandardErrorImportance="low" | ||
StandardOutputImportance="low" | ||
|
@@ -621,7 +629,7 @@ | |
|
||
<PropertyGroup> | ||
<IsValidGitBaseVersion> | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBaseTag), $(_GitBaseVersionExpr))) | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBaseTag), $(GitBaseVersionExpr))) | ||
</IsValidGitBaseVersion> | ||
<IsValidGitBaseVersion>$(IsValidGitBaseVersion.Trim())</IsValidGitBaseVersion> | ||
|
||
|
@@ -677,7 +685,7 @@ | |
|
||
<PropertyGroup> | ||
<IsValidGitDefaultVersion> | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitDefaultVersion), $(_GitBaseVersionExpr))) | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitDefaultVersion), $(GitBaseVersionExpr))) | ||
</IsValidGitDefaultVersion> | ||
<IsValidGitDefaultVersion>$(IsValidGitDefaultVersion.Trim())</IsValidGitDefaultVersion> | ||
<GitCommits>0</GitCommits> | ||
|
@@ -716,7 +724,7 @@ | |
|
||
<PropertyGroup> | ||
<IsValidGitBaseVersion> | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBaseVersion), $(_GitBaseVersionExpr))) | ||
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBaseVersion), $(GitBaseVersionExpr))) | ||
</IsValidGitBaseVersion> | ||
<IsValidGitBaseVersion>$(IsValidGitBaseVersion.Trim())</IsValidGitBaseVersion> | ||
</PropertyGroup> | ||
|
@@ -732,13 +740,13 @@ | |
<!-- Remove the initial optional 'v' or 'V' from the base version. --> | ||
<GitBaseVersion Condition="$(GitBaseVersion.StartsWith('v'))">$(GitBaseVersion.TrimStart('v'))</GitBaseVersion> | ||
<GitBaseVersion Condition="$(GitBaseVersion.StartsWith('V'))">$(GitBaseVersion.TrimStart('V'))</GitBaseVersion> | ||
<GitBaseVersionMajor>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(_GitBaseVersionExpr)).Groups['MAJOR'].Value)</GitBaseVersionMajor> | ||
<GitBaseVersionMinor>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(_GitBaseVersionExpr)).Groups['MINOR'].Value)</GitBaseVersionMinor> | ||
<GitBaseVersionPatch>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(_GitBaseVersionExpr)).Groups['PATCH'].Value)</GitBaseVersionPatch> | ||
<GitBaseVersionMajor>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(GitBaseVersionExpr)).Groups['MAJOR'].Value)</GitBaseVersionMajor> | ||
<GitBaseVersionMinor>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(GitBaseVersionExpr)).Groups['MINOR'].Value)</GitBaseVersionMinor> | ||
<GitBaseVersionPatch>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(GitBaseVersionExpr)).Groups['PATCH'].Value)</GitBaseVersionPatch> | ||
<GitSemVerMajor>$(GitBaseVersionMajor)</GitSemVerMajor> | ||
<GitSemVerMinor>$(GitBaseVersionMinor)</GitSemVerMinor> | ||
<GitSemVerPatch>$([MSBuild]::Add('$(GitBaseVersionPatch)', '$(GitCommits)'))</GitSemVerPatch> | ||
<GitSemVerLabel>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(_GitBaseVersionExpr)).Groups['LABEL'].Value)</GitSemVerLabel> | ||
<GitSemVerLabel>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(GitBaseVersionExpr)).Groups['LABEL'].Value)</GitSemVerLabel> | ||
<GitSemVerDashLabel Condition="'$(GitSemVerLabel)' != ''" >-$(GitSemVerLabel)</GitSemVerDashLabel> | ||
</PropertyGroup> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,3 +92,9 @@ Available MSBuild customizations: | |
whether the branch and tags (if any) | ||
will be used to find a base version. | ||
Defaults to empty value (no ignoring). | ||
|
||
$(GitTagRegex): Regular Experssion used with git describe to find the BaseTag | ||
Defaults to * (all) | ||
|
||
$(GitBaseVersionExpr): Regular Experssion used with git describe to find the BaseTag | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in both strings ( |
||
Defaults to '^v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^(?<LABEL>[\dA-Za-z\-\.]+)\-v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)$' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is really needed. We could just run the version regex against the tags in order to filter out the ones to consider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right, but I didn't have an easy way to test, so I kept them separate to make clear what I thought would help.