Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/GitInfo/build/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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

Copy link
Author

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.

Defaults to * (all)

$(GitBaseVersionExpr): Regular Experssion used with git describe to find the BaseTag
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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+)$'



==============================================================
-->
Expand Down Expand Up @@ -82,6 +90,8 @@
<SkipWriteGitCache Condition="'$(SkipWriteGitCache)' == ''">$(GitSkipCache)</SkipWriteGitCache>

<GitMinVersion>2.5.0</GitMinVersion>
<GitBaseVersionExpr Condition="'$(GitBaseVersionExpr)' == ''">^v?(?&lt;MAJOR&gt;\d+)\.(?&lt;MINOR&gt;\d+)\.(?&lt;PATCH&gt;\d+)(?:\-(?&lt;LABEL&gt;[\dA-Za-z\-\.]+))?$|^(?&lt;LABEL&gt;[\dA-Za-z\-\.]+)\-v?(?&lt;MAJOR&gt;\d+)\.(?&lt;MINOR&gt;\d+)\.(?&lt;PATCH&gt;\d+)$</GitBaseVersionExpr>
<GitTagRegex Condition="'$(GitTagRegex)' == ''">*</GitTagRegex>
</PropertyGroup>

<!-- Private properties -->
Expand All @@ -93,8 +103,6 @@
GitInfoReport;
$(CoreCompileDependsOn)
</CoreCompileDependsOn>

<_GitBaseVersionExpr Condition="'$(_GitBaseVersionExpr)' == ''">^v?(?&lt;MAJOR&gt;\d+)\.(?&lt;MINOR&gt;\d+)\.(?&lt;PATCH&gt;\d+)(?:\-(?&lt;LABEL&gt;[\dA-Za-z\-\.]+))?$|^(?&lt;LABEL&gt;[\dA-Za-z\-\.]+)\-v?(?&lt;MAJOR&gt;\d+)\.(?&lt;MINOR&gt;\d+)\.(?&lt;PATCH&gt;\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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this --match argument support our current semver2 expression? If so, then we just need to pass it and that's it? If it breaks, do we need a simpler format of the semver2 regex?

Copy link
Author

Choose a reason for hiding this comment

The 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"
Expand Down Expand Up @@ -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"
Expand All @@ -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>

Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>

Expand Down
6 changes: 6 additions & 0 deletions src/GitInfo/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in both strings (Experssion -> Expression). Also, it's not correct that this regex is used to find BaseTag. It's used to parse the base version too.

Defaults to '^v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^(?<LABEL>[\dA-Za-z\-\.]+)\-v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)$'