Skip to content

Commit 24bbf53

Browse files
committed
add getversion task
1 parent 26bdd31 commit 24bbf53

File tree

4 files changed

+114
-5
lines changed

4 files changed

+114
-5
lines changed

CommonAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
[assembly: AssemblyTitle("GitFlowVersion")]
55
[assembly: AssemblyProduct("GitFlowVersion")]
6-
[assembly: AssemblyVersion("0.17.0")]
7-
[assembly: AssemblyFileVersion("0.17.0")]
6+
[assembly: AssemblyVersion("0.18.0")]
7+
[assembly: AssemblyFileVersion("0.18.0")]
88
[assembly: InternalsVisibleTo("Tests")]

GitFlowVersionTask/GetVersion.cs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
namespace GitFlowVersionTask
2+
{
3+
using System;
4+
using GitFlowVersion;
5+
using Microsoft.Build.Framework;
6+
using Microsoft.Build.Utilities;
7+
using Logger = GitFlowVersion.Logger;
8+
9+
public class GetVersion : Task
10+
{
11+
12+
[Required]
13+
public string SolutionDirectory { get; set; }
14+
15+
[Output]
16+
public Stability? Stability { get; set; }
17+
18+
[Output]
19+
public int? PreReleasePartTwo { get; set; }
20+
21+
[Output]
22+
public int? PreReleasePartOne { get; set; }
23+
24+
[Output]
25+
public string SemVer { get; set; }
26+
27+
[Output]
28+
public string Sha { get; set; }
29+
30+
[Output]
31+
public string BranchType { get; set; }
32+
33+
[Output]
34+
public string BranchName { get; set; }
35+
36+
[Output]
37+
public string ShortVersion { get; set; }
38+
39+
[Output]
40+
public string NugetVersion { get; set; }
41+
42+
[Output]
43+
public string LongVersion { get; set; }
44+
45+
[Output]
46+
public string Suffix { get; set; }
47+
48+
[Output]
49+
public int Patch { get; set; }
50+
51+
[Output]
52+
public int Minor { get; set; }
53+
54+
[Output]
55+
public int Major { get; set; }
56+
57+
TaskLogger logger;
58+
59+
public GetVersion()
60+
{
61+
logger = new TaskLogger(this);
62+
Logger.WriteInfo = this.LogInfo;
63+
Logger.WriteWarning = this.LogWarning;
64+
}
65+
66+
public override bool Execute()
67+
{
68+
try
69+
{
70+
VersionAndBranch versionAndBranch;
71+
if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch))
72+
{
73+
74+
Major = versionAndBranch.Version.Major;
75+
Minor = versionAndBranch.Version.Minor;
76+
Patch = versionAndBranch.Version.Patch;
77+
Suffix = versionAndBranch.Version.Suffix;
78+
LongVersion = versionAndBranch.ToLongString();
79+
NugetVersion = versionAndBranch.GenerateNugetVersion();
80+
ShortVersion = versionAndBranch.ToShortString();
81+
BranchName = versionAndBranch.BranchName;
82+
BranchType = versionAndBranch.BranchType == null ? null : versionAndBranch.BranchType.ToString();
83+
Sha = versionAndBranch.Sha;
84+
SemVer = versionAndBranch.GenerateSemVer();
85+
var releaseInformation = ReleaseInformationCalculator.Calculate(versionAndBranch.BranchType, versionAndBranch.Version.Tag);
86+
PreReleasePartOne = releaseInformation.ReleaseNumber;
87+
PreReleasePartTwo = versionAndBranch.Version.PreReleasePartTwo;
88+
Stability = releaseInformation.Stability;
89+
}
90+
return true;
91+
}
92+
catch (ErrorException errorException)
93+
{
94+
logger.LogError(errorException.Message);
95+
return false;
96+
}
97+
catch (Exception exception)
98+
{
99+
logger.LogError("Error occurred: " + exception);
100+
return false;
101+
}
102+
finally
103+
{
104+
Logger.Reset();
105+
}
106+
}
107+
}
108+
}

GitFlowVersionTask/GitFlowVersionTask.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
</Compile>
5252
<Compile Include="AssemblyInfoBuilder.cs" />
5353
<Compile Include="BuildLogger.cs" />
54+
<Compile Include="GetVersion.cs" />
5455
<Compile Include="InvalidFileChecker.cs" />
5556
<Compile Include="TaskLogger.cs" />
5657
<Compile Include="TempFileTracker.cs" />

Tests/IntegrationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ public void NServiceBusDevelopOlderCommit()
247247
[Test,Explicit]
248248
public void Foo()
249249
{
250-
using (var repository = new Repository(@"C:\Code\Particular\ServicePulse"))
250+
using (var repository = new Repository(@"C:\Code\ServiceControl"))
251251
{
252-
var branch = repository.Branches.First(x => x.Name == "feature-newUI");
252+
var branch = repository.Branches.First(x => x.Name == "develop");
253253

254254
var finder = new GitVersionFinder();
255255
var version = finder.FindVersion(new GitVersionContext
@@ -262,7 +262,7 @@ public void Foo()
262262
Debug.WriteLine(version.Version.Patch);
263263
Debug.WriteLine(version.Version.Tag);
264264
Debug.WriteLine(version.BranchType);
265-
Debug.WriteLine(version.Version.Suffix);
265+
Debug.WriteLine(version.GenerateSemVer());
266266
}
267267
}
268268
[Test, Explicit]

0 commit comments

Comments
 (0)