nunit-v2-framework-driver/build.cake

234 строки
5.8 KiB
C#

#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.1
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
//////////////////////////////////////////////////////////////////////
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////
var version = "3.5.0";
var modifier = "";
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
if (BuildSystem.IsRunningOnAppVeyor)
{
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);
suffix = suffix.Replace(".", "");
packageVersion = version + suffix;
}
}
AppVeyor.UpdateBuildVersion(packageVersion);
}
var packageName = "NUnitV2Driver-" + packageVersion;
//////////////////////////////////////////////////////////////////////
// DEFINE RUN CONSTANTS
//////////////////////////////////////////////////////////////////////
// Directories
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var PACKAGE_DIR = PROJECT_DIR + "package/";
var PACKAGE_IMAGE_DIR = PACKAGE_DIR + packageName + "/";
var TOOLS_DIR = PROJECT_DIR + "tools/";
var BIN_DIR = PROJECT_DIR + "bin/" + configuration + "/";
// Solution
var SOLUTION_FILE = PROJECT_DIR + "nunit.v2.driver.sln";
// Test Runner
var NUNIT3_CONSOLE = TOOLS_DIR + "NUnit.ConsoleRunner/tools/nunit3-console.exe";
// Test Assembly
var DRIVER_TESTS = BIN_DIR + "nunit.v2.driver.tests.dll";
//////////////////////////////////////////////////////////////////////
// CLEAN
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(BIN_DIR);
});
//////////////////////////////////////////////////////////////////////
// INITIALIZE FOR BUILD
//////////////////////////////////////////////////////////////////////
Task("NuGetRestore")
.Does(() =>
{
NuGetRestore(SOLUTION_FILE);
});
//////////////////////////////////////////////////////////////////////
// BUILD
//////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("NuGetRestore")
.Does(() =>
{
BuildSolution(SOLUTION_FILE, configuration);
});
//////////////////////////////////////////////////////////////////////
// TEST
//////////////////////////////////////////////////////////////////////
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
int rc = StartProcess(
NUNIT3_CONSOLE,
new ProcessSettings()
{
Arguments = DRIVER_TESTS
});
if (rc != 0)
{
var message = rc > 0
? string.Format("Test failure: {0} tests failed", rc)
: string.Format("Test exited with rc = {0}", rc);
throw new CakeException(message);
}
});
//////////////////////////////////////////////////////////////////////
// PACKAGE
//////////////////////////////////////////////////////////////////////
Task("CreatePackageDir")
.Does(() =>
{
CreateDirectory(PACKAGE_DIR);
});
Task("CreateWorkingImage")
.IsDependentOn("Build")
.IsDependentOn("CreatePackageDir")
.Does(() =>
{
CreateDirectory(PACKAGE_IMAGE_DIR);
CleanDirectory(PACKAGE_IMAGE_DIR);
CopyFileToDirectory("LICENSE.txt", PACKAGE_IMAGE_DIR);
var binFiles = new FilePath[]
{
BIN_DIR + "NUnit3.TestAdapter.dll",
BIN_DIR + "nunit.engine.dll",
BIN_DIR + "nunit.engine.api.dll",
BIN_DIR + "Mono.Cecil.dll",
BIN_DIR + "Mono.Cecil.Pdb.dll",
BIN_DIR + "Mono.Cecil.Mdb.dll",
BIN_DIR + "Mono.Cecil.Rocks.dll"
};
var binDir = PACKAGE_IMAGE_DIR + "bin/";
CreateDirectory(binDir);
CopyFiles(binFiles, binDir);
});
Task("PackageZip")
.IsDependentOn("CreateWorkingImage")
.Does(() =>
{
Zip(PACKAGE_IMAGE_DIR, File(PACKAGE_DIR + packageName + ".zip"));
});
Task("PackageNuGet")
.IsDependentOn("CreateWorkingImage")
.Does(() =>
{
NuGetPack("nuget/NUnit3TestAdapter.nuspec", new NuGetPackSettings()
{
Version = packageVersion,
BasePath = PACKAGE_IMAGE_DIR,
OutputDirectory = PACKAGE_DIR
});
});
//////////////////////////////////////////////////////////////////////
// HELPER METHODS
//////////////////////////////////////////////////////////////////////
void BuildSolution(string solutionPath, string configuration)
{
MSBuild(solutionPath, new MSBuildSettings()
.SetConfiguration(configuration)
.SetMSBuildPlatform(MSBuildPlatform.x86)
.SetVerbosity(Verbosity.Minimal)
.SetNodeReuse(false)
);
}
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
Task("Package")
.IsDependentOn("Build")
.IsDependentOn("PackageZip")
.IsDependentOn("PackageNuGet");
Task("Appveyor")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package");
Task("Default")
.IsDependentOn("Build");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);