Skip to content

Commit e00bf89

Browse files
committed
split out write info task
1 parent 24bbf53 commit e00bf89

9 files changed

+98
-27
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.18.0")]
7-
[assembly: AssemblyFileVersion("0.18.0")]
6+
[assembly: AssemblyVersion("0.19.0")]
7+
[assembly: AssemblyFileVersion("0.19.0")]
88
[assembly: InternalsVisibleTo("Tests")]

GitFlowVersion/GitFlow/GitFlowVariableProvider.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ public static Dictionary<string, string> ToKeyValue(this VersionAndBranch versio
1919
{"BranchName", versionAndBranch.BranchName},
2020
{"BranchType", versionAndBranch.BranchType == null ? null : versionAndBranch.BranchType.ToString()},
2121
{"Sha", versionAndBranch.Sha},
22-
{"SemVer", versionAndBranch.GenerateSemVer()}
22+
{"MajorMinorPatch", string.Format("{0}.{1}.{2}", versionAndBranch.Version.Major, versionAndBranch.Version.Minor, versionAndBranch.Version.Patch)},
23+
{"SemVer", versionAndBranch.GenerateSemVer()},
24+
//TODO: legacy. people should move over to semver
25+
{"Version", versionAndBranch.GenerateSemVer()}
2326
};
2427

2528
var releaseInformation = ReleaseInformationCalculator.Calculate(versionAndBranch.BranchType, versionAndBranch.Version.Tag);
2629
if (releaseInformation.ReleaseNumber.HasValue)
2730
{
2831
variables.Add("PreReleasePartOne", releaseInformation.ReleaseNumber.ToString());
32+
//TODO: legacy. people should move over to PreReleasePartOne
33+
variables.Add("PreReleaseNumber", releaseInformation.ReleaseNumber.ToString());
2934
}
3035
if (versionAndBranch.Version.PreReleasePartTwo != null)
3136
{

GitFlowVersionTask/GetVersion.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class GetVersion : Task
3232

3333
[Output]
3434
public string BranchName { get; set; }
35+
[Output]
36+
public string MajorMinorPatch { get; set; }
3537

3638
[Output]
3739
public string ShortVersion { get; set; }
@@ -70,7 +72,7 @@ public override bool Execute()
7072
VersionAndBranch versionAndBranch;
7173
if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch))
7274
{
73-
75+
MajorMinorPatch = string.Format("{0}.{1}.{2}", versionAndBranch.Version.Major, versionAndBranch.Version.Minor, versionAndBranch.Version.Patch);
7476
Major = versionAndBranch.Version.Major;
7577
Minor = versionAndBranch.Version.Minor;
7678
Patch = versionAndBranch.Version.Patch;

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="WriteVersionInfoToBuildLog.cs" />
5455
<Compile Include="GetVersion.cs" />
5556
<Compile Include="InvalidFileChecker.cs" />
5657
<Compile Include="TaskLogger.cs" />

GitFlowVersionTask/NugetAssets/GitFlowVersionTask.targets

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
<UsingTask
88
TaskName="GitFlowVersionTask.UpdateAssemblyInfo"
99
AssemblyFile="$(MSBuildThisFileDirectory)..\GitFlowVersionTask.dll" />
10+
<UsingTask
11+
TaskName="GitFlowVersionTask.WriteVersionInfoToBuildLog"
12+
AssemblyFile="$(MSBuildThisFileDirectory)..\GitFlowVersionTask.dll" />
1013

1114
<Target Name="UpdateAssemblyInfo"
1215
BeforeTargets="CoreCompile">
13-
<GitFlowVersionTask.UpdateAssemblyInfo
16+
<WriteVersionInfoToBuildLog
17+
SolutionDirectory="$(SolutionDir)"
18+
/>
19+
<UpdateAssemblyInfo
1420
SolutionDirectory="$(SolutionDir)"
1521
AssemblyName="$(AssemblyName)"
1622
ProjectFile="$(ProjectPath)"
@@ -19,14 +25,11 @@
1925
<Output
2026
TaskParameter="AssemblyInfoTempFilePath"
2127
PropertyName="AssemblyInfoTempFilePath" />
22-
</GitFlowVersionTask.UpdateAssemblyInfo>
23-
<Message Text="$(AssemblyInfoTempFilePath)" />
28+
</UpdateAssemblyInfo>
2429

25-
<Message Text="BeforeInjection @(Compile)" />
2630
<ItemGroup>
2731
<Compile Include="$(AssemblyInfoTempFilePath)" />
2832
</ItemGroup>
29-
<Message Text="AfterInjection @(Compile)" />
3033
</Target>
3134

3235
<!--Support for ncrunch-->

GitFlowVersionTask/UpdateAssemblyInfo.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace GitFlowVersionTask
22
{
33
using System;
4-
using System.Collections.Generic;
54
using System.IO;
65
using GitFlowVersion;
76
using Microsoft.Build.Framework;
@@ -71,26 +70,10 @@ public void InnerExecute()
7170
return;
7271
}
7372

74-
WriteIntegrationParameters(versionAndBranch, BuildServerList.GetApplicableBuildServers());
75-
7673
CreateTempAssemblyInfo(versionAndBranch);
7774

7875
}
7976

80-
public void WriteIntegrationParameters(VersionAndBranch versionAndBranch, IEnumerable<IBuildServer> applicableBuildServers)
81-
{
82-
foreach (var buildServer in applicableBuildServers)
83-
{
84-
logger.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
85-
logger.LogInfo(buildServer.GenerateSetVersionMessage(versionAndBranch.GenerateSemVer()));
86-
logger.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
87-
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(versionAndBranch, buildServer))
88-
{
89-
logger.LogInfo(buildParameter);
90-
}
91-
}
92-
}
93-
9477

9578
void CreateTempAssemblyInfo(VersionAndBranch versionAndBranch)
9679
{
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
namespace GitFlowVersionTask
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using GitFlowVersion;
6+
using Microsoft.Build.Framework;
7+
using Microsoft.Build.Utilities;
8+
using Logger = GitFlowVersion.Logger;
9+
10+
public class WriteVersionInfoToBuildLog : Task
11+
{
12+
13+
[Required]
14+
public string SolutionDirectory { get; set; }
15+
16+
TaskLogger logger;
17+
18+
public WriteVersionInfoToBuildLog()
19+
{
20+
logger = new TaskLogger(this);
21+
Logger.WriteInfo = this.LogInfo;
22+
Logger.WriteWarning = this.LogWarning;
23+
}
24+
25+
public override bool Execute()
26+
{
27+
try
28+
{
29+
InnerExecute();
30+
return true;
31+
}
32+
catch (ErrorException errorException)
33+
{
34+
logger.LogError(errorException.Message);
35+
return false;
36+
}
37+
catch (Exception exception)
38+
{
39+
logger.LogError("Error occurred: " + exception);
40+
return false;
41+
}
42+
finally
43+
{
44+
Logger.Reset();
45+
}
46+
}
47+
48+
public void InnerExecute()
49+
{
50+
VersionAndBranch versionAndBranch;
51+
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch))
52+
{
53+
return;
54+
}
55+
56+
WriteIntegrationParameters(versionAndBranch, BuildServerList.GetApplicableBuildServers());
57+
}
58+
59+
public void WriteIntegrationParameters(VersionAndBranch versionAndBranch, IEnumerable<IBuildServer> applicableBuildServers)
60+
{
61+
foreach (var buildServer in applicableBuildServers)
62+
{
63+
logger.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
64+
logger.LogInfo(buildServer.GenerateSetVersionMessage(versionAndBranch.GenerateSemVer()));
65+
logger.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
66+
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(versionAndBranch, buildServer))
67+
{
68+
logger.LogInfo(buildParameter);
69+
}
70+
}
71+
}
72+
73+
}
74+
}

Tests/IntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.GenerateSemVer());
265+
Debug.WriteLine(version.ToShortString());
266266
}
267267
}
268268
[Test, Explicit]

Tests/JsonVersionBuilderTests.Json.approved.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"BranchName":"feature1",
1010
"BranchType":"Feature",
1111
"Sha":"a682956dc1a2752aa24597a0f5cd939f93614509",
12+
"MajorMinorPatch":"1.2.3",
1213
"SemVer":"1.2.3-Feature-feature1-a682956dc1a2752aa24597a0f5cd939f93614509",
14+
"Version":"1.2.3-Feature-feature1-a682956dc1a2752aa24597a0f5cd939f93614509",
1315
"PreReleasePartOne":4,
16+
"PreReleaseNumber":4,
1417
"Stability":"Unstable"
1518
}

0 commit comments

Comments
 (0)