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

Initial use of GitVersion #226

Merged
merged 13 commits into from
Sep 8, 2017
50 changes: 39 additions & 11 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#tool nuget:?package=GitVersion.CommandLine
#addin "Cake.Incubator"

using System.Text.RegularExpressions;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had a regular expression at one point but it's gone now.

Copy link
Contributor

Choose a reason for hiding this comment

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

The regex is back for parsing whether it is a PR or not, so we should keep this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly.


//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -233,30 +235,56 @@ Task("PackageChocolatey")

class BuildInfo
{
private GitVersion _gitVersion;

public BuildInfo(GitVersion gitVersion)
{
BranchName = gitVersion.BranchName;
PreReleaseLabel = gitVersion.PreReleaseLabel;
AssemblyVersion = gitVersion.AssemblySemVer;
AssemblyFileVersion = PackageVersion =
gitVersion.MajorMinorPatch + "-" + PreReleaseLabel + "-" + gitVersion.CommitsSinceVersionSourcePadded;
_gitVersion = gitVersion;
}

public string BranchName
{
get { return _gitVersion.BranchName; }
}

public string AssemblyVersion
{
get { return _gitVersion.AssemblySemVer; }
}
public string AssemblyFileVersion
{
get { return PackageVersion; }
}

public string BranchName { get; set; }
public string PreReleaseLabel
{
get { return _gitVersion.PreReleaseLabel; }
}

public string PackageVersion
{
get { return _gitVersion.MajorMinorPatch + "-" + PreReleaseLabel + "-" + _gitVersion.PreReleaseNumber.PadLeft(4, '0'); }
}

public string AssemblyVersion { get; set; }
public string AssemblyFileVersion { get; set; }
public bool IsPullRequest
{
// Requires correct setup of GitVersion.yml
get { return PreReleaseLabel == "pr"; }
}

public string PreReleaseLabel { get; set; }
public string PackageVersion { get; set; }
public string PullRequestNumber
{
get { return IsPullRequest ? _gitVersion.PreReleaseNumber : string.Empty; }
}

public string Dump()
{
var NL = Environment.NewLine;
return " BranchName: " + BranchName + NL +
" IsPullRequest: " + IsPullRequest.ToString() + NL +
" PullRequestNumber: " + PullRequestNumber + NL +
" AssemblyVersion: " + AssemblyVersion + NL +
" AssemblyFileVersion: " + AssemblyFileVersion + NL +
" PreReleaseLabel: " + PreReleaseLabel + NL +
" Package Version: " + PackageVersion + NL;
}
}
Expand Down