Add code for publishing to nuget and chocolatey

This commit is contained in:
Charlie Poole 2021-09-13 05:48:07 -07:00
Родитель 68d92cdacb
Коммит 03c8c78c3c
5 изменённых файлов: 51 добавлений и 23 удалений

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

@ -13,3 +13,7 @@ artifacts:
environment: environment:
MYGET_API_KEY: MYGET_API_KEY:
secure: wtAvJDVl2tfwiVcyLExFHLvZVfUWiQRHsfdHBFCNEATeCHo1Nd8JP642PfY8xhji secure: wtAvJDVl2tfwiVcyLExFHLvZVfUWiQRHsfdHBFCNEATeCHo1Nd8JP642PfY8xhji
NUGET_API_KEY:
secure: 3ojZLs9hiHk/7047hiirFk/qG2RxUACmA8DAUk+8AoILr5R7c4tDGXeTsBjjhq5h
CHOCO_API_KEY:
secure: aDsu1U+umVYFVybjkBVtVQsatSj3QKbD7VkGQci9mNF3493g9Giao/GABISIaHjT

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

@ -130,12 +130,11 @@ Task("BuildNuGetPackage")
}); });
Task("InstallNuGetPackage") Task("InstallNuGetPackage")
//.IsDependentOn("RemoveChocolateyPackageIfPresent") // So both are not present
.Does<BuildParameters>((parameters) => .Does<BuildParameters>((parameters) =>
{ {
// Ensure we aren't inadvertently using the chocolatey install // Ensure we aren't inadvertently using the chocolatey install
if (DirectoryExists(parameters.ChocolateyInstallDirectory)) if (DirectoryExists(parameters.ChocolateyInstallDirectory))
DeleteDirectory(parameters.ChocolateyInstallDirectory, new DeleteDirectorySettings() { Recursive = true }); DeleteDirectory(parameters.ChocolateyInstallDirectory, new DeleteDirectorySettings() { Recursive = true });
CreateDirectory(parameters.NuGetInstallDirectory); CreateDirectory(parameters.NuGetInstallDirectory);
CleanDirectory(parameters.NuGetInstallDirectory); CleanDirectory(parameters.NuGetInstallDirectory);
@ -170,12 +169,11 @@ Task("BuildChocolateyPackage")
}); });
Task("InstallChocolateyPackage") Task("InstallChocolateyPackage")
//.IsDependentOn("RemoveNuGetPackageIfPresent") // So both are not present
.Does<BuildParameters>((parameters) => .Does<BuildParameters>((parameters) =>
{ {
// Ensure we aren't inadvertently using the nuget install // Ensure we aren't inadvertently using the nuget install
if (DirectoryExists(parameters.NuGetInstallDirectory)) if (DirectoryExists(parameters.NuGetInstallDirectory))
DeleteDirectory(parameters.NuGetInstallDirectory, new DeleteDirectorySettings() { Recursive = true }); DeleteDirectory(parameters.NuGetInstallDirectory, new DeleteDirectorySettings() { Recursive = true });
CreateDirectory(parameters.ChocolateyInstallDirectory); CreateDirectory(parameters.ChocolateyInstallDirectory);
CleanDirectory(parameters.ChocolateyInstallDirectory); CleanDirectory(parameters.ChocolateyInstallDirectory);
@ -211,8 +209,8 @@ static bool hadPublishingErrors = false;
Task("PublishPackages") Task("PublishPackages")
.Description("Publish nuget and chocolatey packages according to the current settings") .Description("Publish nuget and chocolatey packages according to the current settings")
.IsDependentOn("PublishToMyGet") .IsDependentOn("PublishToMyGet")
// .IsDependentOn("PublishToNuGet") .IsDependentOn("PublishToNuGet")
// .IsDependentOn("PublishToChocolatey") .IsDependentOn("PublishToChocolatey")
.Does(() => .Does(() =>
{ {
if (hadPublishingErrors) if (hadPublishingErrors)
@ -239,6 +237,44 @@ Task("PublishToMyGet")
} }
}); });
// This task may either be run by the PublishPackages task,
// which depends on it, or directly when recovering from errors.
Task("PublishToNuGet")
.Description("Publish packages to NuGet")
.Does<BuildParameters>((parameters) =>
{
if (!parameters.ShouldPublishToNuGet)
Information("Nothing to publish to NuGet from this run.");
else
try
{
PushNuGetPackage(parameters.NuGetPackage, parameters.NuGetApiKey, parameters.NuGetPushUrl);
}
catch (Exception)
{
hadPublishingErrors = true;
}
});
// This task may either be run by the PublishPackages task,
// which depends on it, or directly when recovering from errors.
Task("PublishToChocolatey")
.Description("Publish packages to Chocolatey")
.Does<BuildParameters>((parameters) =>
{
if (!parameters.ShouldPublishToChocolatey)
Information("Nothing to publish to Chocolatey from this run.");
else
try
{
PushChocolateyPackage(parameters.ChocolateyPackage, parameters.ChocolateyApiKey, parameters.ChocolateyPushUrl);
}
catch (Exception)
{
hadPublishingErrors = true;
}
});
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// TASK TARGETS // TASK TARGETS
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

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

@ -11,8 +11,6 @@ const string MOCK_ASSEMBLY = "mock-assembly.dll";
// Packaging // Packaging
const string NUGET_ID = "NUnit.Extension.NUnitV2ResultWriter"; const string NUGET_ID = "NUnit.Extension.NUnitV2ResultWriter";
const string CHOCO_ID = "nunit-extension-nunit-v2-result-writer"; const string CHOCO_ID = "nunit-extension-nunit-v2-result-writer";
//const string GITHUB_SITE = "https://github.com/nunit/nunit-v2-project-loader";
//const string WIKI_PAGE = "https://github.com/nunit/docs/wiki/Console-Command-Line";
// Package sources for nuget restore // Package sources for nuget restore
static readonly string[] PACKAGE_SOURCES = new string[] static readonly string[] PACKAGE_SOURCES = new string[]
@ -21,8 +19,6 @@ static readonly string[] PACKAGE_SOURCES = new string[]
"https://www.myget.org/F/nunit/api/v2" "https://www.myget.org/F/nunit/api/v2"
}; };
const string DEFAULT_TEST_RESULT_FILE = "TestResult.xml";
// URLs for uploading packages // URLs for uploading packages
private const string MYGET_PUSH_URL = "https://www.myget.org/F/nunit/api/v2"; 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 NUGET_PUSH_URL = "https://api.nuget.org/v3/index.json";
@ -32,11 +28,6 @@ private const string CHOCO_PUSH_URL = "https://push.chocolatey.org/";
private const string MYGET_API_KEY = "MYGET_API_KEY"; private const string MYGET_API_KEY = "MYGET_API_KEY";
private const string NUGET_API_KEY = "NUGET_API_KEY"; private const string NUGET_API_KEY = "NUGET_API_KEY";
private const string CHOCO_API_KEY = "CHOCO_API_KEY"; private const string CHOCO_API_KEY = "CHOCO_API_KEY";
// Environment Variable names holding GitHub identity of user
private const string GITHUB_OWNER = "NUnit";
private const string GITHUB_REPO = "v2-result-writer";
// Access token is used by GitReleaseManager
private const string GITHUB_ACCESS_TOKEN = "GITHUB_ACCESS_TOKEN"; private const string GITHUB_ACCESS_TOKEN = "GITHUB_ACCESS_TOKEN";
// Pre-release labels that we publish // Pre-release labels that we publish

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

@ -80,8 +80,6 @@ public abstract class PackageTester
foreach (var packageTest in PackageTests) foreach (var packageTest in PackageTests)
{ {
var resultFile = _parameters.OutputDirectory + DEFAULT_TEST_RESULT_FILE;
foreach (var consoleVersion in packageTest.TestConsoleVersions) foreach (var consoleVersion in packageTest.TestConsoleVersions)
{ {
// Delete result files ahead of time so we don't mistakenly // Delete result files ahead of time so we don't mistakenly
@ -156,12 +154,6 @@ public abstract class PackageTester
} }
_context.StartProcess(runner, arguments); _context.StartProcess(runner, arguments);
// We don't check the error code because we know that
// mock-assembly returns -4 due to a bad fixture.
// Should have created the result file
if (!_context.FileExists(DEFAULT_TEST_RESULT_FILE))
throw new System.Exception("The result file was not created.");
} }
private void DisplayBanner(string message) private void DisplayBanner(string message)

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

@ -28,10 +28,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cake", "cake", "{C60D66FA-F
cake\assertions.cake = cake\assertions.cake cake\assertions.cake = cake\assertions.cake
cake\constants.cake = cake\constants.cake cake\constants.cake = cake\constants.cake
cake\constraints.cake = cake\constraints.cake cake\constraints.cake = cake\constraints.cake
cake\package-checks.cake = cake\package-checks.cake
cake\package-tests.cake = cake\package-tests.cake
cake\packaging.cake = cake\packaging.cake cake\packaging.cake = cake\packaging.cake
cake\parameters.cake = cake\parameters.cake cake\parameters.cake = cake\parameters.cake
cake\test-reports.cake = cake\test-reports.cake
cake\test-results.cake = cake\test-results.cake
cake\test-runner.cake = cake\test-runner.cake cake\test-runner.cake = cake\test-runner.cake
cake\tests.cake = cake\tests.cake cake\tests.cake = cake\tests.cake
cake\versioning.cake = cake\versioning.cake
EndProjectSection EndProjectSection
EndProject EndProject
Global Global