build(git-provider): Add GitRepoRegistration commands to build

This commit is contained in:
Scott 2026-09-03 20:42:20 +10:00
commit 270d545e56
2 changed files with 31 additions and 8 deletions

View file

@ -1,15 +1,18 @@
param ( param (
[string]$path, [string]$powershellModuleFileLocation,
[string]$guid, [string]$guid,
[string]$author, [string]$author,
[string[]]$nestedModules, [string[]]$nestedModules,
[string]$rootModule, [string]$rootModule,
[string[]]$cmdletsToExport, [string[]]$cmdletsToExport,
[string]$manifestFileLocation [string]$manifestFileLocation,
# not used for anything yet, but I should probably simplify the module locations as they get the output dir
# created in CopyOutputTask.cs
[string]$outputDir
) )
$manifestSplat = @{ $manifestSplat = @{
Path = "$path" Path = "$powershellModuleFileLocation"
GUID = "$guid" GUID = "$guid"
Author = "$author" Author = "$author"
NestedModules = @($nestedModules) NestedModules = @($nestedModules)

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Cake.Core.Diagnostics; using Cake.Core.Diagnostics;
using Cake.Core.IO; using Cake.Core.IO;
@ -13,17 +14,20 @@ public class CopyOutputTask : FrostingTask<BuildContext>
public override void Run(BuildContext context) public override void Run(BuildContext context)
{ {
var powershellModuleName = "PowershellModule"; var powershellModuleName = "PowershellModule";
// TODO: probably don't create full file locations when I can pass the output dir in and have the script
// make the path
var scriptParams = new var scriptParams = new
{ {
Path = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psd1", PowershellModuleFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psd1",
Guid = Guid.Parse("5cdf4635-edb0-428c-8d9b-92d0bcd47443"), Guid = Guid.Parse("5cdf4635-edb0-428c-8d9b-92d0bcd47443"),
Author = "Me", Author = "Me",
NestedModules = new[] { $"{powershellModuleName}.dll" }, NestedModules = new[] { $"{powershellModuleName}.dll" },
RootModule = $"{powershellModuleName}.psm1", RootModule = $"{powershellModuleName}.psm1",
CmdletsToExport = new[] { "Get-Calendar" }, CmdletsToExport = GetExportedCmdlets(),
ManifestFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psm1" ManifestFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psm1",
OutputLocation = context.PowershellModuleOutputDir,
}; };
var psSettings = new PowershellSettings() var psSettings = new PowershellSettings()
{ {
Arguments = new ProcessArgumentBuilder(), Arguments = new ProcessArgumentBuilder(),
@ -31,13 +35,14 @@ public class CopyOutputTask : FrostingTask<BuildContext>
// This feels a bit ugly/redundant seeing as I've defined the scriptParams above, but I'm leaving it as is // 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 // until I want to come back and clean this up properly
psSettings.Arguments.Append("path", ToPowershellSafeString(scriptParams.Path)); psSettings.Arguments.Append("powershellModuleFileLocation", ToPowershellSafeString(scriptParams.PowershellModuleFileLocation));
psSettings.Arguments.Append("guid", ToPowershellSafeString(scriptParams.Guid.ToString())); psSettings.Arguments.Append("guid", ToPowershellSafeString(scriptParams.Guid.ToString()));
psSettings.Arguments.Append("author", ToPowershellSafeString(scriptParams.Author)); psSettings.Arguments.Append("author", ToPowershellSafeString(scriptParams.Author));
psSettings.Arguments.Append("nestedModules", $"@({string.Join(",", scriptParams.NestedModules.Select(ToPowershellSafeString))})"); psSettings.Arguments.Append("nestedModules", $"@({string.Join(",", scriptParams.NestedModules.Select(ToPowershellSafeString))})");
psSettings.Arguments.Append("rootModule", ToPowershellSafeString(scriptParams.RootModule)); psSettings.Arguments.Append("rootModule", ToPowershellSafeString(scriptParams.RootModule));
psSettings.Arguments.Append("cmdletsToExport", $"@({string.Join(",", scriptParams.CmdletsToExport.Select(ToPowershellSafeString))})"); psSettings.Arguments.Append("cmdletsToExport", $"@({string.Join(",", scriptParams.CmdletsToExport.Select(ToPowershellSafeString))})");
psSettings.Arguments.Append("manifestFileLocation", ToPowershellSafeString(scriptParams.ManifestFileLocation)); psSettings.Arguments.Append("manifestFileLocation", ToPowershellSafeString(scriptParams.ManifestFileLocation));
psSettings.Arguments.Append("outputDir", ToPowershellSafeString(scriptParams.OutputLocation));
context.StartPowershellFile(context.CreateModuleManifestScript, psSettings); context.StartPowershellFile(context.CreateModuleManifestScript, psSettings);
context.Log.Information($"Module output to: {context.PowershellModuleOutputDir.Path.MakeAbsolute(context.Environment)}"); context.Log.Information($"Module output to: {context.PowershellModuleOutputDir.Path.MakeAbsolute(context.Environment)}");
@ -46,4 +51,19 @@ public class CopyOutputTask : FrostingTask<BuildContext>
} }
private static string ToPowershellSafeString(string unescapedString) => $"'{unescapedString}'"; private static string ToPowershellSafeString(string unescapedString) => $"'{unescapedString}'";
private static List<string> GetExportedCmdlets()
{
return ["Get-Calendar", .. GetGitRepoRegistrationVerbs()];
}
private static List<string> GetGitRepoRegistrationVerbs()
{
// TODO: I should make some reference file for these verbs and name but that'd pull in powershell dependencies
// to the build and I'd like to avoid that.
// This isn't great but commands are unlikely to change that frequently
string[] verbs = ["Get", "New", "Remove", "Show"];
var commandName = "GitRepoRegistration";
return [.. verbs.Select(x => $"{x}-{commandName}")];
}
} }