feat: add Cake build to produce powershell module (#2)

- Add Cake build project
- Change to CPM
- Package bumps for security bumps
- Reorganise solution structure to group harness projects
This commit is contained in:
Scott 2026-07-31 02:15:16 +00:00
commit ecb0a20cbb
27 changed files with 267 additions and 58 deletions

36
build/Tasks/BuildTask.cs Normal file
View file

@ -0,0 +1,36 @@
using Cake.Common.Tools.DotNet;
using Cake.Common.Tools.DotNet.Build;
using Cake.Common.Tools.DotNet.MSBuild;
using Cake.Core.Diagnostics;
using Cake.Frosting;
namespace Build.Tasks;
[TaskName("Build")]
[IsDependentOn(typeof(CleanTask))]
[IsDependeeOf(typeof(CopyOutputTask))]
public class BuildTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.Log.Information($"Building: {context.PowershellModuleCsproj}");
var buildSettings = new DotNetBuildSettings()
{
MSBuildSettings = new DotNetMSBuildSettings()
{
VersionSuffix = "cake"
},
OutputDirectory = context.PowershellModuleOutputDir,
DiagnosticOutput = true
};
// /p:DebugSymbols=false
buildSettings.MSBuildSettings.Properties.Add("DebugSymbols", ["false"]);
// /p:DebugType=None
buildSettings.MSBuildSettings.Properties.Add("DebugType", ["None"]);
context.DotNetBuild(context.PowershellModuleCsproj, buildSettings);
base.Run(context);
}
}

23
build/Tasks/CleanTask.cs Normal file
View file

@ -0,0 +1,23 @@
using Cake.Common;
using Cake.Common.Tools.DotNet;
using Cake.Core.Diagnostics;
using Cake.Frosting;
namespace Build.Tasks;
[TaskName("Clean")]
public class CleanTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.DotNetClean(context.PowershellModuleProjectDirectory);
var outDir = context.FileSystem.GetDirectory(context.PowershellModuleOutputDir);
if (outDir.Exists)
{
outDir.Delete(true);
}
base.Run(context);
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Linq;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Frosting;
using Cake.Powershell;
namespace Build.Tasks;
[TaskName("CopyOutput")]
public class CopyOutputTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var powershellModuleName = "PowershellModule";
var scriptParams = new
{
Path = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psd1",
Guid = Guid.Parse("5cdf4635-edb0-428c-8d9b-92d0bcd47443"),
Author = "Me",
NestedModules = new[] { $"{powershellModuleName}.dll" },
RootModule = $"{powershellModuleName}.psm1",
CmdletsToExport = new[] { "Get-Calendar" },
ManifestFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psm1"
};
var psSettings = new PowershellSettings()
{
Arguments = new ProcessArgumentBuilder(),
};
// This feels a bit ugly/redundant seeing as I've defined the scriptParams above, but I'm leaving it as is
// until I want to come back and clean this up properly
psSettings.Arguments.Append("path", ToPowershellSafeString(scriptParams.Path));
psSettings.Arguments.Append("guid", ToPowershellSafeString(scriptParams.Guid.ToString()));
psSettings.Arguments.Append("author", ToPowershellSafeString(scriptParams.Author));
psSettings.Arguments.Append("nestedModules", $"@({string.Join(",", scriptParams.NestedModules.Select(ToPowershellSafeString))})");
psSettings.Arguments.Append("rootModule", ToPowershellSafeString(scriptParams.RootModule));
psSettings.Arguments.Append("cmdletsToExport", $"@({string.Join(",", scriptParams.CmdletsToExport.Select(ToPowershellSafeString))})");
psSettings.Arguments.Append("manifestFileLocation", ToPowershellSafeString(scriptParams.ManifestFileLocation));
context.StartPowershellFile(context.CreateModuleManifestScript, psSettings);
context.Log.Information($"Module output to: {context.PowershellModuleOutputDir.Path.MakeAbsolute(context.Environment)}");
base.Run(context);
}
private static string ToPowershellSafeString(string unescapedString) => $"'{unescapedString}'";
}

View file

@ -0,0 +1,16 @@
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Frosting;
namespace Build.Tasks;
// Consider this the "entry" point for builds, task order is defined by a chain of IsDependentOn
[TaskName("Default")]
[IsDependentOn(typeof(CopyOutputTask))]
public class DefaultTask : FrostingTask
{
public override void Run(ICakeContext context)
{
base.Run(context);
}
}