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
Merged
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ _UpgradeReport_Files/
Backup*/
UpgradeLog*.XML

# VsCode
.vscode

# NUnit Files
TestResult.xml
*.VisualState.xml
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ mono:
- latest
- 4.6.2
script:
- ./build.sh -target="Travis" -configuration="Release" -verbosity="verbose"
- git fetch --unshallow
- ./build.sh --target "Travis"
Copy link
Contributor

Choose a reason for hiding this comment

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

I've pushed a commit b758c79 to correct the error from the merge (the error made Travis fail every time).

14 changes: 14 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file included on purpose? I can google that it defines a vscode task, but I cannot find the script Package that is mentioned.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's because I executed tasks in the script under VsCode. File should be in .gitignore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The script is build.cake, Package is a target.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. The "script": "Package" was a bit misleading 😄

"tasks": [
{
"type": "cake",
"script": "Package",
"problemMatcher": [
"$eslint-stylish"
]
}
]
}
19 changes: 19 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mode: ContinuousDelivery
branches:
master:
tag: dev
increment: Minor
releases?[/-]:
tag: ci
increment: Minor
features?[/-]:
tag: ci
increment: Minor
issues?[/-]:
tag: ci
increment: Minor
(pull|pull\-requests|pr)[/-]:
tag: pr
increment: Minor
ignore:
sha: []
173 changes: 109 additions & 64 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#tool nuget:?package=NUnit.ConsoleRunner&version=3.7.0
#tool nuget:?package=GitVersion.CommandLine

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 All @@ -8,15 +11,11 @@ var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");

//////////////////////////////////////////////////////////////////////
// SET PACKAGE VERSION
// SET PACKAGE VERSION DEFAULTS
//////////////////////////////////////////////////////////////////////

var version = "0.5";
var modifier = "";

var isAppveyor = BuildSystem.IsRunningOnAppVeyor;
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
GitVersion GitVersionInfo { get; set; }
BuildInfo Build { get; set;}

//////////////////////////////////////////////////////////////////////
// DEFINE RUN CONSTANTS
Expand All @@ -41,10 +40,6 @@ var PACKAGE_SOURCE = new string[]
"https://www.myget.org/F/nunit-gui-team/api/v2"
};

// Packages
var SRC_PACKAGE = PACKAGE_DIR + "NUnit-Gui-" + version + modifier + "-src.zip";
var ZIP_PACKAGE = PACKAGE_DIR + "NUnit-Gui-" + packageVersion + ".zip";

//////////////////////////////////////////////////////////////////////
// CLEAN
//////////////////////////////////////////////////////////////////////
Expand All @@ -57,63 +52,44 @@ Task("Clean")


//////////////////////////////////////////////////////////////////////
// INITIALIZE FOR BUILD
// RESTORE NUGET PACKAGES
//////////////////////////////////////////////////////////////////////

Task("InitializeBuild")
Task("RestorePackages")
.Does(() =>
{
NuGetRestore(GUI_SOLUTION, new NuGetRestoreSettings
{
Source = PACKAGE_SOURCE,
Verbosity = NuGetVerbosity.Detailed
});
});

if (BuildSystem.IsRunningOnAppVeyor)
//////////////////////////////////////////////////////////////////////
// SET BUILD INFO
//////////////////////////////////////////////////////////////////////
Task("SetBuildInfo")
.Does(() =>
{
var settings = new GitVersionSettings();
if (!BuildSystem.IsLocalBuild)
{
var tag = AppVeyor.Environment.Repository.Tag;

if (tag.IsTag)
{
packageVersion = tag.Name;
}
else
{
var buildNumber = AppVeyor.Environment.Build.Number.ToString("00000");
var branch = AppVeyor.Environment.Repository.Branch;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;

if (branch == "master" && !isPullRequest)
{
packageVersion = version + "-dev-" + buildNumber + dbgSuffix;
}
else
{
var suffix = "-ci-" + buildNumber + dbgSuffix;

if (isPullRequest)
suffix += "-pr-" + AppVeyor.Environment.PullRequest.Number;
else
suffix += "-" + branch;

// Nuget limits "special version part" to 20 chars. Add one for the hyphen.
if (suffix.Length > 21)
suffix = suffix.Substring(0, 21);

packageVersion = version + suffix;
}
}

AppVeyor.UpdateBuildVersion(packageVersion);
settings.UpdateAssemblyInfo = true;
settings.UpdateAssemblyInfoFilePath = "src/CommonAssemblyInfo.cs";
}

GitVersionInfo = GitVersion(settings);
Build = new BuildInfo(GitVersionInfo);
});

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

Task("Build")
.IsDependentOn("InitializeBuild")
.IsDependentOn("Clean")
.IsDependentOn("RestorePackages")
.IsDependentOn("SetBuildInfo")
.Does(() =>
{
if(IsRunningOnWindows())
Expand Down Expand Up @@ -167,9 +143,7 @@ Task("PackageZip")
BIN_DIR + "CHANGES.txt",
BIN_DIR + "nunit-gui.exe",
BIN_DIR + "nunit-gui.exe.config",
BIN_DIR + "nunit-gui.pdb",
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the motivation for not providing pdbs ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They break the build under Mono 4.6.2, which doesn't produce them. We could put them back if we used logic to include them only when they actually are present.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Let us just leave them out to begin with. Then we can always include them later.

BIN_DIR + "nunit.uikit.dll",
BIN_DIR + "nunit.uikit.pdb",
BIN_DIR + "nunit.engine.api.dll",
BIN_DIR + "nunit.engine.dll",
BIN_DIR + "Mono.Cecil.dll",
Expand All @@ -179,7 +153,7 @@ Task("PackageZip")
BIN_DIR + "nunit-agent-x86.exe.config"
};

Zip(BIN_DIR, File(ZIP_PACKAGE), zipFiles);
Zip(BIN_DIR, File(PACKAGE_DIR + "NUnit-Gui-" + Build.PackageVersion + ".zip"), zipFiles);
});

Task("PackageChocolatey")
Expand All @@ -188,12 +162,12 @@ Task("PackageChocolatey")
{
CreateDirectory(PACKAGE_DIR);

ChocolateyPack("choco/nunit-gui.nuspec",
new ChocolateyPackSettings()
{
Version = packageVersion,
OutputDirectory = PACKAGE_DIR,
Files = new ChocolateyNuSpecContent[]
ChocolateyPack("choco/nunit-gui.nuspec",
new ChocolateyPackSettings()
{
Version = Build.PackageVersion,
OutputDirectory = PACKAGE_DIR,
Files = new ChocolateyNuSpecContent[]
{
new ChocolateyNuSpecContent() { Source = "../LICENSE" },
new ChocolateyNuSpecContent() { Source = "../CHANGES.txt" },
Expand All @@ -211,16 +185,86 @@ Task("PackageChocolatey")
new ChocolateyNuSpecContent() { Source = "nunit-agent-x86.exe.ignore", Target="tools" },
new ChocolateyNuSpecContent() { Source = "nunit.choco.addins", Target="tools" }
}
});
});
});

//////////////////////////////////////////////////////////////////////
// TASK TARGETS
// BUILD INFO
//////////////////////////////////////////////////////////////////////

Task("Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
class BuildInfo
{
public BuildInfo(GitVersion gitVersion)
{
Version = gitVersion.MajorMinorPatch;
BranchName = gitVersion.BranchName;
BuildNumber = gitVersion.CommitsSinceVersionSourcePadded;

// Initially assume it's neither master nor a PR
IsMaster = false;
IsPullRequest = false;
PullRequestNumber = string.Empty;

if (BranchName == "master")
{
IsMaster = true;
PreReleaseSuffix = "dev-" + BuildNumber;
}
else
{
var re = new Regex(@"(pull|pull\-requests?|pr)[/-](\d*)[/-]");
var match = re.Match(BranchName);

if (match.Success)
{
IsPullRequest = true;
PullRequestNumber = match.Groups[2].Value;
PreReleaseSuffix = "pr-" + PullRequestNumber + "-" + BuildNumber;
}
else
{
PreReleaseSuffix = "ci-" + BuildNumber + "-" + Regex.Replace(BranchName, "[^0-9A-Za-z-]+", "-");
// Nuget limits "special version part" to 20 chars.
if (PreReleaseSuffix.Length > 20)
PreReleaseSuffix = PreReleaseSuffix.Substring(0, 20);
}
}

PackageVersion = Version + "-" + PreReleaseSuffix;

AssemblyVersion = gitVersion.AssemblySemVer;
AssemblyFileVersion = PackageVersion;
}

public string BranchName { get; private set; }
public string Version { get; private set; }
public bool IsMaster { get; private set; }
public bool IsPullRequest { get; private set; }
public string PullRequestNumber { get; private set; }
public string BuildNumber { get; private set; }
public string PreReleaseSuffix { get; private set; }
public string PackageVersion { get; private set; }

public string AssemblyVersion { get; private set; }
public string AssemblyFileVersion { get; private set; }

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

//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////

Task("Package")
.IsDependentOn("PackageZip")
Expand All @@ -232,7 +276,8 @@ Task("Appveyor")
.IsDependentOn("Package");

Task("Travis")
.IsDependentOn("Build");
.IsDependentOn("Build")
.IsDependentOn("PackageZip");

Task("Default")
.IsDependentOn("Build");
Expand Down
3 changes: 2 additions & 1 deletion src/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// Common version information for all assemblies.
// Common version information for local developer builds.
// Should be set to the NEXT planned version between releases.
// For CI builds, this info will be updated by GitVersion.
[assembly: AssemblyVersion("0.6.0.0")]
[assembly: AssemblyFileVersion("0.6.0.0")]