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

Add GitVersionTask #6

Merged
merged 17 commits into from
Jul 1, 2016
Merged
Show file tree
Hide file tree
Changes from 15 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
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ bld/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# Cake is installed by the bootstrap script when needed
tools/Cake
# All tools are installed by the bootstrap script when needed
tools/*

# MSTest test Results
[Tt]est[Rr]esult*/
Expand Down Expand Up @@ -143,7 +143,7 @@ publish/
*.[Pp]ublish.xml
*.azurePubxml

# TODO: Un-comment the next line if you do not want to checkin
# TODO: Un-comment the next line if you do not want to checkin
# your web deploy settings because they may include unencrypted
# passwords
#*.pubxml
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ configuration: Release
platform: Any CPU

build_script:
- ps: .\build.ps1 -Target "Appveyor"
- ps: .\build.ps1 -Target "Appveyor" -Verbosity Diagnostic
Copy link
Member

Choose a reason for hiding this comment

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

We should drop this once we're satisfied it works correctly.


# disable built-in tests.
test: off
Expand Down
92 changes: 63 additions & 29 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#tool "nuget:?package=GitVersion.CommandLine&version=3.5.4"

Copy link
Member

Choose a reason for hiding this comment

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

So in the end we use both the Task and the commandline?

Copy link
Author

Choose a reason for hiding this comment

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

Yea, we unfortunately can't yet get the result from GitVersionTask available in the Cake script, so we need to run gitversion.exe as well. It will produce the same version number, though, so it's only a theoretical performance issue. I'd like to avoid it, but currently that is not possible.

//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
Expand All @@ -18,10 +20,9 @@ var SOLUTION = PROJECT_DIR + "NUnit.System.Linq.sln";
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////

var version = "0.6.0";
var modifier = "";
var version = "0.0.0";
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
var packageVersion = version + dbgSuffix;

//////////////////////////////////////////////////////////////////////
// CLEAN
Expand All @@ -37,39 +38,72 @@ Task("Clean")
// RESTORE PACKAGES
//////////////////////////////////////////////////////////////////////

Task("InitializeBuild")
Task("NuGet-Package-Restore")
.Does(() =>
{
if (BuildSystem.IsRunningOnAppVeyor)
{
var tag = AppVeyor.Environment.Repository.Tag;

if (tag.IsTag)
{
packageVersion = tag.Name;
}
else
{
var buildNumber = AppVeyor.Environment.Build.Number;
packageVersion = version + "-CI-" + buildNumber + dbgSuffix;
if (AppVeyor.Environment.PullRequest.IsPullRequest)
packageVersion += "-PR-" + AppVeyor.Environment.PullRequest.Number;
else if (AppVeyor.Environment.Repository.Branch.StartsWith("release", StringComparison.OrdinalIgnoreCase))
packageVersion += "-PRE-" + buildNumber;
else
packageVersion += "-" + AppVeyor.Environment.Repository.Branch;
}

AppVeyor.UpdateBuildVersion(packageVersion);
}
NuGetRestore(SOLUTION);
});

//////////////////////////////////////////////////////////////////////
// INITIALIZE BUILD
//////////////////////////////////////////////////////////////////////

Setup(context =>
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason to prefer SetUp to a Task here?

Copy link
Author

Choose a reason for hiding this comment

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

I'm not a Cake expert, but it seems like this is something you'd want to explicitly run no matter what target you choose or how you set the different target dependencies up, for which Setup() fits the bill quite nicely.

Copy link
Member

Choose a reason for hiding this comment

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

Well, cake is a general scripting language and the Tasks could do anything. For example, we have targets in nunit that just run the tests, without building. That's why we created InitializeBuild. In fact, it doesn't matter much, because (1) everything is conditioned by IsRunningOnAppveyor and (2) there are no targets like that in this project. I think it's mostly a style thing - no need to change what you have done.

{
if (IsRunningOnWindows())
{
var settings = new GitVersionSettings
{
OutputType = GitVersionOutput.Json,
};

/*if (!BuildSystem.IsLocalBuild)
{
settings.LogFilePath = "console";
settings.OutputType = GitVersionOutput.BuildServer;
}*/
Copy link
Member

Choose a reason for hiding this comment

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

Can the commented out stuff be removed?


var gitVersion = GitVersion(settings);

Information("AssemblySemVer: " + gitVersion.AssemblySemVer);
Information("BranchName: " + gitVersion.BranchName);
Information("BuildMetaData: " + gitVersion.BuildMetaData);
Information("BuildMetaDataPadded: " + gitVersion.BuildMetaDataPadded);
Information("CommitDate: " + gitVersion.CommitDate);
Information("CommitsSinceVersionSource: " + gitVersion.CommitsSinceVersionSource);
Information("CommitsSinceVersionSourcePadded: " + gitVersion.CommitsSinceVersionSourcePadded);
Information("FullBuildMetaData: " + gitVersion.FullBuildMetaData);
Information("FullSemVer: " + gitVersion.FullSemVer);
Information("InformationalVersion: " + gitVersion.InformationalVersion);
Information("LegacySemVer: " + gitVersion.LegacySemVer);
Information("LegacySemVerPadded: " + gitVersion.LegacySemVerPadded);
Information("Major: " + gitVersion.Major);
Information("Minor: " + gitVersion.Minor);
Information("NuGetVersion: " + gitVersion.NuGetVersion);
Information("NuGetVersionV2: " + gitVersion.NuGetVersionV2);
Information("Patch: " + gitVersion.Patch);
Information("PreReleaseLabel: " + gitVersion.PreReleaseLabel);
Information("PreReleaseNumber: " + gitVersion.PreReleaseNumber);
Information("PreReleaseTag: " + gitVersion.PreReleaseTag);
Information("PreReleaseTagWithDash: " + gitVersion.PreReleaseTagWithDash);
Information("SemVer: " + gitVersion.SemVer);
Information("Sha: " + gitVersion.Sha);

packageVersion = gitVersion.NuGetVersion ?? context.EnvironmentVariable("GitVersion_NuGetVersion");
Copy link
Member

Choose a reason for hiding this comment

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

We had some logic in the original script that did different things based on whether there was a tag and the name of the branch. Is that all incorporated somewhere or are we getting default settings now?

}

if (string.IsNullOrWhiteSpace(packageVersion))
{
Warning("The package version is null or empty.");
}
});

//////////////////////////////////////////////////////////////////////
// BUILD
//////////////////////////////////////////////////////////////////////

Task("Build")
.IsDependentOn("InitializeBuild")
.IsDependentOn("NuGet-Package-Restore")
.Does(() =>
{
if (IsRunningOnWindows())
Expand All @@ -88,7 +122,7 @@ Task("Build")
.WithTarget("Build")
.WithProperty("Configuration", configuration)
.SetVerbosity(Verbosity.Minimal));
}
}
});

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -125,7 +159,7 @@ Task("Travis")
.IsDependentOn("Build");

Task("Default")
.IsDependentOn("Build");
.IsDependentOn("Build");

//////////////////////////////////////////////////////////////////////
// EXECUTION
Expand Down
10 changes: 10 additions & 0 deletions src/NUnit.System.Linq/NUnit.System.Linq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<AssemblyName>NUnit.System.Linq</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -64,8 +66,16 @@
</ItemGroup>
<ItemGroup>
<None Include="nunit.snk" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\GitVersionTask.3.5.4\build\portable-net+sl+win+wpa+wp\GitVersionTask.targets" Condition="Exists('..\..\packages\GitVersionTask.3.5.4\build\portable-net+sl+win+wpa+wp\GitVersionTask.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\GitVersionTask.3.5.4\build\portable-net+sl+win+wpa+wp\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\GitVersionTask.3.5.4\build\portable-net+sl+win+wpa+wp\GitVersionTask.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
13 changes: 0 additions & 13 deletions src/NUnit.System.Linq/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,4 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d7ed9849-5dde-4e23-8390-76a80acde2f8")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.6.0.0")]
[assembly: AssemblyFileVersion("0.6.0.0")]

[assembly: CLSCompliant(true)]
4 changes: 4 additions & 0 deletions src/NUnit.System.Linq/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GitVersionTask" version="3.5.4" targetFramework="net20" developmentDependency="true" />
</packages>
Binary file removed tools/nuget.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.6.4" />
<package id="Cake" version="0.13.0" />
</packages>