feat: Adds Build Tool for Publishing/Setup (#2392)
## Summary Replaces the basic `publish.cmd`/`publish.sh` scripts with an interactive **BuildTool** — a C# console app using [Spectre.Console](https://spectreconsole.net/) that guides users through publishing, prerequisite checking, and cross-compilation. ### Why The community found the existing publish scripts unhelpful for newcomers. They worked but didn't walk users through the process, didn't check prerequisites, and provided no feedback when things went wrong. ### What's New **Interactive BuildTool** (`Projects/BuildTool/`) - NativeAOT-compiled C# console app with true-color ASCII logo and ModernUO brand gold/silver palette - Guided publish wizard with step-by-step back navigation (Ctrl+C or menu "Back" to go to previous step) - Prerequisite checking: .NET SDK version, VC++ Redistributable (Windows), native libraries (Linux/macOS) - .NET SDK auto-install offer via Microsoft's official install scripts - Platform detection: Windows 10 vs 11 (build number), macOS codenames, Linux distro + kernel version - Cross-compilation support: skips native library checks, shows target prerequisites after build - Non-interactive mode for CI: `--config Release --skip-prereqs` - Backward-compatible positional args: `publish.cmd release win x64` still works **Shell Wrappers** (`publish.cmd`, `publish.ps1`, `publish.sh`) - Try native BuildTool binary first (downloaded from GitHub Releases) - Fall back to `dotnet run --project Projects/BuildTool` if unavailable - SDK bootstrapping: offer to install .NET if not found **CI/CD Updates** - Build/test workflows target `Projects/Application/Application.csproj` instead of the solution (excludes BuildTool and test projects from publish) - New `build-tool-release.yml` workflow builds NativeAOT binaries for win-x64, win-arm64, osx-arm64, linux-x64, linux-arm64 - Minimum SDK bumped to 10.0.201 (required for Serialization Generator 2.14.3 / Roslyn 5.3.0) **Other Changes** - Solution converted from `.sln` to `.slnx` - Updated README with interactive mode instructions and deployment guidance ## Screenshots <img width="320" height="378" alt="image" src="https://github.com/user-attachments/assets/83c057c5-3992-4dbd-99fa-0e3c24ef6428" /> <img width="749" height="554" alt="image" src="https://github.com/user-attachments/assets/e4ee4d6f-71d4-47f9-86b6-8fd1ca3c3e7a" />
This commit is contained in:
parent
3b4e1137f6
commit
ec4d6a7a85
32 changed files with 2372 additions and 165 deletions
182
Projects/BuildTool/Publishing/PublishOrchestrator.cs
Normal file
182
Projects/BuildTool/Publishing/PublishOrchestrator.cs
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
using BuildTool.Platform;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace BuildTool.Publishing;
|
||||
|
||||
public static class PublishOrchestrator
|
||||
{
|
||||
// Target the Application project (not the solution) to avoid building BuildTool and test projects
|
||||
private const string AppProject = "Projects/Application/Application.csproj";
|
||||
|
||||
private static readonly (string Description, string Command, string Arguments)[] BuildSteps =
|
||||
[
|
||||
("Restoring tools", "dotnet", "tool restore"),
|
||||
("Cleaning project", "dotnet", $"clean {AppProject} --verbosity quiet"),
|
||||
("Restoring packages", "dotnet", $"restore {AppProject} --force-evaluate --source https://api.nuget.org/v3/index.json"),
|
||||
];
|
||||
|
||||
public static int Run(string config, PlatformInfo platform, bool interactive)
|
||||
{
|
||||
return Run(config, platform.Rid, interactive);
|
||||
}
|
||||
|
||||
public static int Run(string config, string rid, bool interactive, bool isCrossCompile = false)
|
||||
{
|
||||
if (interactive)
|
||||
{
|
||||
return RunInteractive(config, rid, isCrossCompile);
|
||||
}
|
||||
|
||||
return RunNonInteractive(config, rid);
|
||||
}
|
||||
|
||||
private static int RunInteractive(string config, string rid, bool isCrossCompile)
|
||||
{
|
||||
var panel = new Panel($"[bold]Publishing[/] [rgb(223,198,136)]{config}[/] for [rgb(223,198,136)]{rid}[/]")
|
||||
.Border(BoxBorder.Rounded)
|
||||
.BorderColor(Branding.Gold)
|
||||
.Padding(1, 0);
|
||||
AnsiConsole.Write(panel);
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
var allSteps = new List<(string Description, string Command, string Arguments)>(BuildSteps)
|
||||
{
|
||||
($"Publishing ({config}, {rid})", "dotnet", $"publish {AppProject} -c {config} -r {rid} --no-restore --self-contained=false"),
|
||||
("Generating serialization schema", "dotnet", "tool run ModernUOSchemaGenerator -- ModernUO.slnx")
|
||||
};
|
||||
|
||||
var completed = 0;
|
||||
var total = allSteps.Count;
|
||||
|
||||
foreach (var (description, command, arguments) in allSteps)
|
||||
{
|
||||
completed++;
|
||||
var exitCode = RunStepInteractive(description, command, arguments, completed, total);
|
||||
if (exitCode != 0)
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Write(new Panel("[red bold]Build failed.[/] See error output above for details.")
|
||||
.Border(BoxBorder.Rounded)
|
||||
.BorderColor(Color.Red)
|
||||
.Padding(1, 0));
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
AnsiConsole.WriteLine();
|
||||
DisplaySuccess(rid, isCrossCompile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int RunStepInteractive(string description, string command, string arguments, int step, int total)
|
||||
{
|
||||
var exitCode = 0;
|
||||
string errorOutput = "";
|
||||
|
||||
AnsiConsole.Status()
|
||||
.Spinner(Spinner.Known.Dots)
|
||||
.SpinnerStyle(Branding.GoldStyle)
|
||||
.Start($"[grey]({step}/{total})[/] {description}...", _ =>
|
||||
{
|
||||
var result = ProcessRunner.RunCaptured(command, arguments);
|
||||
exitCode = result.ExitCode;
|
||||
errorOutput = result.StandardError;
|
||||
});
|
||||
|
||||
if (exitCode == 0)
|
||||
{
|
||||
AnsiConsole.MarkupLine($" [green]:check_mark:[/] [grey]({step}/{total})[/] {description}");
|
||||
}
|
||||
else
|
||||
{
|
||||
AnsiConsole.MarkupLine($" [red]:cross_mark:[/] [grey]({step}/{total})[/] {description} [red](failed)[/]");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(errorOutput))
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Write(new Panel(Markup.Escape(errorOutput.Trim()))
|
||||
.Header("[red]Error Output[/]")
|
||||
.Border(BoxBorder.Rounded)
|
||||
.BorderColor(Color.Red)
|
||||
.Expand());
|
||||
}
|
||||
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine($" [grey]Command: {command} {arguments}[/]");
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
private static int RunNonInteractive(string config, string rid)
|
||||
{
|
||||
// Run common build steps
|
||||
foreach (var (description, command, arguments) in BuildSteps)
|
||||
{
|
||||
Console.WriteLine($"{command} {arguments}");
|
||||
var exitCode = ProcessRunner.RunPassthrough(command, arguments);
|
||||
if (exitCode != 0)
|
||||
{
|
||||
Console.Error.WriteLine($"Error: '{description}' failed with exit code {exitCode}");
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Publish step
|
||||
{
|
||||
var publishArgs = $"publish {AppProject} -c {config} -r {rid} --no-restore --self-contained=false";
|
||||
Console.WriteLine($"dotnet {publishArgs}");
|
||||
var exitCode = ProcessRunner.RunPassthrough("dotnet", publishArgs);
|
||||
if (exitCode != 0)
|
||||
{
|
||||
Console.Error.WriteLine($"Error: 'publish' failed with exit code {exitCode}");
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Schema generation
|
||||
{
|
||||
Console.WriteLine("Generating serialization migration schema...");
|
||||
const string schemaArgs = "tool run ModernUOSchemaGenerator -- ModernUO.slnx";
|
||||
var exitCode = ProcessRunner.RunPassthrough("dotnet", schemaArgs);
|
||||
if (exitCode != 0)
|
||||
{
|
||||
Console.Error.WriteLine($"Error: schema generation failed with exit code {exitCode}");
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
internal static void DisplaySuccess(string rid, bool isCrossCompile = false)
|
||||
{
|
||||
var isWindows = rid.StartsWith("win", StringComparison.OrdinalIgnoreCase);
|
||||
var runCommand = isWindows ? "ModernUO.exe" : "dotnet ModernUO.dll";
|
||||
|
||||
var rows = new List<Spectre.Console.Rendering.IRenderable>
|
||||
{
|
||||
new Markup("[green bold]:check_mark_button: Build complete![/]"),
|
||||
new Markup("")
|
||||
};
|
||||
|
||||
if (isCrossCompile)
|
||||
{
|
||||
rows.Add(new Markup($"Copy the [rgb(213,191,116)]Distribution[/] folder to your [rgb(213,191,116)]{rid}[/] server, then run:"));
|
||||
}
|
||||
else
|
||||
{
|
||||
rows.Add(new Markup("Run the server from the [rgb(213,191,116)]Distribution[/] directory:"));
|
||||
}
|
||||
|
||||
rows.Add(new Markup(""));
|
||||
rows.Add(new Markup(" [white on grey23] cd Distribution [/]"));
|
||||
rows.Add(new Markup($" [white on grey23] {runCommand} [/]"));
|
||||
|
||||
AnsiConsole.Write(new Panel(new Rows(rows))
|
||||
.Border(BoxBorder.Rounded)
|
||||
.BorderColor(Color.Green)
|
||||
.Padding(1, 0));
|
||||
AnsiConsole.WriteLine();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue