386 строки
12 KiB
C#
386 строки
12 KiB
C#
//////////////////////////////////////////////////////////////////////
|
|
// ARGUMENTS
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
var target = Argument("target", "Default");
|
|
var configuration = Argument("configuration", "Debug");
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// SET ERROR LEVELS
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
var ErrorDetail = new List<string>();
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// SET PACKAGE VERSION
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
var version = "3.6.0";
|
|
var modifier = "";
|
|
|
|
//Find program files on 32-bit or 64-bit Windows
|
|
var programFiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)") ?? Environment.GetEnvironmentVariable("ProgramFiles");
|
|
var isSilverlightSDKInstalled = FileExists(programFiles + "\\MSBuild\\Microsoft\\Silverlight\\v5.0\\Microsoft.Silverlight.CSharp.targets");
|
|
|
|
var isAppveyor = BuildSystem.IsRunningOnAppVeyor;
|
|
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
|
|
var packageVersion = version + modifier + dbgSuffix;
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// DEFINE RUN CONSTANTS
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
|
|
var PACKAGE_DIR = PROJECT_DIR + "package/";
|
|
var BIN_DIR = PROJECT_DIR + "bin/" + configuration + "/";
|
|
var IMAGE_DIR = PROJECT_DIR + "images/";
|
|
|
|
var SOLUTION_FILE = "./nunit-sl.sln";
|
|
|
|
// Package sources for nuget restore
|
|
var PACKAGE_SOURCE = new string[]
|
|
{
|
|
"https://www.nuget.org/api/v2",
|
|
"https://www.myget.org/F/nunit/api/v2"
|
|
};
|
|
|
|
// Test Runners
|
|
var NUNITLITE_RUNNER = "nunitlite-runner.exe";
|
|
|
|
// Test Assemblies
|
|
var FRAMEWORK_TESTS = "nunit.framework.tests.dll";
|
|
var NUNITLITE_TESTS = "nunitlite.tests.dll";
|
|
|
|
// Packages
|
|
var SRC_PACKAGE = PACKAGE_DIR + "NUnitSL-" + version + modifier + "-src.zip";
|
|
var ZIP_PACKAGE = PACKAGE_DIR + "NUnitSL-" + packageVersion + ".zip";
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// CLEAN
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
Task("Clean")
|
|
.Does(() =>
|
|
{
|
|
CleanDirectory(BIN_DIR);
|
|
});
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// INITIALIZE FOR BUILD
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
Task("InitializeBuild")
|
|
.Does(() =>
|
|
{
|
|
NuGetRestore(SOLUTION_FILE, new NuGetRestoreSettings()
|
|
{
|
|
Source = PACKAGE_SOURCE
|
|
});
|
|
|
|
if (isAppveyor)
|
|
{
|
|
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 if (AppVeyor.Environment.Repository.Branch.StartsWith("release", StringComparison.OrdinalIgnoreCase))
|
|
suffix += "-pre-" + buildNumber;
|
|
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);
|
|
}
|
|
});
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// BUILD FRAMEWORKS
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
Task("Build")
|
|
.IsDependentOn("InitializeBuild")
|
|
.WithCriteria(IsRunningOnWindows())
|
|
.Does(() =>
|
|
{
|
|
if(isSilverlightSDKInstalled)
|
|
{
|
|
BuildProject("src/NUnitFramework/framework/nunit.framework-sl-5.0.csproj", configuration);
|
|
BuildProject("src/NUnitFramework/nunitlite/nunitlite-sl-5.0.csproj", configuration);
|
|
BuildProject("src/NUnitFramework/mock-assembly/mock-assembly-sl-5.0.csproj", configuration);
|
|
BuildProject("src/NUnitFramework/testdata/nunit.testdata-sl-5.0.csproj", configuration);
|
|
BuildProject("src/NUnitFramework/tests/nunit.framework.tests-sl-5.0.csproj", configuration);
|
|
BuildProject("src/NUnitFramework/nunitlite.tests/nunitlite.tests-sl-5.0.csproj", configuration);
|
|
BuildProject("src/NUnitFramework/nunitlite-runner/nunitlite-runner-sl-5.0.csproj", configuration);
|
|
}
|
|
else
|
|
{
|
|
Warning("Silverlight build skipped because files were not present.");
|
|
if(isAppveyor)
|
|
throw new Exception("Running Build on Appveyor, but Silverlight not found.");
|
|
}
|
|
});
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// TEST
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
Task("CheckForError")
|
|
.Does(() => CheckForError(ref ErrorDetail));
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// TEST FRAMEWORK
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
Task("Test")
|
|
.WithCriteria(IsRunningOnWindows())
|
|
.IsDependentOn("Build")
|
|
.OnError(exception => { ErrorDetail.Add(exception.Message); })
|
|
.Does(() =>
|
|
{
|
|
if(isSilverlightSDKInstalled)
|
|
{
|
|
var runtime = "sl-5.0";
|
|
var dir = BIN_DIR + runtime + "/";
|
|
RunTest(dir + NUNITLITE_RUNNER, dir, FRAMEWORK_TESTS, runtime, ref ErrorDetail);
|
|
RunTest(dir + NUNITLITE_RUNNER, dir, NUNITLITE_TESTS, runtime, ref ErrorDetail);
|
|
}
|
|
else
|
|
{
|
|
Warning("Silverlight tests skipped because files were not present.");
|
|
}
|
|
});
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// PACKAGE
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
var RootFiles = new FilePath[]
|
|
{
|
|
"LICENSE.txt",
|
|
"NOTICES.txt",
|
|
"CHANGES.txt"
|
|
};
|
|
|
|
var FrameworkFiles = new FilePath[]
|
|
{
|
|
"AppManifest.xaml",
|
|
"mock-assembly.dll",
|
|
"nunit.framework.dll",
|
|
"nunit.framework.xml",
|
|
"nunit.framework.tests.dll",
|
|
"nunit.framework.tests.xap",
|
|
"nunit.framework.tests_TestPage.html",
|
|
"nunit.testdata.dll",
|
|
"nunitlite.dll",
|
|
"nunitlite.tests.dll",
|
|
"slow-nunit-tests.dll",
|
|
"nunitlite-runner.exe",
|
|
};
|
|
|
|
Task("PackageSource")
|
|
.Does(() =>
|
|
{
|
|
CreateDirectory(PACKAGE_DIR);
|
|
RunGitCommand(string.Format("archive -o {0} HEAD", SRC_PACKAGE));
|
|
});
|
|
|
|
Task("CreateImage")
|
|
.Does(() =>
|
|
{
|
|
var currentImageDir = IMAGE_DIR + "NUnit-" + packageVersion + "/";
|
|
var imageBinDir = currentImageDir + "bin/";
|
|
|
|
CleanDirectory(currentImageDir);
|
|
|
|
CopyFiles(RootFiles, currentImageDir);
|
|
|
|
CreateDirectory(imageBinDir);
|
|
Information("Created directory " + imageBinDir);
|
|
|
|
var runtime = "sl-5.0";
|
|
var targetDir = imageBinDir + Directory(runtime);
|
|
var sourceDir = BIN_DIR + Directory(runtime);
|
|
CreateDirectory(targetDir);
|
|
foreach (FilePath file in FrameworkFiles)
|
|
{
|
|
var sourcePath = sourceDir + "/" + file;
|
|
if (FileExists(sourcePath))
|
|
CopyFileToDirectory(sourcePath, targetDir);
|
|
}
|
|
});
|
|
|
|
Task("PackageFramework")
|
|
.IsDependentOn("CreateImage")
|
|
.Does(() =>
|
|
{
|
|
var currentImageDir = IMAGE_DIR + "NUnit-" + packageVersion + "/";
|
|
|
|
CreateDirectory(PACKAGE_DIR);
|
|
|
|
NuGetPack("nuget/framework/nunitSL.nuspec", new NuGetPackSettings()
|
|
{
|
|
Version = packageVersion,
|
|
BasePath = currentImageDir,
|
|
OutputDirectory = PACKAGE_DIR
|
|
});
|
|
|
|
NuGetPack("nuget/nunitlite/nunitliteSL.nuspec", new NuGetPackSettings()
|
|
{
|
|
Version = packageVersion,
|
|
BasePath = currentImageDir,
|
|
OutputDirectory = PACKAGE_DIR
|
|
});
|
|
});
|
|
|
|
Task("PackageZip")
|
|
.IsDependentOn("CreateImage")
|
|
.Does(() =>
|
|
{
|
|
CreateDirectory(PACKAGE_DIR);
|
|
|
|
var currentImageDir = IMAGE_DIR + "NUnit-" + packageVersion + "/";
|
|
|
|
var zipFiles =
|
|
GetFiles(currentImageDir + "*.*") +
|
|
GetFiles(currentImageDir + "bin/sl-5.0/*.*");
|
|
Zip(currentImageDir, File(ZIP_PACKAGE), zipFiles);
|
|
});
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// UPLOAD ARTIFACTS
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
Task("UploadArtifacts")
|
|
.IsDependentOn("Package")
|
|
.Does(() =>
|
|
{
|
|
UploadArtifacts(PACKAGE_DIR, "*.nupkg");
|
|
UploadArtifacts(PACKAGE_DIR, "*.zip");
|
|
});
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// SETUP AND TEARDOWN TASKS
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
Teardown(context => CheckForError(ref ErrorDetail));
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// HELPER METHODS - GENERAL
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
void RunGitCommand(string arguments)
|
|
{
|
|
StartProcess("git", new ProcessSettings()
|
|
{
|
|
Arguments = arguments
|
|
});
|
|
}
|
|
|
|
void UploadArtifacts(string packageDir, string searchPattern)
|
|
{
|
|
foreach(var zip in System.IO.Directory.GetFiles(packageDir, searchPattern))
|
|
AppVeyor.UploadArtifact(zip);
|
|
}
|
|
|
|
void CheckForError(ref List<string> errorDetail)
|
|
{
|
|
if(errorDetail.Count != 0)
|
|
{
|
|
var copyError = new List<string>();
|
|
copyError = errorDetail.Select(s => s).ToList();
|
|
errorDetail.Clear();
|
|
throw new Exception("One or more unit tests failed, breaking the build.\n"
|
|
+ copyError.Aggregate((x,y) => x + "\n" + y));
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// HELPER METHODS - BUILD
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
void BuildProject(string projectPath, string configuration)
|
|
{
|
|
if(!IsRunningOnWindows()) return;
|
|
|
|
MSBuild(projectPath, new MSBuildSettings()
|
|
.SetConfiguration(configuration)
|
|
.SetMSBuildPlatform(MSBuildPlatform.x86)
|
|
.UseToolVersion(MSBuildToolVersion.Default)
|
|
.SetVerbosity(Verbosity.Minimal)
|
|
.SetNodeReuse(false));
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// HELPER METHODS - TEST
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
void RunTest(FilePath exePath, DirectoryPath workingDir, string arguments, string framework, ref List<string> errorDetail)
|
|
{
|
|
int rc = StartProcess(
|
|
MakeAbsolute(exePath),
|
|
new ProcessSettings()
|
|
{
|
|
Arguments = arguments,
|
|
WorkingDirectory = workingDir
|
|
});
|
|
|
|
if (rc > 0)
|
|
errorDetail.Add(string.Format("{0}: {1} tests failed", framework, rc));
|
|
else if (rc < 0)
|
|
errorDetail.Add(string.Format("{0} returned rc = {1}", exePath, rc));
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// TASK TARGETS
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
Task("Rebuild")
|
|
.IsDependentOn("Clean")
|
|
.IsDependentOn("Build");
|
|
|
|
Task("Package")
|
|
.IsDependentOn("CheckForError")
|
|
.IsDependentOn("PackageFramework")
|
|
.IsDependentOn("PackageZip");
|
|
|
|
Task("Appveyor")
|
|
.IsDependentOn("Build")
|
|
.IsDependentOn("Test")
|
|
.IsDependentOn("Package")
|
|
.IsDependentOn("UploadArtifacts");
|
|
|
|
Task("Default")
|
|
.IsDependentOn("Build");
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// EXECUTION
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
RunTarget(target);
|