Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
Splitting the GetSemanticVersion.msbuild script into CalculateSemanti…
Browse files Browse the repository at this point in the history
…cVersion.msbuild and GetSemanticVersion.msbuild.

The first script calls GitHubVersion to determine the semantic version and writes that to a file. Then the second script can be used to parse that file to get the version numbers where they are needed.
This ensures that we only get the version once during the build process which prevents while tagging.

references #30
  • Loading branch information
pvandervelde committed May 11, 2014
1 parent 60f7f30 commit ec60053
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 72 deletions.
84 changes: 84 additions & 0 deletions Build.GatherReleaseNotes.msbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="Run"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Build flags -->
<ShouldClean>true</ShouldClean>
<ShouldCleanPackages>false</ShouldCleanPackages>

<!-- Directories -->
<DirWorkspace>$(MSBuildProjectDirectory)</DirWorkspace>
<DirPackages>$(DirWorkspace)\packages</DirPackages>
<DirTools>$(DirWorkspace)\tools</DirTools>
<DirBuild>$(DirWorkspace)\build</DirBuild>
<DirBuildBin>$(DirBuild)\bin\$(PlatformTranslated)\$(Configuration)</DirBuildBin>
<DirBuildDeploy>$(DirBuild)\deploy</DirBuildDeploy>
<DirBuildLogs>$(DirBuild)\logs</DirBuildLogs>
<DirBuildTemp>$(DirBuild)\temp</DirBuildTemp>
<DirSrc>$(DirWorkspace)\src</DirSrc>

<!-- Issue tracker -->
<GitHubUserName></GitHubUserName>
<GitHubToken></GitHubToken>

<!-- Version number -->
<VersionSemantic>0</VersionSemantic>

<!-- Tools -->
<MsBuildExtensionsPath>$(DirTools)\msbuild.extensions</MsBuildExtensionsPath>
</PropertyGroup>

<Import Project="$(MsBuildExtensionsPath)\FindToolFromPackages.msbuild"
Condition="Exists('$(MsBuildExtensionsPath)\FindToolFromPackages.msbuild')" />
<Import Project="$(MsBuildExtensionsPath)\CalculateSemanticVersion.msbuild"
Condition="Exists('$(MsBuildExtensionsPath)\CalculateSemanticVersion.msbuild')" />
<Import Project="$(MsBuildExtensionsPath)\GetSemanticVersion.msbuild"
Condition="Exists('$(MsBuildExtensionsPath)\GetSemanticVersion.msbuild')" />
<Import Project="$(MsBuildExtensionsPath)\TemplateFile.msbuild"
Condition="Exists('$(MsBuildExtensionsPath)\TemplateFile.msbuild')"/>

<Target Name="Run" DependsOnTargets="_DisplayInfo;_GatherReleaseNotes">
<!-- Do nothing here -->
</Target>

<!-- Display info -->
<Target Name="_DisplayInfo">
<Message Text="Gathering release notes ..." />
<Message Text="WARNING: Github username not specified" Condition=" '$(GitHubUserName)' == '' " />
<Message Text="WARNING: Github token not specified" Condition=" '$(GitHubToken)' == '' " />
</Target>

<PropertyGroup>
<FileGitVersionExe>GitHubFlowVersion.exe</FileGitVersionExe>
<FileSemanticVersion>$(DirBuildTemp)\semantic_version.json</FileSemanticVersion>
</PropertyGroup>
<Target Name="_GetSemanticVersion">
<FindToolFromPackages PackagesDir="$(DirPackages)" FileToLocate="$(FileGitVersionExe)">
<Output TaskParameter="Path" PropertyName="PathGitVersionExe" />
</FindToolFromPackages>

<CalculateSemanticVersion ExePath="$(PathGitVersionExe)" VersionFile="$(FileSemanticVersion)" Condition="!Exists('$(FileSemanticVersion)')" />

<GetSemanticVersion VersionFile="$(FileSemanticVersion)">
<Output TaskParameter="VersionSemantic" PropertyName="VersionSemantic" />
</GetSemanticVersion>
</Target>

<PropertyGroup>
<FileGitReleaseNotes>GitReleaseNotes.exe</FileGitReleaseNotes>
<FileReleaseNotesShort>$(DirBuildTemp)\releasenotes_short.md</FileReleaseNotesShort>
<FileReleaseNotesFull>$(DirBuildTemp)\releasenotes_full.md</FileReleaseNotesFull>
</PropertyGroup>
<Target Name="_GatherReleaseNotes" DependsOnTargets="_DisplayInfo;_GetSemanticVersion" Condition=" '$(GitHubUserName)' != '' AND '$(GitHubToken)' != '' ">
<FindToolFromPackages PackagesDir="$(DirPackages)" FileToLocate="$(FileGitReleaseNotes)">
<Output TaskParameter="Path" PropertyName="PathGitReleaseNotesExe" />
</FindToolFromPackages>

<Exec Command="&quot;$(PathGitReleaseNotesExe)&quot; /I GitHub /R $(GitHubUserName)/nuclei /U $(GitHubUserName) /T $(GitHubToken) /V $(VersionSemantic) /O &quot;$(FileReleaseNotesShort)&quot;"
WorkingDirectory="$(DirWorkspace)" />

<Exec Command="&quot;$(PathGitReleaseNotesExe)&quot; /I GitHub /R $(GitHubUserName)/nuclei /U $(GitHubUserName) /T $(GitHubToken) /F all /V $(VersionSemantic) /O &quot;$(FileReleaseNotesFull)&quot;"
WorkingDirectory="$(DirWorkspace)" />
</Target>
</Project>
20 changes: 4 additions & 16 deletions Build.Package.NuGet.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,18 @@
</Target>

<PropertyGroup>
<FileGitVersionExe>GitHubFlowVersion.exe</FileGitVersionExe>
<FileSemanticVersion>$(DirBuildTemp)\semantic_version.json</FileSemanticVersion>
</PropertyGroup>
<Target Name="_GetSemanticVersion">
<FindToolFromPackages PackagesDir="$(DirPackages)" FileToLocate="$(FileGitVersionExe)">
<Output TaskParameter="Path" PropertyName="PathGitVersionExe" />
</FindToolFromPackages>

<GetSemanticVersion ExePath="$(PathGitVersionExe)" TempDirectory="$(DirBuildTemp)">
<Target Name="_GetSemanticVersion" DependsOnTargets="_DisplayInfo;">
<GetSemanticVersion VersionFile="$(FileSemanticVersion)">
<Output TaskParameter="VersionSemantic" PropertyName="VersionSemantic" />
</GetSemanticVersion>
</Target>

<PropertyGroup>
<FileGitReleaseNotes>GitReleaseNotes.exe</FileGitReleaseNotes>
<FileReleaseNotes>$(DirBuildTemp)\releasenotes.md</FileReleaseNotes>
<FileReleaseNotes>$(DirBuildTemp)\releasenotes_full.md</FileReleaseNotes>
</PropertyGroup>
<Target Name="_GatherReleaseNotes" Condition=" '$(GitHubUserName)' != '' AND '$(GitHubToken)' != '' ">
<FindToolFromPackages PackagesDir="$(DirPackages)" FileToLocate="$(FileGitReleaseNotes)">
<Output TaskParameter="Path" PropertyName="PathGitReleaseNotesExe" />
</FindToolFromPackages>

<Exec Command="&quot;$(PathGitReleaseNotesExe)&quot; /I GitHub /R $(GitHubUserName)/nuclei /U $(GitHubUserName) /T $(GitHubToken) /F all /O &quot;$(FileReleaseNotes)&quot;"
WorkingDirectory="$(DirWorkspace)" />

<CreateProperty Condition="Exists('$(FileReleaseNotes)')" Value="$([System.IO.File]::ReadAllText('$(FileReleaseNotes)'))">
<Output TaskParameter="Value" PropertyName="ReleaseNotes" />
</CreateProperty>
Expand Down
12 changes: 10 additions & 2 deletions Build.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<DirWorkspace>$(MSBuildProjectDirectory)</DirWorkspace>
</PropertyGroup>

<Target Name="Run" DependsOnTargets="_PrepareWorkspace;_BuildBinaries;_ExecuteUnitTests;_PackageNuget">
<Target Name="Run" DependsOnTargets="_PrepareWorkspace;_GatherReleaseNotes;_BuildBinaries;_ExecuteUnitTests;_PackageNuget">
<!-- Do nothing here -->
</Target>

Expand All @@ -32,11 +32,19 @@
<MSBuild Projects="$(MsBuildPrepareWorkspace)" Properties="ShouldClean=$(ShouldClean);ShouldCleanPackages=$(ShouldCleanPackages)" />
</Target>

<!-- Gather release notes -->
<PropertyGroup>
<MsBuildGatherReleaseNotes>$(DirWorkspace)\Build.GatherReleaseNotes.msbuild</MsBuildGatherReleaseNotes>
</PropertyGroup>
<Target Name="_GatherReleaseNotes" DependsOnTargets="_PrepareWorkspace">
<MSBuild Projects="$(MsBuildGatherReleaseNotes)" Properties="ShouldClean=$(ShouldClean);ShouldCleanPackages=$(ShouldCleanPackages)" />
</Target>

<!-- Build binaries -->
<PropertyGroup>
<MsBuildBuildBinaries>$(DirWorkspace)\Build.Binaries.msbuild</MsBuildBuildBinaries>
</PropertyGroup>
<Target Name="_BuildBinaries" DependsOnTargets="_PrepareWorkspace">
<Target Name="_BuildBinaries" DependsOnTargets="_GatherReleaseNotes">
<MSBuild Projects="$(MsBuildBuildBinaries)" Properties="Configuration=Release;Platform=$(Platform)" />
<MSBuild Projects="$(MsBuildBuildBinaries)" Properties="Configuration=Deploy;Platform=$(Platform)" />
</Target>
Expand Down
12 changes: 4 additions & 8 deletions Deploy.GitTag.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,18 @@
</Target>

<PropertyGroup>
<FileGitVersionExe>GitHubFlowVersion.exe</FileGitVersionExe>
<FileSemanticVersion>$(DirBuildTemp)\semantic_version.json</FileSemanticVersion>
</PropertyGroup>
<Target Name="_GetSemanticVersion">
<FindToolFromPackages PackagesDir="$(DirPackages)" FileToLocate="$(FileGitVersionExe)">
<Output TaskParameter="Path" PropertyName="PathGitVersionExe" />
</FindToolFromPackages>

<GetSemanticVersion ExePath="$(PathGitVersionExe)" TempDirectory="$(DirBuildTemp)">
<Target Name="_GetSemanticVersion" DependsOnTargets="_DisplayInfo;">
<GetSemanticVersion VersionFile="$(FileSemanticVersion)">
<Output TaskParameter="VersionSemantic" PropertyName="VersionSemantic" />
</GetSemanticVersion>
</Target>

<PropertyGroup>
<FileReleaseNotes>$(DirBuildTemp)\releasenotes.md</FileReleaseNotes>
</PropertyGroup>
<Target Name="_LoadReleaseNotes">
<Target Name="_LoadReleaseNotes" DependsOnTargets="_DisplayInfo;_GetSemanticVersion">
<CreateProperty Condition="Exists('$(FileReleaseNotes)')" Value="$([System.IO.File]::ReadAllText('$(FileReleaseNotes)'))">
<Output TaskParameter="Value" PropertyName="ReleaseNotes" />
</CreateProperty>
Expand Down
70 changes: 70 additions & 0 deletions tools/msbuild.extensions/CalculateSemanticVersion.msbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!--
Copyright 2013 Nuclei. Licensed under the Apache License, Version 2.0.
-->

<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'
ToolsVersion="4.0">
<UsingTask TaskName="CalculateSemanticVersion"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<ExePath ParameterType="System.String" Required="true" />
<VersionFile ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Code Type="Method" Language="cs">
<![CDATA[
public override bool Execute()
{
var info = new System.Diagnostics.ProcessStartInfo
{
FileName = ExePath,
Arguments = string.Format("/ToFile \"{0}\"", VersionFile),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
};

Log.LogMessage(MessageImportance.Normal, ExePath);
Log.LogMessage(MessageImportance.Normal, info.Arguments);

var process = new System.Diagnostics.Process();
process.StartInfo = info;
process.OutputDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Log.LogMessage(MessageImportance.Normal, e.Data);
}
};
process.ErrorDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Log.LogError(e.Data);
}
};
process.Start();

process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();

if (process.ExitCode != 0)
{
Log.LogError("Failed to get semantic version information");
return false;
}

// Log.HasLoggedErrors is true if the task logged any errors -- even if they were logged
// from a task's constructor or property setter. As long as this task is written to always log an error
// when it fails, we can reliably return HasLoggedErrors.
return !Log.HasLoggedErrors;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
48 changes: 2 additions & 46 deletions tools/msbuild.extensions/GetSemanticVersion.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<ExePath ParameterType="System.String" Required="true" />
<TempDirectory ParameterType="System.String" Required="true" />
<VersionFile ParameterType="System.String" Required="true" />
<VersionMajor ParameterType="System.String" Output="true" />
<VersionMinor ParameterType="System.String" Output="true" />
<VersionPatch ParameterType="System.String" Output="true" />
Expand All @@ -22,53 +21,10 @@
<![CDATA[
public override bool Execute()
{
var outputPath = System.IO.Path.Combine(TempDirectory, "semantic_version.json");
var info = new System.Diagnostics.ProcessStartInfo
{
FileName = ExePath,
Arguments = string.Format("/ToFile \"{0}\"", outputPath),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
};

Log.LogMessage(MessageImportance.Normal, ExePath);
Log.LogMessage(MessageImportance.Normal, info.Arguments);

var process = new System.Diagnostics.Process();
process.StartInfo = info;
process.OutputDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Log.LogMessage(MessageImportance.Normal, e.Data);
}
};
process.ErrorDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Log.LogError(e.Data);
}
};
process.Start();

process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();

if (process.ExitCode != 0)
{
Log.LogError("Failed to get semantic version information");
return false;
}

try
{
string text;
using (var reader = new System.IO.StreamReader(outputPath))
using (var reader = new System.IO.StreamReader(VersionFile))
{
text = reader.ReadToEnd();
}
Expand Down

0 comments on commit ec60053

Please sign in to comment.