Skip to content

Commit 4824bfc

Browse files
committed
feat(versioning): Expose comprehensive GitVersion variables
Updates GitVersion variable models and build integrations to provide a full set of versioning details. Deprecates `CommitsSinceVersionSource` in favor of `VersionSourceDistance` for improved accuracy.
1 parent 8f4dc9a commit 4824bfc

File tree

10 files changed

+261
-224
lines changed

10 files changed

+261
-224
lines changed

build/common/Addins/GitVersion/GitVersion.cs

Lines changed: 78 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,102 +6,143 @@ namespace Common.Addins.GitVersion;
66
public sealed class GitVersion
77
{
88
/// <summary>
9-
/// Gets or sets the major version.
9+
/// Gets or sets the assembly semantic file version. Suitable for .NET AssemblyFileVersion. Defaults to Major.Minor.Patch.0.
1010
/// </summary>
11-
public int Major { get; set; }
11+
public string? AssemblySemFileVer { get; set; }
1212

1313
/// <summary>
14-
/// Gets or sets the minor version.
14+
/// Gets or sets the assembly Semantic Version. Suitable for .NET AssemblyVersion. Defaults to Major.Minor.0.0.
1515
/// </summary>
16-
public int Minor { get; set; }
16+
public string? AssemblySemVer { get; set; }
1717

1818
/// <summary>
19-
/// Gets or sets the patch version.
19+
/// Gets or sets the branch name. The name of the checked out Git branch.
2020
/// </summary>
21-
public int Patch { get; set; }
21+
public string? BranchName { get; set; }
2222

2323
/// <summary>
24-
/// Gets or sets the pre-release tag.
24+
/// Gets or sets the build metadata, usually representing number of commits since the VersionSourceSha.
2525
/// </summary>
26-
public string? PreReleaseTag { get; set; }
26+
public int? BuildMetaData { get; set; }
2727

2828
/// <summary>
29-
/// Gets or sets the pre-release tag with dash.
29+
/// Gets or sets the commit date. The ISO-8601 formatted date of the commit identified by Sha.
3030
/// </summary>
31-
public string? PreReleaseTagWithDash { get; set; }
31+
public string? CommitDate { get; set; }
3232

3333
/// <summary>
34-
/// Gets or sets the pre-release label.
34+
/// Gets or sets the commits since version source.
3535
/// </summary>
36-
public string? PreReleaseLabel { get; set; }
36+
[Obsolete("CommitsSinceVersionSource has been deprecated. Use VersionSourceDistance instead.")]
37+
public int? CommitsSinceVersionSource { get; set; }
3738

3839
/// <summary>
39-
/// Gets or sets the pre-release number.
40+
/// Gets or sets the escaped branch name. Equal to BranchName, but with / replaced with -.
4041
/// </summary>
41-
public int? PreReleaseNumber { get; set; }
42+
public string? EscapedBranchName { get; set; }
4243

4344
/// <summary>
44-
/// Gets or sets the build metadata.
45+
/// Gets or sets the full build metadata. The BuildMetaData suffixed with BranchName and Sha.
4546
/// </summary>
46-
public string? BuildMetaData { get; set; }
47+
public string? FullBuildMetaData { get; set; }
4748

4849
/// <summary>
49-
/// Gets or sets the major version.
50+
/// Gets or sets the full Semantic Version. The full, SemVer 2.0 compliant version number.
5051
/// </summary>
51-
public string? FullBuildMetaData { get; set; }
52+
public string? FullSemVer { get; set; }
5253

5354
/// <summary>
54-
/// Gets or sets the major, minor, and path.
55+
/// Gets or sets the informational version. Suitable for .NET AssemblyInformationalVersion. Defaults to FullSemVer suffixed by FullBuildMetaData.
56+
/// </summary>
57+
public string? InformationalVersion { get; set; }
58+
59+
/// <summary>
60+
/// Gets or sets the major version. Should be incremented on breaking changes.
61+
/// </summary>
62+
public int? Major { get; set; }
63+
64+
/// <summary>
65+
/// Gets or sets the major, minor, and patch. Major, Minor and Patch joined together, separated by '.'.
5566
/// </summary>
5667
public string? MajorMinorPatch { get; set; }
5768

5869
/// <summary>
59-
/// Gets or sets the Semantic Version.
70+
/// Gets or sets the minor version. Should be incremented on new features.
6071
/// </summary>
61-
public string? SemVer { get; set; }
72+
public int? Minor { get; set; }
6273

6374
/// <summary>
64-
/// Gets or sets the assembly Semantic Version.
75+
/// Gets or sets the patch version. Should be incremented on bug fixes.
6576
/// </summary>
66-
public string? AssemblySemVer { get; set; }
77+
public int? Patch { get; set; }
6778

6879
/// <summary>
69-
/// Gets or sets the assembly semantic file version.
80+
/// Gets or sets the pre-release label. The pre-release label is the name of the pre-release.
7081
/// </summary>
71-
public string? AssemblySemFileVer { get; set; }
82+
public string? PreReleaseLabel { get; set; }
7283

7384
/// <summary>
74-
/// Gets or sets the full Semantic Version.
85+
/// Gets or sets the pre-release label with dash. The pre-release label prefixed with a dash.
7586
/// </summary>
76-
public string? FullSemVer { get; set; }
87+
public string? PreReleaseLabelWithDash { get; set; }
7788

7889
/// <summary>
79-
/// Gets or sets the informational version.
90+
/// Gets or sets the pre-release number. The pre-release number is the number of commits since the last version bump.
8091
/// </summary>
81-
public string? InformationalVersion { get; set; }
92+
public int? PreReleaseNumber { get; set; }
8293

8394
/// <summary>
84-
/// Gets or sets the branch name.
95+
/// Gets or sets the pre-release tag. The pre-release tag is the pre-release label suffixed by the PreReleaseNumber.
8596
/// </summary>
86-
public string? BranchName { get; set; }
97+
public string? PreReleaseTag { get; set; }
98+
99+
/// <summary>
100+
/// Gets or sets the pre-release tag with dash. The pre-release tag prefixed with a dash.
101+
/// </summary>
102+
public string? PreReleaseTagWithDash { get; set; }
87103

88104
/// <summary>
89-
/// Gets or sets the Git SHA.
105+
/// Gets or sets the Semantic Version. The semantic version number, including PreReleaseTagWithDash for pre-release version numbers.
106+
/// </summary>
107+
public string? SemVer { get; set; }
108+
109+
/// <summary>
110+
/// Gets or sets the Git SHA. The SHA of the Git commit.
90111
/// </summary>
91112
public string? Sha { get; set; }
92113

93114
/// <summary>
94-
/// Gets or sets the commits since version source.
115+
/// Gets or sets the short SHA. The Sha limited to 7 characters.
95116
/// </summary>
96-
public int? CommitsSinceVersionSource { get; set; }
117+
public string? ShortSha { get; set; }
97118

98119
/// <summary>
99-
/// Gets or sets the version source distance.
120+
/// Gets or sets the number of uncommitted changes present in the repository.
121+
/// </summary>
122+
public int? UncommittedChanges { get; set; }
123+
124+
/// <summary>
125+
/// Gets or sets the version source distance. The number of commits since the version source.
100126
/// </summary>
101127
public int? VersionSourceDistance { get; set; }
102128

103129
/// <summary>
104-
/// Gets or sets the commit date.
130+
/// Gets or sets the version source increment. The increment strategy used for the version calculation. Possible values: None, Patch, Minor, Major.
105131
/// </summary>
106-
public string? CommitDate { get; set; }
132+
public string? VersionSourceIncrement { get; set; }
133+
134+
/// <summary>
135+
/// Gets or sets the version source SemVer. The semantic version of the commit used as version source.
136+
/// </summary>
137+
public string? VersionSourceSemVer { get; set; }
138+
139+
/// <summary>
140+
/// Gets or sets the version source SHA. The SHA of the commit used as version source.
141+
/// </summary>
142+
public string? VersionSourceSha { get; set; }
143+
144+
/// <summary>
145+
/// Gets or sets the weighted pre-release number. A summation of branch specific pre-release-weight and the PreReleaseNumber. Can be used to obtain a monotonically increasing version number across the branches.
146+
/// </summary>
147+
public int? WeightedPreReleaseNumber { get; set; }
107148
}

build/common/Addins/GitVersion/GitVersionAliases.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace Common.Addins.GitVersion;
33
/// <summary>
44
/// <para>Contains functionality related to <see href="https://github.com/gittools/gitversion">GitVersion</see>.</para>
55
/// <para>
6-
/// In order to use the commands for this alias, include the following in your build.cake file to download and
6+
/// To use the commands for this alias, include the following in your build.cake file to download and
77
/// install from nuget.org, or specify the ToolPath within the <see cref="GitVersionSettings" /> class:
88
/// <code>
99
/// #tool "nuget:?package=GitVersion.CommandLine"
@@ -58,7 +58,7 @@ public GitVersion GitVersion()
5858
{
5959
ArgumentNullException.ThrowIfNull(context);
6060

61-
return GitVersion(context, new GitVersionSettings());
61+
return context.GitVersion(new GitVersionSettings());
6262
}
6363

6464
/// <summary>

build/common/Utilities/Models.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static BuildVersion Calculate(GitVersion gitVersion)
3333
chocolateyVersion += $"-{prefix}{gitVersion.PreReleaseTag?.Replace(".", "-")}";
3434
}
3535

36-
if (!string.IsNullOrWhiteSpace(gitVersion.BuildMetaData))
36+
if (gitVersion.BuildMetaData is not null)
3737
{
3838
semVersion += $"-{gitVersion.BuildMetaData}";
3939
chocolateyVersion += $"-{gitVersion.BuildMetaData}";

src/GitVersion.Core.Tests/Helpers/TestableGitVersionVariables.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,32 @@
33
namespace GitVersion.Core.Tests.Helpers;
44

55
internal record TestableGitVersionVariables() : GitVersionVariables(
6-
Major: "",
7-
Minor: "",
8-
Patch: "",
9-
BuildMetaData: "",
10-
FullBuildMetaData: "",
6+
AssemblySemFileVer: "",
7+
AssemblySemVer: "",
118
BranchName: "",
9+
BuildMetaData: "",
10+
CommitDate: "",
11+
CommitsSinceVersionSource: "",
1212
EscapedBranchName: "",
13-
Sha: "",
14-
ShortSha: "",
15-
MajorMinorPatch: "",
16-
SemVer: "",
13+
FullBuildMetaData: "",
1714
FullSemVer: "",
18-
AssemblySemVer: "",
19-
AssemblySemFileVer: "",
20-
PreReleaseTag: "",
21-
PreReleaseTagWithDash: "",
15+
InformationalVersion: "",
16+
Major: "",
17+
MajorMinorPatch: "",
18+
Minor: "",
19+
Patch: "",
2220
PreReleaseLabel: "",
2321
PreReleaseLabelWithDash: "",
2422
PreReleaseNumber: "",
25-
WeightedPreReleaseNumber: "",
26-
InformationalVersion: "",
27-
CommitDate: "",
23+
PreReleaseTag: "",
24+
PreReleaseTagWithDash: "",
25+
SemVer: "",
26+
Sha: "",
27+
ShortSha: "",
28+
UncommittedChanges: "",
29+
VersionSourceDistance: "",
30+
VersionSourceIncrement: "",
2831
VersionSourceSemVer: "",
2932
VersionSourceSha: "",
30-
CommitsSinceVersionSource: "",
31-
VersionSourceDistance: "",
32-
UncommittedChanges: "",
33-
VersionSourceIncrement: "");
33+
WeightedPreReleaseNumber: ""
34+
);

0 commit comments

Comments
 (0)