Skip to content

Commit d74da04

Browse files
authored
Merge pull request #1448 from nunit/issue-1447
Add target for re-publishing symbol packages
2 parents 91edb30 + 533876c commit d74da04

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

build.cake

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,65 @@ public class ConsoleRunnerSelfTester : TestRunner, IPackageTestRunner
407407
}
408408
}
409409

410+
//////////////////////////////////////////////////////////////////////
411+
// ADDITIONAL TARGETS USED FOR RECOVERY AND DEBUGGING
412+
//////////////////////////////////////////////////////////////////////
413+
414+
// Some of these targets may be moved into the recipe itself in the future.
415+
416+
// When a NuGet package was published successfully but the corresponding symbols
417+
// package failed, use this target locally after correcting the error.
418+
// TODO: This task is extemely complicated because it has to copy lots of code
419+
// from the recipe. It would be simpler if it were integrated in the recipe.
420+
// TODO: This has been tested on NUnit.ConsoleRunner, so the branches with either
421+
// zero or one packages are speculative at this point. They will need testing
422+
// if this is incorporated into the recipe.
423+
Task("PublishSymbolsPackage")
424+
.Description("Re-publish a specific symbols package to NuGet after a failure")
425+
.Does(() =>
426+
{
427+
if (!BuildSettings.ShouldPublishToNuGet)
428+
Information("Nothing to publish to NuGet from this run.");
429+
else if (CommandLineOptions.NoPush)
430+
Information("NoPush option suppressing publication to NuGet");
431+
else
432+
{
433+
List<PackageDefinition> packages;
434+
435+
if (BuildSettings.Packages.Count == 0)
436+
throw new Exception("No packages exist!");
437+
else if (BuildSettings.Packages.Count == 1)
438+
{
439+
if (BuildSettings.Packages[0].PackageType != PackageType.NuGet)
440+
throw new Exception("The only package is not a NuGet package");
441+
442+
packages = BuildSettings.Packages;
443+
}
444+
else // count is > 1
445+
{
446+
if (!CommandLineOptions.PackageSelector.Exists)
447+
throw new Exception("Multiple packages exist. Specify a nuget package id using the '--where' option");
448+
449+
packages = new List<PackageDefinition>();
450+
451+
foreach (var package in BuildSettings.Packages)
452+
if (package.IsSelectedBy(CommandLineOptions.PackageSelector.Value))
453+
packages.Add(package);
454+
455+
if (packages.Count > 1)
456+
throw new Exception("The '--where' option selected multiple packages");
457+
458+
if (packages[0].PackageType != PackageType.NuGet)
459+
throw new Exception("The selected package is a {package.PackageType} package. It must be a package for nuget.org.");
460+
}
461+
462+
// At this point we have a single NuGet package in packages
463+
var packageName = $"{packages[0].PackageId}.{BuildSettings.PackageVersion}.snupkg";
464+
var packagePath = BuildSettings.PackageDirectory + packageName;
465+
NuGetPush(packagePath, new NuGetPushSettings() { ApiKey = BuildSettings.NuGetApiKey, Source = BuildSettings.NuGetPushUrl });
466+
}
467+
});
468+
410469
//////////////////////////////////////////////////////////////////////
411470
// EXECUTION
412471
//////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)