Merge pull request #44 from nunit/issue-42

Standardize build scripts
This commit is contained in:
CharliePoole 2021-09-14 07:17:56 -07:00 коммит произвёл GitHub
Родитель 0946b20117 d5e311c3f6
Коммит ebe9463d60
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 109 добавлений и 101 удалений

Просмотреть файл

@ -3,24 +3,28 @@
#tool nuget:?package=NUnit.ConsoleRunner&version=3.11.1
#tool nuget:?package=NUnit.ConsoleRunner&version=3.10.0
////////////////////////////////////////////////////////////////////
// PROJECT-SPECIFIC CONSTANTS
//////////////////////////////////////////////////////////////////////
const string SOLUTION_FILE = "nunit.v2.driver.sln";
const string NUGET_ID = "NUnit.Extension.NUnitV2Driver";
const string CHOCO_ID = "nunit-extension-nunit-v2-driver";
const string DEFAULT_VERSION = "3.9.0";
const string DEFAULT_CONFIGURATION = "Release";
// Load scripts after defining constants
#load cake/parameters.cake
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
// NOTE: These two constants are set here because constants.cake
// isn't loaded until after the arguments are parsed.
//
// Since GitVersion is only used when running under
// Windows, the default version should be updated to the
// next version after each release.
const string DEFAULT_VERSION = "3.9.0";
const string DEFAULT_CONFIGURATION = "Release";
var target = Argument("target", "Default");
// Load additional cake files here since some of them
// depend on the arguments provided.
#load cake/parameters.cake
// Additional arguments defined in the cake scripts:
// --configuration
// --version
//////////////////////////////////////////////////////////////////////
// SETUP AND TEARDOWN
@ -55,9 +59,19 @@ Task("DumpSettings")
Task("Clean")
.Does<BuildParameters>((parameters) =>
{
Information("Cleaning " + parameters.OutputDirectory);
CleanDirectory(parameters.OutputDirectory);
});
Task("CleanAll")
.Does<BuildParameters>((parameters) =>
{
Information("Cleaning all output directories");
CleanDirectory(parameters.ProjectDirectory + "bin/");
Information("Deleting object directories");
DeleteObjectDirectories(parameters);
});
//////////////////////////////////////////////////////////////////////
// INITIALIZE FOR BUILD
@ -68,7 +82,11 @@ Task("NuGetRestore")
{
NuGetRestore(SOLUTION_FILE, new NuGetRestoreSettings()
{
Source = PACKAGE_SOURCES
Source = new string[]
{
"https://www.nuget.org/api/v2",
"https://www.myget.org/F/nunit/api/v2"
}
});
});
@ -108,7 +126,7 @@ Task("Test")
.IsDependentOn("Build")
.Does<BuildParameters>((parameters) =>
{
NUnit3(parameters.OutputDirectory + UNIT_TEST_ASSEMBLY);
NUnit3(parameters.OutputDirectory + "nunit.v2.driver.tests.dll");
});
//////////////////////////////////////////////////////////////////////
@ -151,7 +169,7 @@ Task("TestNuGetPackage")
.IsDependentOn("InstallNuGetPackage")
.Does<BuildParameters>((parameters) =>
{
new NuGetPackageTester(parameters).RunPackageTests();
new NuGetPackageTester(parameters).RunPackageTests(PackageTests);
});
Task("BuildChocolateyPackage")
@ -197,9 +215,30 @@ Task("TestChocolateyPackage")
//using (var writer = new StreamWriter(runnerDir + "/choco.engine.addins"))
// writer.WriteLine("../../nunit-extension-*/tools/");
new ChocolateyPackageTester(parameters).RunPackageTests();
new ChocolateyPackageTester(parameters).RunPackageTests(PackageTests);
});
PackageTest[] PackageTests = new PackageTest[]
{
new PackageTest()
{
Description = "Integration Tests using NUnit V2",
Arguments = "bin/Release/v2-tests/v2-test-assembly.dll",
TestConsoleVersions = new string[] { "3.12.0", "3.11.1", "3.10.0" },
ExpectedResult = new ExpectedResult("Passed")
{
Total = 75,
Passed = 75,
Failed = 0,
Warnings = 0,
Inconclusive = 0,
Skipped = 0,
Assemblies = new[] { new ExpectedAssemblyResult(
System.IO.Path.GetFullPath("bin/Release/v2-tests/v2-test-assembly.dll"), "net-2.0") }
}
}
};
//////////////////////////////////////////////////////////////////////
// PUBLISH
//////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -44,7 +44,7 @@ Param(
[string]$Target = "Default",
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Verbose",
[string]$Verbosity = "Normal",
[switch]$Experimental,
[Alias("DryRun","Noop")]
[switch]$WhatIf,

Просмотреть файл

@ -1,37 +0,0 @@
// This file contains both constants and static readonly values, which
// are used as constants. The latter must not depend in any way on the
// contents of other cake files, which are loaded after this one.
// Files
const string SOLUTION_FILE = "nunit.v2.driver.sln";
const string UNIT_TEST_ASSEMBLY = "nunit.v2.driver.tests.dll";
// Packaging
const string NUGET_ID = "NUnit.Extension.NUnitV2Driver";
const string CHOCO_ID = "nunit-extension-nunit-v2-driver";
// Package sources for nuget restore - used in build.cake
static readonly string[] PACKAGE_SOURCES = new string[]
{
"https://www.nuget.org/api/v2",
"https://www.myget.org/F/nunit/api/v2"
};
// The following items are only used in parameters.cake
// URLs for uploading packages
private const string MYGET_PUSH_URL = "https://www.myget.org/F/nunit/api/v2";
private const string NUGET_PUSH_URL = "https://api.nuget.org/v3/index.json";
private const string CHOCO_PUSH_URL = "https://push.chocolatey.org/";
// Environment Variable names holding API keys
private const string MYGET_API_KEY = "MYGET_API_KEY";
private const string NUGET_API_KEY = "NUGET_API_KEY";
private const string CHOCO_API_KEY = "CHOCO_API_KEY";
private const string GITHUB_ACCESS_TOKEN = "GITHUB_ACCESS_TOKEN";
// Pre-release labels that we publish
private static readonly string[] LABELS_WE_PUBLISH_ON_MYGET = { "dev", "pre" };
private static readonly string[] LABELS_WE_PUBLISH_ON_NUGET = { "alpha", "beta", "rc" };
private static readonly string[] LABELS_WE_PUBLISH_ON_CHOCOLATEY = { "alpha", "beta", "rc" };
private static readonly string[] LABELS_WE_RELEASE_ON_GITHUB = { "alpha", "beta", "rc" };

Просмотреть файл

@ -27,38 +27,17 @@ public abstract class PackageTester
{
_parameters = parameters;
_context = parameters.Context;
PackageTests.Add(new PackageTest()
{
Description = "Integration Tests using NUnit V2",
Arguments = "bin/Release/v2-tests/v2-test-assembly.dll",
TestConsoleVersions = new string[] { "3.12.0", "3.11.1", "3.10.0" },
ExpectedResult = new ExpectedResult("Passed")
{
Total = 75,
Passed = 75,
Failed = 0,
Warnings = 0,
Inconclusive = 0,
Skipped = 0,
Assemblies = new[] { new ExpectedAssemblyResult(
System.IO.Path.GetFullPath("bin/Release/v2-tests/v2-test-assembly.dll"), "net-2.0") }
}
});
}
protected abstract string PackageName { get; }
protected abstract string PackageUnderTest { get; }
public abstract string InstallDirectory { get; }
public PackageCheck[] PackageChecks { get; set; }
public List<PackageTest> PackageTests = new List<PackageTest>();
public void RunPackageTests()
public void RunPackageTests(IList<PackageTest> packageTests)
{
var reporter = new ResultReporter(PackageName);
foreach (var packageTest in PackageTests)
foreach (var packageTest in packageTests)
{
foreach (var consoleVersion in packageTest.TestConsoleVersions)
{

Просмотреть файл

@ -104,22 +104,3 @@ public void BuildChocolateyPackage(BuildParameters parameters)
}
});
}
private void PushNuGetPackage(FilePath package, string apiKey, string url)
{
CheckPackageExists(package);
NuGetPush(package, new NuGetPushSettings() { ApiKey = apiKey, Source = url });
}
private void PushChocolateyPackage(FilePath package, string apiKey, string url)
{
CheckPackageExists(package);
ChocolateyPush(package, new ChocolateyPushSettings() { ApiKey = apiKey, Source = url });
}
private void CheckPackageExists(FilePath package)
{
if (!FileExists(package))
throw new InvalidOperationException(
$"Package not found: {package.GetFilename()}.\nCode may have changed since package was last built.");
}

Просмотреть файл

@ -1,13 +1,30 @@
#load "./constants.cake"
#load "./versioning.cake"
#load "./versioning.cake"
#load "./packaging.cake"
#load "./package-checks.cake"
#load "./package-tests.cake"
#load "./test-results.cake"
#load "./test-reports.cake"
#load "./utilities.cake"
using System;
// URLs for uploading packages
private const string MYGET_PUSH_URL = "https://www.myget.org/F/nunit/api/v2";
private const string NUGET_PUSH_URL = "https://api.nuget.org/v3/index.json";
private const string CHOCO_PUSH_URL = "https://push.chocolatey.org/";
// Environment Variable names holding API keys
private const string MYGET_API_KEY = "MYGET_API_KEY";
private const string NUGET_API_KEY = "NUGET_API_KEY";
private const string CHOCO_API_KEY = "CHOCO_API_KEY";
private const string GITHUB_ACCESS_TOKEN = "GITHUB_ACCESS_TOKEN";
// Pre-release labels that we publish
private static readonly string[] LABELS_WE_PUBLISH_ON_MYGET = { "dev", "pre" };
private static readonly string[] LABELS_WE_PUBLISH_ON_NUGET = { "alpha", "beta", "rc" };
private static readonly string[] LABELS_WE_PUBLISH_ON_CHOCOLATEY = { "alpha", "beta", "rc" };
private static readonly string[] LABELS_WE_RELEASE_ON_GITHUB = { "alpha", "beta", "rc" };
public class BuildParameters
{
private ISetupContext _context;
@ -63,8 +80,7 @@ public class BuildParameters
public string ProjectDirectory { get; }
public string OutputDirectory => ProjectDirectory + "bin/" + Configuration + "/";
public string Net20OutputDirectory => OutputDirectory + "net20/";
public string NetCore21OutputDirectory => OutputDirectory + "netcoreapp2.1/";
public string SourceDirectory => ProjectDirectory + "src/";
public string PackageDirectory => ProjectDirectory + "output/";
public string ToolsDirectory => ProjectDirectory + "tools/";
public string NuGetInstallDirectory => ToolsDirectory + NUGET_ID + "/";

30
cake/utilities.cake Normal file
Просмотреть файл

@ -0,0 +1,30 @@
//////////////////////////////////////////////////////////////////////
// GLOBALLY ACCESSIBLE UTILITY METHODS
//////////////////////////////////////////////////////////////////////
public void DeleteObjectDirectories(BuildParameters parameters)
{
string pattern = parameters.SourceDirectory + "**/obj/";
foreach (var dir in GetDirectories(pattern))
DeleteDirectory(dir, new DeleteDirectorySettings() { Recursive = true });
}
private void PushNuGetPackage(FilePath package, string apiKey, string url)
{
CheckPackageExists(package);
NuGetPush(package, new NuGetPushSettings() { ApiKey = apiKey, Source = url });
}
private void PushChocolateyPackage(FilePath package, string apiKey, string url)
{
CheckPackageExists(package);
ChocolateyPush(package, new ChocolateyPushSettings() { ApiKey = apiKey, Source = url });
}
private void CheckPackageExists(FilePath package)
{
if (!FileExists(package))
throw new InvalidOperationException(
$"Package not found: {package.GetFilename()}.\nCode may have changed since package was last built.");
}

Просмотреть файл

@ -26,13 +26,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.v2.driver.tests", "sr
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cake", "cake", "{0E1320F6-992A-48FA-871B-5FD018BD8BE8}"
ProjectSection(SolutionItems) = preProject
cake\constants.cake = cake\constants.cake
cake\package-checks.cake = cake\package-checks.cake
cake\package-tests.cake = cake\package-tests.cake
cake\packaging.cake = cake\packaging.cake
cake\parameters.cake = cake\parameters.cake
cake\test-reports.cake = cake\test-reports.cake
cake\test-results.cake = cake\test-results.cake
cake\utilities.cake = cake\utilities.cake
cake\versioning.cake = cake\versioning.cake
EndProjectSection
EndProject