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

Commit

Permalink
Merge pull request #226 from NUnitSoftware/issue-206
Browse files Browse the repository at this point in the history
Initial use of GitVersion
  • Loading branch information
CharliePoole authored Sep 8, 2017
2 parents 5880fff + 62a1cfd commit e0699e2
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 67 deletions.
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
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",
"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;

//////////////////////////////////////////////////////////////////////
// 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",
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")]

0 comments on commit e0699e2

Please sign in to comment.