Skip to content

Commit

Permalink
Refactor cake scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
CharliePoole committed Oct 12, 2022
1 parent 121e363 commit 75ab3be
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 42 deletions.
39 changes: 15 additions & 24 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,7 @@ Task("BuildPackages")
EnsureDirectoryExists(PACKAGE_DIR);
foreach (var package in AllPackages)
{
DisplayBanner($"Building package {package.PackageName}");
package.BuildPackage();
}
});

//////////////////////////////////////////////////////////////////////
Expand All @@ -406,20 +402,27 @@ Task("VerifyPackages")
int failures = 0;
foreach (var package in AllPackages)
{
if (!CheckPackage($"{PACKAGE_DIR}{package.PackageName}", package.PackageChecks))
++failures;
if (package.HasSymbols && !CheckPackage($"{PACKAGE_DIR}{package.SymbolPackageName}", package.SymbolChecks))
++failures;
}
failures += VerifyPackage(package);
if (failures == 0)
Information("\nAll packages passed verification.");
else
throw new System.Exception($"{failures} packages failed verification.");
});

public int VerifyPackage(PackageDefinition package)
{
int failures = 0;

if (!CheckPackage($"{PACKAGE_DIR}{package.PackageName}", package.PackageChecks))
++failures;

if (package.HasSymbols && !CheckPackage($"{PACKAGE_DIR}{package.SymbolPackageName}", package.SymbolChecks))
++failures;

return failures;
}

//////////////////////////////////////////////////////////////////////
// TEST PACKAGES
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -449,25 +452,13 @@ Task("PackageMsi")
{
EnsureDirectoryExists(PACKAGE_DIR);
DisplayBanner($"Building MSI package {package.PackageId}");
package.BuildPackage();
DisplayBanner("Checking package content");
if (!CheckPackage($"{PACKAGE_DIR}{package.PackageName}", package.PackageChecks))
throw new System.Exception($"Package failed verification.");
if (package.HasSymbols)
{
DisplayBanner("Checking symbol package content");
if (!CheckPackage($"{PACKAGE_DIR}{package.SymbolPackageName}", package.SymbolChecks))
throw new System.Exception($"Symbol package failed verification.");
}
VerifyPackage(package);
if (package.PackageTests != null)
{
DisplayBanner("Testing package");
new PackageTester(Context, package).RunTests();
}
}
}
});
Expand Down
17 changes: 0 additions & 17 deletions cake/constants.cake
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,6 @@ static string MOCK_ASSEMBLY_PROJECT_BIN_DIR; MOCK_ASSEMBLY_PROJECT_BIN_DIR = SOU
static string MOCK_ASSEMBLY_X86_PROJECT_BIN_DIR; MOCK_ASSEMBLY_X86_PROJECT_BIN_DIR = SOURCE_DIR + $"NUnitConsole/mock-assembly-x86/bin/{Configuration}/";
static string NOTEST_ASSEMBLY_PROJECT_BIN_DIR; NOTEST_ASSEMBLY_PROJECT_BIN_DIR = SOURCE_DIR + $"NUnitConsole/notest-assembly/bin/{Configuration}/";

static string[] ALL_BIN_DIRS; ALL_BIN_DIRS = new string[]
{
NETFX_CONSOLE_PROJECT_BIN_DIR,
NETCORE_CONSOLE_PROJECT_BIN_DIR,
ENGINE_PROJECT_BIN_DIR,
ENGINE_CORE_PROJECT_BIN_DIR,
ENGINE_API_PROJECT_BIN_DIR,
AGENT_PROJECT_BIN_DIR,
AGENT_X86_PROJECT_BIN_DIR,
CONSOLE_TESTS_PROJECT_BIN_DIR,
ENGINE_TESTS_PROJECT_BIN_DIR,
ENGINE_CORE_TESTS_PROJECT_BIN_DIR,
MOCK_ASSEMBLY_PROJECT_BIN_DIR,
MOCK_ASSEMBLY_X86_PROJECT_BIN_DIR,
NOTEST_ASSEMBLY_PROJECT_BIN_DIR
};

// Project Targets
// We build two console runners. If version of either is upgraded, change it here
const string NETFX_CONSOLE_TARGET = "net462";
Expand Down
13 changes: 13 additions & 0 deletions cake/package-definitions.cake
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ public abstract class PackageDefinition
public abstract string PackageName { get; }
public abstract void BuildPackage();

public void DisplayAction(string action)
{
DisplayBanner($"{action} package {PackageName}");
}

public bool HasSymbols { get; protected set; } = false;
public virtual string SymbolPackageName => throw new System.NotImplementedException($"Symbols are not available for {PackageType} packages.");
}
Expand All @@ -308,6 +313,8 @@ public class NuGetPackage : PackageDefinition

public override void BuildPackage()
{
DisplayAction("Building");

var nugetPackSettings = new NuGetPackSettings()
{
Version = PackageVersion,
Expand All @@ -334,6 +341,8 @@ public class ChocolateyPackage : PackageDefinition

public override void BuildPackage()
{
DisplayAction("Building");

_context.ChocolateyPack(PackageSource,
new ChocolateyPackSettings()
{
Expand All @@ -354,6 +363,8 @@ public class MsiPackage : PackageDefinition

public override void BuildPackage()
{
DisplayAction("Building");

_context.MSBuild(PackageSource, new MSBuildSettings()
.WithTarget("Rebuild")
.SetConfiguration(Configuration)
Expand All @@ -376,6 +387,8 @@ public class ZipPackage : PackageDefinition

public override void BuildPackage()
{
DisplayAction("Building");

_context.Zip(ZIP_IMG_DIR, $"{PACKAGE_DIR}{PackageName}");
}
}
4 changes: 3 additions & 1 deletion cake/package-tester.cake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
public class PackageTester
{
private ICakeContext _context;
private PackageDefinition _package;

private PackageType _packageType;
private string _packageName;
Expand All @@ -16,6 +17,7 @@ public class PackageTester
public PackageTester(ICakeContext context, PackageDefinition package)
{
_context = context;
_package = package;

_packageType = package.PackageType;
_packageName = package.PackageName;
Expand All @@ -29,7 +31,7 @@ public class PackageTester

public void RunTests()
{
DisplayBanner("Testing package " + _packageName);
_package.DisplayAction("Testing");

Console.WriteLine("Creating Test Directory...");
CreatePackageInstallDirectory();
Expand Down

0 comments on commit 75ab3be

Please sign in to comment.