Skip to content

Commit 3f6f6d0

Browse files
committed
Add local feed for sharing code between NUnit and TestCentric
1 parent 98c4dc7 commit 3f6f6d0

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

recipe/build-settings.cake

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public static class BuildSettings
8585
Context.Warning($" SolutionFile: '{SolutionFile}'");
8686
Context.Information($" PackageTestLevel: {PackageTestLevel}");
8787

88+
LocalPackagesDirectory = FindLocalPackagesDirectory() ?? ProjectDirectory + "LOCAL_PACKAGES_DIR";
89+
8890
// Keep this last
8991
if (IsRunningOnAppVeyor)
9092
{
@@ -107,7 +109,19 @@ public static class BuildSettings
107109
return null;
108110
}
109111

110-
private static int CalcPackageTestLevel()
112+
private static string FindLocalPackagesDirectory()
113+
{
114+
for (var dir = new DirectoryInfo(ProjectDirectory); dir != null; dir = dir.Parent)
115+
{
116+
string candidate = SIO.Path.Combine(dir.FullName, "LocalPackages");
117+
if (SIO.Directory.Exists(candidate))
118+
return candidate;
119+
}
120+
121+
return null;
122+
}
123+
124+
private static int CalcPackageTestLevel()
111125
{
112126
if (!BuildVersion.IsPreRelease)
113127
return 3;
@@ -238,9 +252,10 @@ public static class BuildSettings
238252
public static string ZipImageDirectory => ProjectDirectory + ZIP_IMG_DIR;
239253
public static string ExtensionsDirectory => ProjectDirectory + "bundled-extensions/";
240254
public static string ToolsDirectory => ProjectDirectory + TOOLS_DIR;
255+
public static string LocalPackagesDirectory { get; private set; }
241256

242-
// Files
243-
public static string SolutionFile { get; set; }
257+
// Files
258+
public static string SolutionFile { get; set; }
244259

245260
// Building
246261
public static string[] ValidConfigurations { get; set; }
@@ -325,7 +340,10 @@ public static class BuildSettings
325340
!IsPreRelease || LABELS_WE_PUBLISH_ON_CHOCOLATEY.Contains(BuildVersion.PreReleaseLabel) && !IsFractionalPreRelease;
326341
public static bool ShouldPublishToGitHub =>
327342
!IsPreRelease || LABELS_WE_PUBLISH_ON_GITHUB.Contains(BuildVersion.PreReleaseLabel) && !IsFractionalPreRelease;
328-
public static bool IsFractionalPreRelease
343+
public static bool ShouldPublishToLocalFeed =>
344+
!IsPreRelease || LABELS_WE_ADD_TO_LOCAL_FEED.Contains(BuildVersion.PreReleaseLabel);
345+
346+
public static bool IsFractionalPreRelease
329347
{
330348
get
331349
{
@@ -395,6 +413,7 @@ public static class BuildSettings
395413
Console.WriteLine("ZipResult: " + ZipResultDirectory);
396414
Console.WriteLine("Image: " + ImageDirectory);
397415
Console.WriteLine("ZipImage: " + ZipImageDirectory);
416+
Console.WriteLine("LocalPackages: " + LocalPackagesDirectory);
398417

399418
Console.WriteLine("\nBUILD");
400419
Console.WriteLine("Configuration: " + Configuration);
@@ -430,6 +449,7 @@ public static class BuildSettings
430449
Console.WriteLine("ShouldPublishToMyGet: " + ShouldPublishToMyGet);
431450
Console.WriteLine("ShouldPublishToNuGet: " + ShouldPublishToNuGet);
432451
Console.WriteLine("ShouldPublishToChocolatey: " + ShouldPublishToChocolatey);
452+
Console.WriteLine("ShouldPublishToLocalFeed: " + ShouldPublishToLocalFeed);
433453

434454
Console.WriteLine("\nRELEASING");
435455
Console.WriteLine("BranchName: " + BranchName);

recipe/constants.cake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const string ZIP_RSLT_DIR = "package/results/zip/";
3434
const string IMAGE_DIR = "package/images";
3535
const string ZIP_IMG_DIR = "package/images/zip/";
3636
const string TOOLS_DIR = "tools/";
37+
const string LOCAL_PACKAGES_DIR = "../LocalPackages";
3738

3839
// URLs for uploading packages
3940
private const string MYGET_PUSH_URL = "https://www.myget.org/F/nunit/api/v2";
@@ -53,3 +54,4 @@ private static readonly string[] LABELS_WE_PUBLISH_ON_NUGET = { "beta", "rc" };
5354
private static readonly string[] LABELS_WE_PUBLISH_ON_CHOCOLATEY = { "beta", "rc" };
5455
private static readonly string[] LABELS_WE_PUBLISH_ON_GITHUB = { "beta", "rc" };
5556
private static readonly string[] LABELS_USED_AS_TAGS = { "alpha", "beta", "rc" };
57+
private static readonly string[] LABELS_WE_ADD_TO_LOCAL_FEED = { "dev", "alpha", "beta", "rc" };

recipe/package-definition.cake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ public abstract class PackageDefinition
163163

164164
public abstract void BuildPackage();
165165

166+
// This may be called by NuGet or Chocolatey packages
167+
public void AddPackageToLocalFeed()
168+
{
169+
try
170+
{
171+
_context.NuGetAdd(PackageFilePath, BuildSettings.LocalPackagesDirectory);
172+
}
173+
catch (Exception ex)
174+
{
175+
_context.Error(ex.Message);
176+
}
177+
}
178+
166179
// Base implementation is used for installing both NuGet and
167180
// Chocolatey packages. Other package types should override.
168181
public virtual void InstallPackage()

recipe/task-builders.cake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static class BuildTasks
3535
public static CakeTaskBuilder PublishToMyGetTask { get; set; }
3636
public static CakeTaskBuilder PublishToNuGetTask { get; set; }
3737
public static CakeTaskBuilder PublishToChocolateyTask { get; set; }
38+
public static CakeTaskBuilder PublishToLocalFeedTask { get; set; }
3839
public static CakeTaskBuilder PublishSymbolsPackageTask { get; set; }
3940

4041
// Releasing

recipe/task-definitions.cake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ BuildTasks.PublishTask = Task("Publish")
107107
Information("Nothing to publish from this run.");
108108
});
109109

110+
BuildTasks.PublishToLocalFeedTask = Task("PublishToLocalFeed")
111+
.Description("""
112+
Publishes packages to the local feed for a dev, alpha, beta, or rc build
113+
or for a final release. If not, or if the --nopush option was used,
114+
a message is displayed.
115+
""")
116+
.WithCriteria(() => BuildSettings.IsLocalBuild)
117+
.Does(() => {
118+
if (!BuildSettings.ShouldPublishToLocalFeed)
119+
Information("Nothing to add to local feed from this run.");
120+
else if (CommandLineOptions.NoPush)
121+
Information("NoPush option suppressing publication to local feed");
122+
else if (!SIO.Directory.Exists(BuildSettings.LocalPackagesDirectory))
123+
throw new Exception("Local packages directory not found");
124+
else
125+
foreach (var package in BuildSettings.Packages)
126+
if (package.PackageType == PackageType.NuGet || package.PackageType == PackageType.Chocolatey)
127+
package.AddPackageToLocalFeed();
128+
});
129+
110130
BuildTasks.PublishSymbolsPackageTask = Task("PublishSymbolsPackage")
111131
.Description("\"Re-publish a specific symbols package to NuGet after a failure\"")
112132
.Does(() => PackageReleaseManager.PublishSymbolsPackage());

0 commit comments

Comments
 (0)