From 6f3be1f6bf05db1b5e31212629b77b332c5aebd9 Mon Sep 17 00:00:00 2001 From: MarcT1me Date: Sat, 28 Nov 2026 20:57:45 +0200 Subject: [PATCH 1/3] [SCRIPTS] [SDK] build and pack the modules with the core, keep one registration per root --- .github/workflows/tests.yml | 2 +- .../Stellar.Cli/Commands/InstallCommand.cs | 54 +++++++------ .../Environment/InstallationRegistry.cs | 37 +++++---- .../Installation/EngineInstaller.cs | 3 +- .../Modules/ModuleSynchronizer.cs | 20 ++--- .../Stellar.Tools.Tests/InstallationTests.cs | 80 +++++++++++++------ scripts/build.ps1 | 41 ++++++++-- 7 files changed, 152 insertions(+), 85 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6be51fd..c3f2d00 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -68,7 +68,7 @@ jobs: shell: pwsh run: | New-Item -ItemType Directory -Force packages | Out-Null - ./scripts/build.ps1 -Configuration Debug -SkipTests -Install -NoUserRegistration + ./scripts/build.ps1 -Configuration Debug -SkipTests -Install -NoUserRegistration -SkipModules - name: Build and test the module if: env.IS_CORE != 'true' diff --git a/SDK/src/Stellar.Cli/Commands/InstallCommand.cs b/SDK/src/Stellar.Cli/Commands/InstallCommand.cs index 4081785..9fd417d 100644 --- a/SDK/src/Stellar.Cli/Commands/InstallCommand.cs +++ b/SDK/src/Stellar.Cli/Commands/InstallCommand.cs @@ -1,16 +1,42 @@ using System.ComponentModel; + using Spectre.Console.Cli; + using Stellar.Tools.Environment; using Stellar.Tools.Installation; namespace Stellar.Cli.Commands; +/// +/// What install and uninstall take from the machine. +/// +internal static class InstallationPaths +{ + /// + /// The root a command acts on: the argument, $STELLAR_ROOT or the current directory. + /// + public static string Root(string? path) + { + return path + ?? Environment.GetEnvironmentVariable(StellarInstallation.EnvironmentVariable) + ?? Environment.CurrentDirectory; + } + + /// + /// The NuGet package cache of the user: $NUGET_PACKAGES, or ~/.nuget/packages. + /// + public static string PackageCache() + { + return Tools.Installation.PackageCache.Location(); + } +} + public sealed class InstallSettings : CommandSettings { [CommandArgument(0, "[PATH]")] - [Description( - "The checkout of StellarEngine-Core to turn into an installation. $STELLAR_ROOT or the current directory when omitted")] + [Description("The checkout of StellarEngine-Core to turn into an installation. " + + "$STELLAR_ROOT or the current directory when omitted")] public string? Path { get; set; } [CommandOption("--no-user-registration")] @@ -32,27 +58,3 @@ public override int Execute(CommandContext context, InstallSettings settings) return 0; } } - -/// -/// What install and uninstall take from the machine. -/// -internal static class InstallationPaths -{ - /// - /// The root a command acts on: the argument, $STELLAR_ROOT or the current directory. - /// - public static string Root(string? path) - { - return path - ?? Environment.GetEnvironmentVariable(StellarInstallation.EnvironmentVariable) - ?? Environment.CurrentDirectory; - } - - /// - /// The NuGet package cache of the user: $NUGET_PACKAGES, or ~/.nuget/packages. - /// - public static string PackageCache() - { - return Stellar.Tools.Installation.PackageCache.Location(); - } -} diff --git a/SDK/src/Stellar.Tools/Environment/InstallationRegistry.cs b/SDK/src/Stellar.Tools/Environment/InstallationRegistry.cs index f20fcbe..335f175 100644 --- a/SDK/src/Stellar.Tools/Environment/InstallationRegistry.cs +++ b/SDK/src/Stellar.Tools/Environment/InstallationRegistry.cs @@ -1,3 +1,5 @@ +// ReSharper disable PropertyCanBeMadeInitOnly.Global + using System; using System.Collections.Generic; using System.IO; @@ -45,8 +47,9 @@ public sealed class InstallationRegistryFile /// while it evaluates a project. Tools change the JSON through this class only, so both stay in step. /// /// -/// One installation per orchestra version: registering a version again moves it to the new root. What an orchestra -/// holds (modules, versions) is not here: it is in the manifests of the installation itself. +/// One installation per orchestra version, and one version per root: registering a version again moves it to the +/// new root, and a root installed again with a newer orchestra keeps only that one. What an orchestra holds (modules, +/// versions) is not here: it is in the manifests of the installation itself. /// /// /// An instance is a folder, not a global: tests and sandboxes create their own. @@ -94,9 +97,9 @@ public static string UserDirectory { get { - var fromVariable = System.Environment.GetEnvironmentVariable(EnvironmentVariable); + string? fromVariable = System.Environment.GetEnvironmentVariable(EnvironmentVariable); return !string.IsNullOrWhiteSpace(fromVariable) - ? Path.GetFullPath(fromVariable!) + ? Path.GetFullPath(fromVariable) : Path.Combine( System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile), ".stellar"); } @@ -124,22 +127,24 @@ public IReadOnlyList List() /// The installation, or null if the version is not registered. public StellarInstallation? Find(string orchesterVersion) { - var entry = Read().Installations.FirstOrDefault(installation => + RegisteredInstallation? entry = Read().Installations.FirstOrDefault(installation => string.Equals(installation.OrchesterVersion, orchesterVersion, StringComparison.Ordinal)); return entry is null ? null : new StellarInstallation(entry.Root); } /// - /// Registers an installation for an orchestra version, replacing the one registered for it before. + /// Registers an installation for an orchestra version, replacing the one registered for it before and what was + /// registered for the same root. /// public void Register(string orchesterVersion, StellarInstallation installation) { if (string.IsNullOrWhiteSpace(orchesterVersion)) throw new ArgumentException("The orchestra version must not be empty", nameof(orchesterVersion)); - var file = Read(); + InstallationRegistryFile file = Read(); file.Installations.RemoveAll(entry => - string.Equals(entry.OrchesterVersion, orchesterVersion, StringComparison.Ordinal)); + string.Equals(entry.OrchesterVersion, orchesterVersion, StringComparison.Ordinal) + || RootComparer.Equals(Normalize(entry.Root), Normalize(installation.Root))); file.Installations.Add(new RegisteredInstallation { OrchesterVersion = orchesterVersion, Root = installation.Root }); Write(file); @@ -151,8 +156,8 @@ public void Register(string orchesterVersion, StellarInstallation installation) /// The orchestra versions that were registered for it. public IReadOnlyList Unregister(StellarInstallation installation) { - var file = Read(); - var removed = file.Installations + InstallationRegistryFile file = Read(); + List removed = file.Installations .Where(entry => RootComparer.Equals(Normalize(entry.Root), Normalize(installation.Root))) .ToList(); @@ -182,7 +187,8 @@ private void Write(InstallationRegistryFile file) // Nothing registered: the registry leaves nothing behind, and an empty folder goes with it Delete(File); Delete(MSBuildFile); - if (System.IO.Directory.Exists(Directory) && !System.IO.Directory.EnumerateFileSystemEntries(Directory).Any()) + if (System.IO.Directory.Exists(Directory) && + !System.IO.Directory.EnumerateFileSystemEntries(Directory).Any()) System.IO.Directory.Delete(Directory); return; } @@ -198,13 +204,14 @@ internal static string RenderMSBuild(InstallationRegistryFile file) { var builder = new StringBuilder(); builder.AppendLine(""); - builder.AppendLine($" "); + builder.AppendLine( + $" "); builder.AppendLine(" "); - foreach (var entry in file.Installations) + foreach (RegisteredInstallation entry in file.Installations) { - var version = SecurityElement.Escape(entry.OrchesterVersion); - var root = SecurityElement.Escape(entry.Root.TrimEnd('/', '\\') + Path.DirectorySeparatorChar); + string version = SecurityElement.Escape(entry.OrchesterVersion); + string root = SecurityElement.Escape(entry.Root.TrimEnd('/', '\\') + Path.DirectorySeparatorChar); builder.AppendLine( $" {root}"); } diff --git a/SDK/src/Stellar.Tools/Installation/EngineInstaller.cs b/SDK/src/Stellar.Tools/Installation/EngineInstaller.cs index 960e093..51d5cc2 100644 --- a/SDK/src/Stellar.Tools/Installation/EngineInstaller.cs +++ b/SDK/src/Stellar.Tools/Installation/EngineInstaller.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; + using Stellar.Kernel.Configuration.Manifest; using Stellar.Tools.Diagnostics; using Stellar.Tools.Environment; @@ -41,7 +42,7 @@ public static void Install(StellarInstallation installation, IToolLogger logger, throw new ToolException( $"{installation.Root} is not a checkout of StellarEngine-Core: the root of an installation is the core itself"); - foreach (var directory in new[] + foreach (string directory in new[] { installation.Modules, installation.Packages, installation.Manifests, installation.Config, installation.Tools, installation.ResourceCompilers, installation.Projects diff --git a/SDK/src/Stellar.Tools/Modules/ModuleSynchronizer.cs b/SDK/src/Stellar.Tools/Modules/ModuleSynchronizer.cs index f64a5e9..2604dcc 100644 --- a/SDK/src/Stellar.Tools/Modules/ModuleSynchronizer.cs +++ b/SDK/src/Stellar.Tools/Modules/ModuleSynchronizer.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; using System.Linq; + +using Stellar.Kernel.Configuration.Manifest; using Stellar.Tools.Diagnostics; using Stellar.Tools.Environment; using Stellar.Tools.Manifests; @@ -27,17 +29,17 @@ public static class ModuleSynchronizer /// Thrown if the modules break the rules. public static ModuleSet Load(StellarInstallation installation) { - var manifest = EngineManifestStore.Load(installation.EngineManifest); - var resolution = ModuleResolver.Resolve(installation, manifest); + EngineManifest manifest = EngineManifestStore.Load(installation.EngineManifest); + ModuleResolution resolution = ModuleResolver.Resolve(installation, manifest); if (!resolution.IsValid) throw Failure(resolution.Errors); - var graph = ModuleGraph.Analyze(resolution.Modules.Select(module => module.Descriptor)); + ModuleGraphResult graph = ModuleGraph.Analyze(resolution.Modules.Select(module => module.Descriptor)); if (!graph.IsValid) throw Failure(graph.Errors); - var byId = resolution.Modules.ToDictionary(module => module.Id); + Dictionary byId = resolution.Modules.ToDictionary(module => module.Id); return new ModuleSet(resolution, graph.LoadOrder.Select(descriptor => byId[descriptor.Id]).ToList()); } @@ -50,15 +52,15 @@ public static ModuleSet Load(StellarInstallation installation) /// Thrown if the modules break the rules. Nothing is written then. public static ModuleSet Synchronize(StellarInstallation installation, IToolLogger logger) { - var set = Load(installation); + ModuleSet set = Load(installation); - foreach (var warning in set.Resolution.Warnings) + foreach (string warning in set.Resolution.Warnings) logger.Warning(warning); - var catalogChanged = + bool catalogChanged = FileWriter.WriteAllText(installation.ModuleCatalog, ModuleCatalogGenerator.Render(set.LoadOrder)); - var lockChanged = FileWriter.WriteAllText(installation.ModuleLock, - StellarJson.Serialize(new ModuleLockFile(set.LoadOrder))); + bool lockChanged = + FileWriter.WriteAllText(installation.ModuleLock, StellarJson.Serialize(new ModuleLockFile(set.LoadOrder))); if (catalogChanged || lockChanged) logger.Info($"Module catalog updated: {set.LoadOrder.Count} module(s), {installation.ModuleCatalog}"); diff --git a/SDK/tests/Stellar.Tools.Tests/InstallationTests.cs b/SDK/tests/Stellar.Tools.Tests/InstallationTests.cs index bc4ca5d..353a529 100644 --- a/SDK/tests/Stellar.Tools.Tests/InstallationTests.cs +++ b/SDK/tests/Stellar.Tools.Tests/InstallationTests.cs @@ -1,4 +1,5 @@ using System.Diagnostics; + using Stellar.Tools.Diagnostics; using Stellar.Tools.Environment; using Stellar.Tools.Installation; @@ -35,8 +36,9 @@ public void Register_KeepsOneInstallationPerOrchestra_AndWritesTheMSBuildView() registry.Find("0.8.0")!.Root.Should().Be(second.Root); registry.Find("0.9.0")!.Root.Should().Be(other.Root); - var props = File.ReadAllText(registry.MSBuildFile); - props.Should().Contain("'$(StellarOrchesterVersion)' == '0.8.0'\">" + second.Root + Path.DirectorySeparatorChar); + string props = File.ReadAllText(registry.MSBuildFile); + props.Should() + .Contain("'$(StellarOrchesterVersion)' == '0.8.0'\">" + second.Root + Path.DirectorySeparatorChar); props.Should().Contain("'$(StellarOrchesterVersion)' == '0.9.0'\">" + other.Root + Path.DirectorySeparatorChar); props.Should().NotContain(first.Root + Path.DirectorySeparatorChar + "<"); } @@ -49,9 +51,10 @@ public void Unregister_RemovesEveryVersionOfTheRoot_AndTheLastOneLeavesNothing() var installation = new StellarInstallation(Path.Combine(directory.Path, "engine")); var other = new StellarInstallation(Path.Combine(directory.Path, "other")); - registry.Register("0.8.0", installation); - registry.Register("0.9.0", installation); registry.Register("1.0.0", other); + File.WriteAllText(registry.File, File.ReadAllText(registry.File).Replace("\"Installations\": [", + $"\"Installations\": [ {{ \"OrchesterVersion\": \"0.8.0\", \"Root\": {Json(installation.Root)} }}, " + + $"{{ \"OrchesterVersion\": \"0.9.0\", \"Root\": {Json(installation.Root)} }},")); registry.Unregister(installation).Should().BeEquivalentTo("0.8.0", "0.9.0"); registry.List().Should().ContainSingle().Which.OrchesterVersion.Should().Be("1.0.0"); @@ -60,6 +63,27 @@ public void Unregister_RemovesEveryVersionOfTheRoot_AndTheLastOneLeavesNothing() Directory.Exists(registry.Directory).Should().BeFalse(); } + private static string Json(string text) + { + return System.Text.Json.JsonSerializer.Serialize(text); + } + + [Fact] + public void Register_ANewOrchestraInTheSameRoot_ReplacesTheOldOne() + { + using var directory = new TempDirectory(); + var registry = new InstallationRegistry(Path.Combine(directory.Path, "home")); + var installation = new StellarInstallation(Path.Combine(directory.Path, "engine")); + var other = new StellarInstallation(Path.Combine(directory.Path, "other")); + + registry.Register("0.9.0", other); + registry.Register("0.10.0", installation); + registry.Register("0.11.0", installation); + + registry.List().Select(entry => $"{entry.OrchesterVersion} {entry.Root}") + .Should().Equal($"0.11.0 {installation.Root}", $"0.9.0 {other.Root}"); + } + [Fact] public void TryLocate_FindsTheInstallationOfThisOrchestraInTheRegistry() { @@ -78,18 +102,19 @@ public void TryLocate_FindsTheInstallationOfThisOrchestraInTheRegistry() public class UninstallerTests { private static (StellarInstallation Installation, InstallationRegistry Registry, string Cache) Installed( - TempDirectory directory) + TempDirectory directory + ) { directory.Write("Shared/Templates/Installation/config/Stellar.Sdk.props", "settings {{OrchesterVersion}}"); directory.Write("Shared/Templates/Installation/projects/Directory.Build.props", "isolation"); - var installation = FakeCore.Create(directory); + StellarInstallation installation = FakeCore.Create(directory); var registry = new InstallationRegistry(Path.Combine(directory.Path, "home")); EngineInstaller.Install(installation, NullToolLogger.Instance, registry); directory.Write("packages/Stellar.Kernel.0.8.0.nupkg"); directory.Write("packages/Stellar.Sdk.0.4.0-preview.1.nupkg"); - var cache = Path.Combine(directory.Path, "nuget"); + string cache = Path.Combine(directory.Path, "nuget"); directory.Write("nuget/stellar.kernel/0.8.0/stellar.kernel.nuspec"); directory.Write("nuget/stellar.kernel/0.7.0/stellar.kernel.nuspec"); directory.Write("nuget/stellar.sdk/0.4.0-preview.1/stellar.sdk.nuspec"); @@ -103,7 +128,7 @@ public void Uninstall_RefusesADirectoryThatIsNotTheCore() { using var directory = new TempDirectory(); - var action = () => EngineUninstaller.Uninstall(new StellarInstallation(directory.Path), + Func action = () => EngineUninstaller.Uninstall(new StellarInstallation(directory.Path), NullToolLogger.Instance, new UninstallOptions()); action.Should().Throw().WithMessage("*not a checkout of StellarEngine-Core*"); @@ -113,12 +138,12 @@ public void Uninstall_RefusesADirectoryThatIsNotTheCore() public void Uninstall_LeavesAPlainCheckout_AndNeverTouchesTheContentOfTheUser() { using var directory = new TempDirectory(); - var (installation, registry, cache) = Installed(directory); + (StellarInstallation installation, InstallationRegistry registry, string cache) = Installed(directory); directory.Write("modules/Stellar.FileSystem/Stellar.FileSystem.stellar.module", "{}"); directory.Write("projects/MyGame/MyGame.csproj", ""); directory.Write("tools/StellarEditor/README.md"); - var report = EngineUninstaller.Uninstall(installation, NullToolLogger.Instance, + UninstallReport report = EngineUninstaller.Uninstall(installation, NullToolLogger.Instance, new UninstallOptions { Registry = registry, PackageCache = cache }); // The machine forgot it @@ -132,7 +157,7 @@ public void Uninstall_LeavesAPlainCheckout_AndNeverTouchesTheContentOfTheUser() Directory.Exists(Path.Combine(cache, "newtonsoft.json", "13.0.3")).Should().BeTrue(); // What the installer made is gone - foreach (var path in new[] + foreach (string path in new[] { installation.Packages, installation.Manifests, installation.Config, Path.Combine(installation.Modules, "Directory.Build.props"), @@ -153,12 +178,12 @@ public void Uninstall_LeavesAPlainCheckout_AndNeverTouchesTheContentOfTheUser() public void Uninstall_RemovesEmptyFoldersOfTheInstaller() { using var directory = new TempDirectory(); - var (installation, registry, cache) = Installed(directory); + (StellarInstallation installation, InstallationRegistry registry, string cache) = Installed(directory); EngineUninstaller.Uninstall(installation, NullToolLogger.Instance, new UninstallOptions { Registry = registry, PackageCache = cache }); - foreach (var path in new[] { installation.Modules, installation.Projects, installation.Tools }) + foreach (string path in new[] { installation.Modules, installation.Projects, installation.Tools }) Directory.Exists(path).Should().BeFalse(path); } @@ -166,11 +191,11 @@ public void Uninstall_RemovesEmptyFoldersOfTheInstaller() public void Uninstall_KeepsEditedFiles_UnlessAll() { using var directory = new TempDirectory(); - var (installation, registry, _) = Installed(directory); - var settings = Path.Combine(installation.Config, "Stellar.Sdk.props"); + (StellarInstallation installation, InstallationRegistry registry, _) = Installed(directory); + string settings = Path.Combine(installation.Config, "Stellar.Sdk.props"); File.WriteAllText(settings, "my settings"); - var report = EngineUninstaller.Uninstall(installation, NullToolLogger.Instance, + UninstallReport report = EngineUninstaller.Uninstall(installation, NullToolLogger.Instance, new UninstallOptions { Registry = registry }); File.ReadAllText(settings).Should().Be("my settings"); @@ -186,9 +211,9 @@ public void Uninstall_KeepsEditedFiles_UnlessAll() public void Uninstall_DryRun_ChangesNothing() { using var directory = new TempDirectory(); - var (installation, registry, cache) = Installed(directory); + (StellarInstallation installation, InstallationRegistry registry, string cache) = Installed(directory); - var report = EngineUninstaller.Uninstall(installation, NullToolLogger.Instance, + UninstallReport report = EngineUninstaller.Uninstall(installation, NullToolLogger.Instance, new UninstallOptions { Registry = registry, PackageCache = cache, DryRun = true }); report.Unregistered.Should().Equal(StellarVersions.Orchester); @@ -207,16 +232,21 @@ public void Uninstall_RemovesALinkAsALink_NeverWhatItPointsAt() using var directory = new TempDirectory(); using var outside = new TempDirectory(); - var precious = outside.Write("precious.txt", "keep me"); - var (installation, registry, _) = Installed(directory); - - var junction = Path.Combine(installation.Packages, "linked"); - using (var mklink = Process.Start(new ProcessStartInfo("cmd.exe", $"/c mklink /J \"{junction}\" \"{outside.Path}\"") - { CreateNoWindow = true, UseShellExecute = false })) + string precious = outside.Write("precious.txt", "keep me"); + (StellarInstallation installation, InstallationRegistry registry, _) = Installed(directory); + + string junction = Path.Combine(installation.Packages, "linked"); + using (Process? mklink = Process.Start( + new ProcessStartInfo("cmd.exe", $"/c mklink /J \"{junction}\" \"{outside.Path}\"") + { CreateNoWindow = true, UseShellExecute = false })) + { mklink!.WaitForExit(); + } + Directory.Exists(junction).Should().BeTrue("the junction must exist for this test to mean anything"); - EngineUninstaller.Uninstall(installation, NullToolLogger.Instance, new UninstallOptions { Registry = registry }); + EngineUninstaller.Uninstall(installation, NullToolLogger.Instance, + new UninstallOptions { Registry = registry }); Directory.Exists(installation.Packages).Should().BeFalse(); File.ReadAllText(precious).Should().Be("keep me"); diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 7d015b7..c56fabf 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -36,6 +36,10 @@ With -Install: do not register this installation for the current user ($STELLAR_HOME or ~/.stellar), and do not install the 'stellar' command. For sandboxes. +.PARAMETER SkipModules + With -Install: do not build and pack the modules of modules/. Without it they are built after the core, with + their tests unless -SkipTests, so games that take the engine as packages find them. + .PARAMETER Uninstall Undoes -Install and the build instead of building: 'stellar uninstall' here (the registration of the user, the packages of this installation in the NuGet cache, what the installer created), the 'stellar' command, then @@ -57,6 +61,7 @@ param( [switch]$Pack, [switch]$Install, [switch]$NoUserRegistration, + [switch]$SkipModules, [switch]$Uninstall, [switch]$All, [switch]$KeepArtifacts @@ -181,6 +186,12 @@ if (-not $SkipNative) { "-p:Configuration=$Configuration" -p:Platform=x64 -m -nologo -v:minimal } + if (-not $SkipTests) { + Invoke-Step 'Native tests' { + & (Join-Path $root "artifacts/bin/Stellar.Native.Core.Tests/$Configuration/Stellar.Native.Core.Tests.exe") + } + } + # Built by the MSBuild of Visual Studio: the .NET SDK cannot build C++/CLI if ($canBuildCli) { Invoke-Step 'C++/CLI wrapper' { @@ -188,12 +199,6 @@ if (-not $SkipNative) { -restore "-p:Configuration=$Configuration" -p:Platform=x64 -m -nologo -v:minimal } } - - if (-not $SkipTests) { - Invoke-Step 'Native tests' { - & (Join-Path $root "artifacts/bin/Stellar.Native.Core.Tests/$Configuration/Stellar.Native.Core.Tests.exe") - } - } } $managed = Join-Path $root 'StellarEngine-Core.Managed.slnf' @@ -212,7 +217,12 @@ foreach ($variant in $wrappers) { } if ($Pack) { - $projects = 'Kernel/src/Managed/Stellar.Kernel', 'Core/src/Managed/Stellar.Core', 'Runtime/src/Managed/Stellar.Runtime', 'SDK/src/Stellar.Tools', 'SDK/src/Stellar.Cli', 'SDK/src/MSBuild/Stellar.Sdk' + $projects = 'Kernel/src/Managed/Stellar.Kernel', + 'Core/src/Managed/Stellar.Core', + 'Runtime/src/Managed/Stellar.Runtime', + 'SDK/src/Stellar.Tools', + 'SDK/src/Stellar.Cli', + 'SDK/src/MSBuild/Stellar.Sdk' foreach ($project in $projects) { $csproj = Join-Path $root "$project/$(Split-Path $project -Leaf).csproj" @@ -251,6 +261,21 @@ if ($Install) { # Registration and the command go together: both belong to the user, not to the checkout if (-not $NoUserRegistration) { Install-StellarTool } + + $modules = @(Get-ChildItem (Join-Path $root 'modules') -Filter '*.stellar.module' -Recurse -Depth 1 -ErrorAction SilentlyContinue) + if (-not $SkipModules -and $modules.Count -gt 0) { + $arguments = @('modules', 'build', '--pack', '-c', $Configuration, '--wrapper', $Wrapper) + if (-not $SkipTests) { $arguments += '--tests' } + + Invoke-Step "Modules ($($modules.Count))" { + Push-Location $root + try { + dotnet run --project (Join-Path $root 'SDK/src/Stellar.Cli/Stellar.Cli.csproj') -c $Configuration --no-build -- @arguments + } finally { + Pop-Location + } + } + } } -Write-Host "StellarEngine-Core built ($Configuration, wrappers: $($wrappers -join ', '), packed with: $Wrapper) in $root" -ForegroundColor Green +Write-Host "StellarEngine built ($Configuration, wrappers: $($wrappers -join ', '), packed with: $Wrapper) in $root" -ForegroundColor Green From 22d5056d1ba49d73fedc26b9bf78119112830749 Mon Sep 17 00:00:00 2001 From: MarcT1me Date: Sat, 28 Nov 2026 20:58:12 +0200 Subject: [PATCH 2/3] [DOCS] [SDK] publish the documentation to the docs site, drop the DocFX sites --- .github/workflows/docs.yml | 112 +++++++-- .gitignore | 2 - Docs/Architecture/NativeAbi.md | 2 +- Docs/Architecture/Sdk.md | 2 +- Docs/Architecture/Tools.md | 2 +- Docs/Engine/Architecture.md | 2 +- Docs/Engine/DesignPhilosophy.md | 2 +- Docs/Engine/Documentation.md | 103 ++++++++ Docs/Engine/FAQ.md | 81 ++++++ Docs/Engine/GitPolicy.md | 6 +- Docs/Engine/Install.md | 3 + Docs/Engine/Marks.md | 2 +- Docs/Engine/Modules.md | 4 +- Docs/Engine/PostInstallSetup.md | 2 +- Docs/Engine/Repository.md | 34 +-- Docs/Engine/Versioning.md | 6 +- Docs/Engine/toc.yml | 12 +- Docs/Formats/EngineManifest.md | 2 +- Docs/Migration-0.11.md | 11 +- Docs/Migration-0.8.md | 2 +- Docs/Reference/Sdk.Properties.md | 2 +- Docs/index.md | 4 +- Docs/toc.yml | 6 +- README.md | 3 +- .../Environment/StellarVersions.cs | 25 +- .../Stellar.Tools/Modules/ModuleScaffolder.cs | 16 +- Shared/Build/Stellar.Core.Build.targets | 3 + Shared/Build/Stellar.Versions.props | 18 +- Shared/Docs/Template/public/main.css | 67 ----- .../Managed/.github/workflows/docs.yml | 108 ++++++-- .../Templates/Modules/Managed/Docs/index.md | 3 +- Shared/Templates/Modules/Managed/Docs/toc.yml | 4 +- .../Modules/Managed/Template/public/main.css | 67 ----- Shared/Templates/Modules/Managed/docfx.json | 30 +-- .../Templates/Modules/Managed/prometheus.json | 15 ++ docfx.json | 39 +-- prometheus.json | 4 + scripts/orchestra-site.ps1 | 230 ------------------ scripts/prometheus.ps1 | 98 ++++++++ 39 files changed, 598 insertions(+), 536 deletions(-) create mode 100644 Docs/Engine/Documentation.md create mode 100644 Docs/Engine/FAQ.md delete mode 100644 Shared/Docs/Template/public/main.css delete mode 100644 Shared/Templates/Modules/Managed/Template/public/main.css create mode 100644 Shared/Templates/Modules/Managed/prometheus.json create mode 100644 prometheus.json delete mode 100644 scripts/orchestra-site.ps1 create mode 100644 scripts/prometheus.ps1 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 00f10c4..55300e0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,11 +1,22 @@ name: Docs -# Builds the documentation site with DocFX and publishes it to GitHub Pages. One workflow, two sites: -# - in StellarEngine-Core: the site of the core (docfx.json): Docs/, the API reference, the schemas, the installer; -# - in the mirror (StellarEngine-Mono), recognized by the .orchestra file scripts/mirror.ps1 puts at its root: -# the site of the orchestra (scripts/orchestra-site.ps1), the core and every module in one site. -# Pull requests and manual runs on other branches only build; the site is deployed from master only. -# Repository setting required once: Settings -> Pages -> Source = "GitHub Actions". +# Publishes the documentation of this repository to GitHub Pages for the Prometheus site (the team site). +# GitHub Pages is only the storage of the site: static files (the installer, the schemas), the documentation as data +# (bundle/) and a small embed that redirects to the site when the site is up. +# +# This file is a thin wrapper and does not need updates: the steps (ci.py, the bundle builder, the embed) are +# downloaded from the site on every run (/docs-kit.zip), so they are always the same version as the site. +# What to build is described by the repository itself in prometheus.json (format prometheus-repo/1, see the DOCS +# page of the site); without it: Docs/ and the API of the projects in docfx.json. +# If the site is down, the static files and a page that leads to the site are published; the next run fixes the rest. +# +# Repository settings: +# Settings -> Pages -> Source = "GitHub Actions" (once) +# Variables (optional): PROMETHEUS_SITE (https://notagood.org by default), +# PROMETHEUS_PROJECT, PROMETHEUS_TITLE (override prometheus.json) +# Secrets (optional): PROMETHEUS_SYNC_KEY an API key of the site with the "sync" scope: the site learns about +# the new build at once instead of on its next check +# Pull requests and manual runs on other branches only build; Pages is deployed from master only. on: push: @@ -24,49 +35,88 @@ env: DOCFX_VERSION: '2.81.0' DOTNET_NOLOGO: 'true' DOTNET_CLI_TELEMETRY_OPTOUT: 'true' + PROMETHEUS_SITE: ${{ vars.PROMETHEUS_SITE || 'https://notagood.org' }} + PROMETHEUS_PROJECT: ${{ vars.PROMETHEUS_PROJECT }} + PROMETHEUS_TITLE: ${{ vars.PROMETHEUS_TITLE }} + OUT: artifacts/pages jobs: build: - name: Build site - runs-on: ubuntu-latest + name: Build + runs-on: ubuntu-latest # pwsh, python3 and bash are there: "prepare" scripts may use any of them steps: - name: Checkout uses: actions/checkout@v5 - name: Setup .NET + if: hashFiles('global.json') != '' uses: actions/setup-dotnet@v5 with: global-json-file: global.json - # Installed outside the checkout so the repository NuGet.config (local "packages" feed) is not involved. + - name: Setup .NET (no global.json) + if: hashFiles('global.json') == '' + uses: actions/setup-dotnet@v5 + with: + dotnet-version: '9.0.x' + + # Installed outside the checkout so a repository NuGet.config (a local feed) is not involved. - name: Install DocFX working-directory: ${{ runner.temp }} run: dotnet tool install docfx --version "$DOCFX_VERSION" --tool-path "$RUNNER_TEMP/docfx" - - name: Choose the site - id: site - shell: pwsh + - name: Prometheus + id: prometheus + continue-on-error: true run: | - # The local feed of an installation: empty here, but NuGet wants the folder it names to exist - New-Item -ItemType Directory -Force packages | Out-Null - if (Test-Path .orchestra) { - ./scripts/orchestra-site.ps1 - "config=docfx.orchestra.json" >> $env:GITHUB_OUTPUT - "output=artifacts/docs/orchestra-site" >> $env:GITHUB_OUTPUT - } else { - "config=docfx.json" >> $env:GITHUB_OUTPUT - "output=artifacts/docs/site" >> $env:GITHUB_OUTPUT - } + set -euo pipefail + # NuGet wants the local feed folder of an installation to exist, even empty + mkdir -p packages + curl -fsSL --retry 2 "$PROMETHEUS_SITE/docs-kit.zip" -o "$RUNNER_TEMP/kit.zip" + unzip -q -o "$RUNNER_TEMP/kit.zip" -d "$RUNNER_TEMP/kit" + python3 -m pip install --quiet pyyaml + python3 "$RUNNER_TEMP/kit/ci.py" --out "$OUT" --docfx "$RUNNER_TEMP/docfx/docfx" - # metadata (the API reference from the managed projects), then build - - name: Build documentation - run: '"$RUNNER_TEMP/docfx/docfx" "${{ steps.site.outputs.config }}" --warningsAsErrors' + # The site is down or the build failed: publish the static files and a page that leads to the site. + # Self-contained on purpose (no kit): the installer and the schemas keep their addresses whatever happens. + - name: Fallback + if: steps.prometheus.outcome == 'failure' + run: | + echo "::warning title=Prometheus::The documentation was not built (is $PROMETHEUS_SITE up?); publishing the static files only" + mkdir -p "$OUT" && touch "$OUT/.nojekyll" + python3 - <<'PY' + import glob, html, json, os, re, shutil + out = os.environ["OUT"] + cfg = json.load(open("prometheus.json", encoding="utf-8-sig")) if os.path.isfile("prometheus.json") else {} + static = cfg.get("static") or next((a.get("docfx") if isinstance(a, dict) else a for a in cfg.get("api") or []), None) \ + or ("docfx.json" if os.path.isfile("docfx.json") else None) + for config in ([static] if isinstance(static, str) else static or []): + if not os.path.isfile(config): + continue + base = os.path.dirname(os.path.abspath(config)) + for r in json.load(open(config, encoding="utf-8-sig")).get("build", {}).get("resource", []): + src, dest = os.path.join(base, r.get("src", "")), os.path.join(out, r.get("dest", "")) + for pattern in r.get("files", []): + for f in glob.glob(os.path.join(src, pattern), recursive=True): + if os.path.isfile(f): + t = os.path.join(dest, os.path.relpath(f, src)) + os.makedirs(os.path.dirname(t), exist_ok=True) + shutil.copy2(f, t) + repo = os.environ.get("GITHUB_REPOSITORY", "").rsplit("/", 1)[-1] + project = os.environ.get("PROMETHEUS_PROJECT") or cfg.get("project") or re.sub(r"[^a-z0-9]+", "-", repo.lower()).strip("-") + url = html.escape(f"{os.environ['PROMETHEUS_SITE'].rstrip('/')}/docs/{project}") + title = html.escape(os.environ.get("PROMETHEUS_TITLE") or cfg.get("title") or repo) + with open(os.path.join(out, "index.html"), "w", encoding="utf-8") as f: + f.write(f'{title}' + f'' + f'

{title} documentation

') + PY - name: Upload Pages artifact if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' uses: actions/upload-pages-artifact@v5 with: - path: ${{ steps.site.outputs.output }} + path: ${{ env.OUT }} deploy: name: Deploy to GitHub Pages @@ -87,3 +137,13 @@ jobs: - name: Deploy id: deployment uses: actions/deploy-pages@v5 + + # The site would notice the new bundle on its next check anyway; this makes it immediate. + - name: Nudge the site + continue-on-error: true + env: + KEY: ${{ secrets.PROMETHEUS_SYNC_KEY }} + run: | + if [ -z "$KEY" ]; then echo "::notice::PROMETHEUS_SYNC_KEY is not set: the site picks the docs up on its next check"; exit 0; fi + sleep 30 # Pages needs a moment to serve the new files + curl -fsS -X POST -H "Authorization: Bearer $KEY" "$PROMETHEUS_SITE/api/v1/sync" diff --git a/.gitignore b/.gitignore index 65937a5..33ae65d 100644 --- a/.gitignore +++ b/.gitignore @@ -16,8 +16,6 @@ /StellarEngine.*.slnf # The bare repository scripts/mirror.ps1 builds the snapshots of the orchestra in /.mirror/ -# The DocFX project of the orchestra site, generated by scripts/orchestra-site.ps1 -/docfx.orchestra.json # ---- Build output ---- [Bb]in/ diff --git a/Docs/Architecture/NativeAbi.md b/Docs/Architecture/NativeAbi.md index 3cae2f5..3cd5611 100644 --- a/Docs/Architecture/NativeAbi.md +++ b/Docs/Architecture/NativeAbi.md @@ -230,7 +230,7 @@ The native core follows the handle and umbrella rules of the Kernel: ``` A native project of a module gets the include directories, `STELLAR_KERNEL_STATIC` and the import libraries from -`Shared/Build/Stellar.Native.Module.props` (see [Modules](https://quantumdevteam.github.io/StellarEngine-Mono/guide/Modules.html)); the toolchain itself comes from +`Shared/Build/Stellar.Native.Module.props` (see [Modules](../Engine/Modules.md)); the toolchain itself comes from `Shared/Build/Stellar.Native.props`, shared with the core. Inside a module, paths start at the root of the module. Headers of the C++/CLI wrapper end with `.cli.h`: MSVC also searches the folders of the open includes, and a wrapper diff --git a/Docs/Architecture/Sdk.md b/Docs/Architecture/Sdk.md index bbc0796..eb60aac 100644 --- a/Docs/Architecture/Sdk.md +++ b/Docs/Architecture/Sdk.md @@ -33,7 +33,7 @@ The SDK itself comes from the local feed through `NuGet.config`. `stellar projec generate both files; a project under the root of the installation also finds the `NuGet.config` of the root. A module project needs even less: it is nearly empty, and the SDK takes its kind, version and dependencies from its -descriptor. See [Modules](https://quantumdevteam.github.io/StellarEngine-Mono/guide/Modules.html). Every property: [Sdk.Properties](../Reference/Sdk.Properties.md). +descriptor. See [Modules](../Engine/Modules.md). Every property: [Sdk.Properties](../Reference/Sdk.Properties.md). ## Kinds of projects diff --git a/Docs/Architecture/Tools.md b/Docs/Architecture/Tools.md index 9dd801d..6643782 100644 --- a/Docs/Architecture/Tools.md +++ b/Docs/Architecture/Tools.md @@ -83,7 +83,7 @@ Later additions win, and anything no compiler claims is packed as is by `RawReso | `stellar uninstall [path]` | Remove an installation: unregister it, drop its packages from the NuGet cache, remove what the installer made; `--all`, `--artifacts`, `--dry-run` | | `stellar modules list` | Show the manifest in load order | | `stellar modules sync` | Find the modules, apply the manifest, check the rules, regenerate the catalog | -| `stellar modules new`, `templates`, `add`, `enable`, `disable`, `reset`, `build` | See [Modules](https://quantumdevteam.github.io/StellarEngine-Mono/guide/Modules.html) | +| `stellar modules new`, `templates`, `add`, `enable`, `disable`, `reset`, `build` | See [Modules](../Engine/Modules.md) | | `stellar solution sync [directory]` | Write the `.sln` again: the projects of the solution, the engine when `"Engine"` is `Sources` | | `stellar run [target]` | Build and run a game or a tool of the solution, or several at once; see [`.stellar.solution`](../Formats/SolutionFile.md) | | `stellar project new