Skip to content

Commit ba3952d

Browse files
committed
Specify PackageContent in script
1 parent ac44b65 commit ba3952d

File tree

7 files changed

+386
-40
lines changed

7 files changed

+386
-40
lines changed

recipe/chocolatey-package.cake

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
public class ChocolateyPackage : PackageDefinition
22
{
33
public ChocolateyPackage(
4-
string id,
5-
string source,
4+
string id,
5+
string title = null,
6+
string summary = null,
7+
string description = null,
8+
string[] releaseNotes = null,
9+
string[] tags = null,
10+
string source = null,
611
string packageVersion = null,
712
IPackageTestRunner testRunner = null,
813
IPackageTestRunner[] testRunners = null,
914
PackageCheck[] checks = null,
10-
IEnumerable<PackageTest> tests = null)
15+
IEnumerable<PackageTest> tests = null,
16+
PackageContent packageContent = null )
1117
: base(
1218
PackageType.Chocolatey,
1319
id,
14-
source,
20+
title: title,
21+
summary: summary,
22+
description: description,
23+
releaseNotes: releaseNotes,
24+
tags: tags,
25+
source: source,
1526
packageVersion: packageVersion,
1627
testRunner: testRunner,
1728
testRunners: testRunners,
1829
checks: checks,
19-
tests: tests)
30+
tests: tests,
31+
packageContent: packageContent )
2032
{
21-
if (!source.EndsWith(".nuspec"))
22-
throw new ArgumentException("Source must be a nuspec file", nameof(source));
2333
}
2434

2535
// The file name of this package, including extension
@@ -33,15 +43,70 @@ public class ChocolateyPackage : PackageDefinition
3343
// The directory into which extensions to the test runner are installed
3444
public override string ExtensionInstallDirectory => BuildSettings.ChocolateyTestDirectory;
3545

36-
public override void BuildPackage()
46+
protected virtual ChocolateyPackSettings ChocolateyPackSettings
3747
{
38-
_context.ChocolateyPack(PackageSource,
39-
new ChocolateyPackSettings()
48+
get
49+
{
50+
var repositoryUrl = NUNIT_GITHUB_URL + BuildSettings.GitHubRepository + "/";
51+
var rawGitHubUserContent = "https://raw.githubusercontent.com/" + BuildSettings.GitHubRepository + "/main/";
52+
53+
// NOTE: Because of how Cake build works, these settings will
54+
// override any settings in a nuspec file. Therefore, no settings
55+
// should be initialized unless they either
56+
// 1) are taken from the PackageDefinition itself.
57+
// 2) are taken from the BuildSettings, which apply to all packages being built.
58+
// 3) are defined to be the same for all TestCentric packages.
59+
60+
var settings = new ChocolateyPackSettings
4061
{
62+
// From PackageDefinition
63+
Id = PackageId,
4164
Version = PackageVersion,
65+
Title = PackageTitle ?? PackageId,
66+
Summary = PackageSummary,
67+
Description = PackageDescription,
68+
ReleaseNotes = ReleaseNotes,
69+
Tags = Tags,
70+
// From BuildSettings
71+
LicenseUrl = new Uri($"{NUNIT_RAW_URL}{BuildSettings.GitHubRepository}/main/LICENSE.txt"),
72+
Verbose = BuildSettings.ChocolateyVerbosity,
4273
OutputDirectory = BuildSettings.PackageDirectory,
74+
ProjectSourceUrl = new Uri(repositoryUrl),
75+
PackageSourceUrl = new Uri(repositoryUrl),
76+
BugTrackerUrl = new Uri(repositoryUrl + "issues"),
77+
// Common to all packages
78+
Authors = NUNIT_PACKAGE_AUTHORS,
79+
Owners = NUNIT_PACKAGE_OWNERS,
80+
Copyright = NUNIT_COPYRIGHT,
81+
ProjectUrl = new Uri(NUNIT_PROJECT_URL),
82+
RequireLicenseAcceptance = false,
83+
DocsUrl = new Uri(NUNIT_PROJECT_URL),
84+
MailingListUrl = new Uri(NUNIT_MAILING_LIST_URL),
4385
ArgumentCustomization = args => args.Append($"BIN_DIR={BuildSettings.OutputDirectory}")
44-
});
86+
};
87+
88+
if (PackageContent != null)
89+
{
90+
foreach (var item in PackageContent.GetChocolateyNuSpecContent(BasePath))
91+
settings.Files.Add(item);
92+
93+
foreach (PackageReference dependency in PackageContent.Dependencies)
94+
settings.Dependencies.Add(new ChocolateyNuSpecDependency { Id = dependency.Id, Version = dependency.Version });
95+
}
96+
97+
return settings;
98+
}
99+
}
100+
101+
public override void BuildPackage()
102+
{
103+
if (string.IsNullOrEmpty(PackageSource))
104+
_context.ChocolateyPack(ChocolateyPackSettings);
105+
else if (PackageSource.EndsWith(".nuspec"))
106+
_context.ChocolateyPack(PackageSource, ChocolateyPackSettings);
107+
else
108+
throw new ArgumentException(
109+
$"Invalid package source specified: {PackageSource}", "source");
45110
}
46111

47112
protected override bool IsRemovableExtension(string id)

recipe/constants.cake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,16 @@ private static readonly string[] LABELS_WE_PUBLISH_ON_CHOCOLATEY = { "beta", "rc
5555
private static readonly string[] LABELS_WE_PUBLISH_ON_GITHUB = { "beta", "rc" };
5656
private static readonly string[] LABELS_USED_AS_TAGS = { "alpha", "beta", "rc" };
5757
private static readonly string[] LABELS_WE_ADD_TO_LOCAL_FEED = { "dev", "alpha", "beta", "rc" };
58+
59+
// Common values used in all NUnit packages
60+
static readonly string[] NUNIT_PACKAGE_AUTHORS = new[] { "Charlie Poole, Rob Prouse" };
61+
static readonly string[] NUNIT_PACKAGE_OWNERS = new[] { "Charlie Poole, Rob Prouse" };
62+
static readonly NuSpecLicense NUNIT_LICENSE = new NuSpecLicense() { Type = "expression", Value = "MIT" };
63+
64+
const string NUNIT_ICON = "nunit_256.png";
65+
// TODO: Automatic update of year
66+
const string NUNIT_COPYRIGHT = "Copyright (c) 2021-2025 Charlie Poole, Rob Prouse";
67+
const string NUNIT_PROJECT_URL = "https://nunit.org/";
68+
const string NUNIT_GITHUB_URL = "https://github.com/nunit/";
69+
const string NUNIT_RAW_URL = "https://raw.githubusercontent.com/nunit/";
70+
const string NUNIT_MAILING_LIST_URL = "https://groups.google.com/forum/#!forum/nunit-discuss";

recipe/dotnet-tool-package.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class DotNetToolPackage : NuGetPackage
1313
IEnumerable<PackageTest> tests = null)
1414
: base(
1515
id,
16-
source,
16+
source: source,
1717
packageVersion: packageVersion,
1818
basePath: basePath,
1919
testRunner: testRunner,

recipe/nuget-package.cake

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,36 @@ public class NuGetPackage : PackageDefinition
22
{
33
public NuGetPackage(
44
string id,
5-
string source,
5+
string title = null,
6+
string description = null,
7+
string summary = null,
8+
string[] releaseNotes = null,
9+
string[] tags = null,
10+
string source = null,
611
string packageVersion = null,
712
string basePath = null,
813
IPackageTestRunner testRunner = null,
914
IPackageTestRunner[] testRunners = null,
1015
PackageCheck[] checks = null,
1116
PackageCheck[] symbols = null,
12-
IEnumerable<PackageTest> tests = null)
17+
IEnumerable<PackageTest> tests = null,
18+
PackageContent packageContent = null)
1319
: base(
1420
PackageType.NuGet,
15-
id,
16-
source,
21+
id,
22+
title: title,
23+
description: description,
24+
summary: summary,
25+
releaseNotes: releaseNotes,
26+
source: source,
1727
packageVersion: packageVersion,
1828
basePath: basePath,
1929
testRunner: testRunner,
2030
testRunners: testRunners,
2131
checks: checks,
2232
symbols: symbols,
23-
tests: tests)
33+
tests: tests,
34+
packageContent: packageContent)
2435
{
2536
//if (!source.EndsWith(".nuspec"))
2637
// throw new ArgumentException("Source must be a nuspec file", nameof(source));
@@ -43,21 +54,57 @@ public class NuGetPackage : PackageDefinition
4354
// The directory into which extensions to the test runner are installed
4455
public override string ExtensionInstallDirectory => BuildSettings.NuGetTestDirectory;
4556

46-
public override void BuildPackage()
57+
protected virtual NuGetPackSettings NuGetPackSettings
4758
{
48-
var NuGetPackSettings = new NuGetPackSettings()
59+
get
4960
{
50-
Version = PackageVersion,
51-
BasePath = BasePath,
52-
OutputDirectory = BuildSettings.PackageDirectory,
53-
NoPackageAnalysis = true,
54-
Symbols = HasSymbols,
55-
Verbosity = BuildSettings.NuGetVerbosity
56-
};
61+
var repositoryUrl = NUNIT_GITHUB_URL + BuildSettings.GitHubRepository + "/";
62+
var rawGitHubUserContent = "https://raw.githubusercontent.com/" + BuildSettings.GitHubRepository + "/main/";
63+
64+
var settings = new NuGetPackSettings()
65+
{
66+
// From PackageDefinition
67+
Id = PackageId,
68+
Version = PackageVersion,
69+
Title = PackageTitle ?? PackageId,
70+
Description = PackageDescription,
71+
ReleaseNotes = ReleaseNotes,
72+
Tags = Tags,
73+
BasePath = BasePath,
74+
// From BuildSettings
75+
Verbosity = BuildSettings.NuGetVerbosity,
76+
OutputDirectory = BuildSettings.PackageDirectory,
77+
Repository = new NuGetRepository() { Type = "Git", Url = repositoryUrl },
78+
Symbols = HasSymbols,
79+
// Common to all packages
80+
Authors = NUNIT_PACKAGE_AUTHORS,
81+
Copyright = NUNIT_COPYRIGHT,
82+
ProjectUrl = new Uri(NUNIT_PROJECT_URL),
83+
License = NUNIT_LICENSE,
84+
RequireLicenseAcceptance = false,
85+
Icon = NUNIT_ICON,
86+
Language = "en-US",
87+
NoPackageAnalysis = true,
88+
};
89+
90+
if (HasSymbols)
91+
settings.SymbolPackageFormat = "snupkg";
5792

58-
if (HasSymbols)
59-
NuGetPackSettings.SymbolPackageFormat = "snupkg";
93+
if (PackageContent != null)
94+
{
95+
foreach (var item in PackageContent.GetNuSpecContent())
96+
settings.Files.Add(item);
6097

98+
foreach (PackageReference dependency in PackageContent.Dependencies)
99+
settings.Dependencies.Add(new NuSpecDependency { Id = dependency.Id, Version = dependency.Version });
100+
}
101+
102+
return settings;
103+
}
104+
}
105+
106+
public override void BuildPackage()
107+
{
61108
if (string.IsNullOrEmpty(PackageSource))
62109
_context.NuGetPack(NuGetPackSettings);
63110
else if (PackageSource.EndsWith(".nuspec"))

recipe/package-checks.cake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static DirectoryCheck HasDirectory(string dirPathOrPattern) => new Direct
99

1010
public static DependencyCheck HasDependency(string packageId, string packageVersion = null) => new DependencyCheck(packageId, packageVersion);
1111
public static DependencyCheck HasDependency(PackageReference packageReference) => new DependencyCheck(packageReference);
12+
public static MultipleDependencies HasDependencies(IEnumerable<PackageReference> packageReferences) => new MultipleDependencies(packageReferences);
1213

1314
//////////////////////////////////////////////////////////////////////
1415
// PACKAGECHECK CLASS
@@ -249,3 +250,26 @@ public class DependencyCheck : PackageCheck
249250
}
250251
}
251252
}
253+
254+
//////////////////////////////////////////////////////////////////////
255+
// MULTIPLEDEPENDENCIES CLASS
256+
//////////////////////////////////////////////////////////////////////
257+
258+
public class MultipleDependencies : PackageCheck
259+
{
260+
private List<DependencyCheck> _dependencies = new List<DependencyCheck>();
261+
262+
public MultipleDependencies(IEnumerable<PackageReference> packageReferences)
263+
{
264+
foreach(var packageReference in packageReferences)
265+
_dependencies.Add(new DependencyCheck(packageReference));
266+
}
267+
268+
public override bool ApplyTo(DirectoryPath testDirPath)
269+
{
270+
bool isOK = true;
271+
foreach (var dependency in _dependencies)
272+
isOK &= dependency.ApplyTo(testDirPath);
273+
return isOK;
274+
}
275+
}

0 commit comments

Comments
 (0)