From 2663f0c574d15e1715143c6b82ade8b11fd06a0a Mon Sep 17 00:00:00 2001 From: Timur Shestakov <153988210+MarcT1me@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:33:33 +0700 Subject: [PATCH 1/7] Remove the repository CLA copy; point to the central CLA (#12) Co-authored-by: MarcT1me --- .github/pull_request_template.md | 1 - CLA.md | 98 -------------------------------- CONTRIBUTING.md | 3 +- Docs/Engine/toc.yml | 2 - NOTICE | 17 +++--- README.md | 2 +- StellarEngine-Core.sln | 1 - scripts/orchestra-site.ps1 | 4 +- 8 files changed, 13 insertions(+), 115 deletions(-) delete mode 100644 CLA.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index bd665f1..76e57ff 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -20,7 +20,6 @@ Describe the purpose of this pull request and the changes introduced. ## Checklist * [ ] I have read `CONTRIBUTING.md` -* [ ] I agree to the terms of `CLA.md` * [ ] I confirm that I have the legal right to submit this contribution * [ ] My contribution does not knowingly include incompatible third-party code or assets diff --git a/CLA.md b/CLA.md deleted file mode 100644 index 52c1275..0000000 --- a/CLA.md +++ /dev/null @@ -1,98 +0,0 @@ -# Contributor License Agreement (CLA) - -Thank you for contributing to StellarEngine. - -By submitting any contribution (including code, documentation, assets, -configuration files, issue patches, pull requests, or other materials) -to the StellarEngine project, you agree to the following terms. - ---- - -## 1. Ownership of Contributions - -By submitting contributions to StellarEngine, you assign and transfer -to Timur Shestakov (the "Project Owner"), operating under the public -project identity "QuantumDevTeam", all rights, title, interest, a -nd associated intellectual property rights, including copyright and -related rights in and to your contributions, including all associated -intellectual property rights. - -If a future legal entity is established by the Project Owner for the -management, development, licensing, or distribution of StellarEngine, -these rights may be transferred or assigned to that entity. - -You acknowledge that your contributions become part of the -StellarEngine project and may be used, modified, relicensed, -commercialized, sublicensed, redistributed, or incorporated into -open-source or closed-source products without restriction by the -Project Owner. - -Contributions are provided "as is", without warranty of any kind, -express or implied. - ---- - -## 2. License Grant - -To the extent that any rights cannot be assigned or transferred under -applicable law, you grant Timur Shestakov (the "Project Owner"), -operating under the public project identity "QuantumDevTeam", as well -as any future legal entity established by the Project Owner for the -management, development, licensing, or distribution of StellarEngine, -a perpetual, irrevocable, worldwide, transferable, assignable, -non-exclusive, royalty-free license to: - -* use -* reproduce -* modify -* adapt -* distribute -* sublicense -* relicense -* publicly display -* commercially license - -your contributions as part of StellarEngine and any future versions, -editions, derivative works, or related products. - -This license applies to both open and closed-source distributions of -StellarEngine. - ---- - -## 3. Right to Contribute - -You confirm that: - -* you have the legal right to submit the contribution -* the contribution is your original work, or you have sufficient rights -to provide it -* the contribution does not knowingly violate the rights of any third -party - ---- - -## 4. Third-Party Content - -Do not submit code, assets, libraries, or content that: - -* you are not legally allowed to distribute -* is incompatible with the project license -* introduces legal or licensing conflicts into the project - ---- - -## 5. No Obligation - -Submitting a contribution does not guarantee that it will be accepted, -reviewed, merged, maintained, or included in future versions of -StellarEngine. - ---- - -## 6. Acceptance of Agreement - -Submitting a pull request, patch, or other contribution to StellarEngine -constitutes acceptance of this agreement. - -If you do not agree to these terms, do not submit contributions. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2943930..61b8d50 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -102,8 +102,7 @@ workflow and versioning rules. ## Licensing and Contributions -By submitting contributions, you agree to the terms described -in [CLA.md](CLA.md). +By submitting contributions, you agree to the project's contribution terms. Contributions are provided "as is", without warranty of any kind, express or implied. diff --git a/Docs/Engine/toc.yml b/Docs/Engine/toc.yml index 3365785..c47ba0b 100644 --- a/Docs/Engine/toc.yml +++ b/Docs/Engine/toc.yml @@ -22,5 +22,3 @@ href: Versioning.md - name: License href: ../../LICENSE.md - - name: CLA - href: ../../CLA.md diff --git a/NOTICE b/NOTICE index 644897c..72dd97b 100644 --- a/NOTICE +++ b/NOTICE @@ -1,12 +1,13 @@ StellarEngine Copyright (c) 2026 QuantumDevTeam -QuantumDevTeam is the name under which Timur Shestakov acts personally. It is a brand and a -trade name, not a legal entity: the copyright in StellarEngine, and in every module and tool -published under this name, belongs to Timur Shestakov, who is the licensor of the license -below and the "Project Owner" of CLA.md. If a legal entity is established later, the rights -may be assigned to it as CLA.md describes, and this notice will name it. +QuantumDevTeam is the name under which Timur Shestakov acts personally. It is a +brand and a trade name, not a legal entity. The copyright in StellarEngine and +in every part of it published under this name belongs to Timur Shestakov, who +is the Project Owner for the purposes of the CLA published at +https://github.com/QuantumDevTeam/.github/blob/master/licensing/CLA.md. If a +legal entity is established later, the rights may be assigned to it as that CLA +describes, and this notice will name it. -Licensed under the PolyForm Noncommercial License 1.0.0 -https://polyformproject.org/licenses/noncommercial/1.0.0 -See LICENSE.md and CLA.md. +Licensed under the PolyForm Noncommercial License 1.0.0. +See LICENSE.md. diff --git a/README.md b/README.md index 061cb6a..e6c5331 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # StellarEngine -Licensed under PolyForm Noncommercial 1.0.0. See [LICENSE.md](LICENSE.md) and [CLA.md](CLA.md). +Licensed under PolyForm Noncommercial 1.0.0. See [LICENSE.md](LICENSE.md). StellarEngine diff --git a/StellarEngine-Core.sln b/StellarEngine-Core.sln index ce30f4d..47fc277 100644 --- a/StellarEngine-Core.sln +++ b/StellarEngine-Core.sln @@ -96,7 +96,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".root", ".root", "{9CBB857E EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{4B2AC1C6-31E4-429A-8073-1A63FD20D65E}" ProjectSection(SolutionItems) = preProject - CLA.md = CLA.md CONTRIBUTING.md = CONTRIBUTING.md LICENSE.md = LICENSE.md NOTICE = NOTICE diff --git a/scripts/orchestra-site.ps1 b/scripts/orchestra-site.ps1 index 9594400..388b524 100644 --- a/scripts/orchestra-site.ps1 +++ b/scripts/orchestra-site.ps1 @@ -8,7 +8,7 @@ / the home of StellarEngine: getting started, what the orchestra is made of /guide/ the guide of the whole engine: Docs/Engine of the core (installing, architecture, - modules, the orchestra, the project), with README, CONTRIBUTING, LICENSE, CLA at / + modules, the orchestra, the project), with README, CONTRIBUTING, LICENSE at / /core/ the core as a component: the rest of its Docs/, /core/api/ its API reference /modules// the Docs/ of each module (each also has a site of its own) /tools// the same for tools @@ -69,7 +69,7 @@ $rows = [System.Collections.Generic.List[string]]::new() # ---- The guide of the engine ---- # Docs/Engine of the core: the pages about the engine as a whole live there, published here only $content.Add([ordered]@{ src = 'Docs/Engine'; dest = 'guide'; files = @('**/*.md', 'toc.yml') }) -$content.Add([ordered]@{ files = @('README.md', 'CONTRIBUTING.md', 'LICENSE.md', 'CLA.md') }) +$content.Add([ordered]@{ files = @('README.md', 'CONTRIBUTING.md', 'LICENSE.md') }) # ---- The core, a component ---- $content.Add([ordered]@{ src = 'Docs'; dest = 'core'; files = @('**/*.md', 'toc.yml'); exclude = @('Engine/**') }) From b7ae98f36e96fe9d38caad0736df4a4881e4dde5 Mon Sep 17 00:00:00 2001 From: MarcT1me Date: Wed, 18 Nov 2026 23:45:50 +0700 Subject: [PATCH 2/7] [KERNEL] [CORE] [RUNTIME] [SDK] [TOOLS] [DOCS] 0.10: FailureSystem namespace, logger contracts, modules of a solution Kernel: the failure types moved from Stellar.Kernel.Failures to Stellar.Kernel.FailureSystem; ILogger is an IQuant with Start/Stop; new ILoggerCatalog, BaseLogger, LoggerExtensions, LogFormat. Core and Runtime follow the new namespace. SDK, Tools, CLI: a game's own libraries are modules of its solution (level EndPoint, found by 'stellar solution sync', catalog in .stellar/stellar.modules.props, always sources); module discovery skips bin/obj. Versions: Kernel, Core, Runtime and the orchestra 0.10.0, Sdk 0.4.1, Tools 0.3.2, CLI 0.2.3, native ABI unchanged. Docs: Migration-0.10, modules of a solution. --- Core/src/Managed/Stellar.Core/EntryPoint.cs | 2 +- .../Stellar.Core/EntryPoints/RunContext.cs | 2 +- .../Stellar.Core/Failures/FailureSystem.cs | 2 +- .../Managed/Stellar.Core/Global/CoreEngine.cs | 3 +- .../src/Managed/Stellar.Core/Global/Engine.cs | 2 +- .../Stellar.Core.Tests/FailureTests.cs | 8 +- Docs/Architecture/Sdk.md | 2 +- Docs/Engine/Modules.md | 3 + Docs/Formats/SolutionFile.md | 29 +++- Docs/Migration-0.10.md | 94 ++++++++++ Docs/Reference/Sdk.Properties.md | 1 + Docs/index.md | 1 + Docs/toc.yml | 2 + .../Stellar.Kernel/EntryPoint/IRunContext.cs | 2 +- .../{Failures => FailureSystem}/Catcher.cs | 2 +- .../{Failures => FailureSystem}/Failure.cs | 2 +- .../FailureException.cs | 2 +- .../FailureKind.cs | 2 +- .../FailureLevel.cs | 2 +- .../IFailureSystem.cs | 2 +- .../FileSystem/DomainNotFoundException.cs | 2 +- .../Lifecycle/IEngineControl.cs | 2 +- .../LoggingSystem/BaseLogger.cs | 81 +++++++++ .../Stellar.Kernel/LoggingSystem/ILogger.cs | 12 +- .../LoggingSystem/ILoggerCatalog.cs | 25 +++ .../Stellar.Kernel/LoggingSystem/LogFormat.cs | 6 + .../LoggingSystem/LoggerExtensions.cs | 70 ++++++++ .../Stellar.Kernel/Stellar.Kernel.csproj | 2 +- README.md | 1 + .../Failures/RuntimeCatchers.cs | 2 +- .../Stellar.Runtime/Lifecycle/Contexts.cs | 2 +- .../Lifecycle/EngineControl.cs | 2 +- .../Lifecycle/ModuleStarter.cs | 2 +- .../Lifecycle/RuntimeContext.cs | 2 +- .../Lifecycle/RuntimePipeline.cs | 2 +- .../Managed/Stellar.Runtime/Loop/MainLoop.cs | 2 +- .../Managed/Stellar.Runtime/Loop/MainLoops.cs | 2 +- .../Threading/MainThreadDispatcher.cs | 2 +- .../Threading/MainThreadPump.cs | 2 +- .../HostEntryPoint.cs | 2 +- .../Stellar.Runtime.Tests/MainLoopTests.cs | 2 +- .../Sdk/Stellar.Sdk.Catalog.targets | 4 + .../Sdk/Stellar.Sdk.Environment.props | 10 ++ .../Sdk/Stellar.Sdk.References.targets | 2 +- .../Sdk/Stellar.Sdk.Validation.targets | 12 +- .../Stellar.Cli/Commands/SolutionCommands.cs | 6 +- .../Modules/ModuleCatalogGenerator.cs | 10 +- .../Stellar.Tools/Modules/ModuleDiscovery.cs | 21 ++- .../Stellar.Tools/Modules/ModuleResolver.cs | 4 +- .../Stellar.Tools/Modules/ResolvedModule.cs | 5 +- .../Solutions/SolutionModules.cs | 160 ++++++++++++++++++ .../Solutions/StellarSolution.cs | 6 + .../SolutionModulesTests.cs | 131 ++++++++++++++ Shared/Build/Stellar.Versions.props | 14 +- Shared/Schemas/stellar.solution.schema.json | 5 + global.json | 2 +- 56 files changed, 727 insertions(+), 55 deletions(-) create mode 100644 Docs/Migration-0.10.md rename Kernel/src/Managed/Stellar.Kernel/{Failures => FailureSystem}/Catcher.cs (99%) rename Kernel/src/Managed/Stellar.Kernel/{Failures => FailureSystem}/Failure.cs (99%) rename Kernel/src/Managed/Stellar.Kernel/{Failures => FailureSystem}/FailureException.cs (97%) rename Kernel/src/Managed/Stellar.Kernel/{Failures => FailureSystem}/FailureKind.cs (98%) rename Kernel/src/Managed/Stellar.Kernel/{Failures => FailureSystem}/FailureLevel.cs (98%) rename Kernel/src/Managed/Stellar.Kernel/{Failures => FailureSystem}/IFailureSystem.cs (98%) create mode 100644 Kernel/src/Managed/Stellar.Kernel/LoggingSystem/BaseLogger.cs create mode 100644 Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILoggerCatalog.cs create mode 100644 Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogFormat.cs create mode 100644 Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LoggerExtensions.cs create mode 100644 SDK/src/Stellar.Tools/Solutions/SolutionModules.cs create mode 100644 SDK/tests/Stellar.Tools.Tests/SolutionModulesTests.cs diff --git a/Core/src/Managed/Stellar.Core/EntryPoint.cs b/Core/src/Managed/Stellar.Core/EntryPoint.cs index 8196dae..b24b15b 100644 --- a/Core/src/Managed/Stellar.Core/EntryPoint.cs +++ b/Core/src/Managed/Stellar.Core/EntryPoint.cs @@ -2,7 +2,7 @@ using Stellar.Core.Global; using Stellar.Kernel.Configuration; using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.LoggingSystem; using Stellar.Kernel.Services; diff --git a/Core/src/Managed/Stellar.Core/EntryPoints/RunContext.cs b/Core/src/Managed/Stellar.Core/EntryPoints/RunContext.cs index 5666aef..926b167 100644 --- a/Core/src/Managed/Stellar.Core/EntryPoints/RunContext.cs +++ b/Core/src/Managed/Stellar.Core/EntryPoints/RunContext.cs @@ -1,5 +1,5 @@ using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.LoggingSystem; using Stellar.Kernel.Quantization; diff --git a/Core/src/Managed/Stellar.Core/Failures/FailureSystem.cs b/Core/src/Managed/Stellar.Core/Failures/FailureSystem.cs index 786dd0a..8f5643a 100644 --- a/Core/src/Managed/Stellar.Core/Failures/FailureSystem.cs +++ b/Core/src/Managed/Stellar.Core/Failures/FailureSystem.cs @@ -3,7 +3,7 @@ using Stellar.Core.Quantization; using Stellar.Kernel.Data.Catalog; using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.LoggingSystem; diff --git a/Core/src/Managed/Stellar.Core/Global/CoreEngine.cs b/Core/src/Managed/Stellar.Core/Global/CoreEngine.cs index 6e2f04a..03f28ce 100644 --- a/Core/src/Managed/Stellar.Core/Global/CoreEngine.cs +++ b/Core/src/Managed/Stellar.Core/Global/CoreEngine.cs @@ -5,7 +5,7 @@ using Stellar.Core.Services; using Stellar.Kernel.Data.Collections; using Stellar.Kernel.Data.Registry; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.LoggingSystem; using Stellar.Kernel.Quantization; @@ -106,6 +106,7 @@ public static CoreEngine For(IEngineInstance engine) /// Whether it had one. public static bool Release(IEngineInstance engine) { + // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract if (engine is null || !Engines.TryGetValue(engine, out var core)) return false; Engines.Remove(engine); diff --git a/Core/src/Managed/Stellar.Core/Global/Engine.cs b/Core/src/Managed/Stellar.Core/Global/Engine.cs index 3fba677..8910f3b 100644 --- a/Core/src/Managed/Stellar.Core/Global/Engine.cs +++ b/Core/src/Managed/Stellar.Core/Global/Engine.cs @@ -1,6 +1,6 @@ using Stellar.Kernel.Data.Collections; using Stellar.Kernel.Data.Registry; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.LoggingSystem; using Stellar.Kernel.Quantization; using Stellar.Kernel.Services; diff --git a/Core/tests/Managed/Stellar.Core.Tests/FailureTests.cs b/Core/tests/Managed/Stellar.Core.Tests/FailureTests.cs index 31dace3..9e5c475 100644 --- a/Core/tests/Managed/Stellar.Core.Tests/FailureTests.cs +++ b/Core/tests/Managed/Stellar.Core.Tests/FailureTests.cs @@ -3,7 +3,7 @@ using Stellar.Core.Global; using Stellar.Kernel.Configuration; using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.FileSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.LoggingSystem; @@ -32,7 +32,11 @@ private sealed class RecordingLogger : ILogger public void LogWithoutFormat(string message) => Lines.Add((LogLevel.Info, message)); - public void Dispose() + public void Start() + { + } + + public void Stop() { } } diff --git a/Docs/Architecture/Sdk.md b/Docs/Architecture/Sdk.md index dfc7081..537af99 100644 --- a/Docs/Architecture/Sdk.md +++ b/Docs/Architecture/Sdk.md @@ -26,7 +26,7 @@ them, but Rider shows an item written in a project file as a file of the project The SDK version is pinned once, in `global.json`, not in every project: ```json -{ "msbuild-sdks": { "Stellar.Sdk": "0.4.0" } } +{ "msbuild-sdks": { "Stellar.Sdk": "0.4.1" } } ``` The SDK itself comes from the local feed through `NuGet.config`. `stellar project new` and `stellar modules new` diff --git a/Docs/Engine/Modules.md b/Docs/Engine/Modules.md index 5a78e12..957f2a3 100644 --- a/Docs/Engine/Modules.md +++ b/Docs/Engine/Modules.md @@ -35,6 +35,9 @@ stellar modules add ../Stellar.Logging It is then part of the installation exactly like a folder of `modules/`, and gets a `NuGet.config` pointing at the local feed if it has none. +A game's own libraries are modules too, of the solution of the game and not of the installation: see +[Modules of a solution](../Formats/SolutionFile.md#modules-of-a-solution). + ## What a module project gets The project of a module is nearly empty: diff --git a/Docs/Formats/SolutionFile.md b/Docs/Formats/SolutionFile.md index 7ec2065..0e9e69d 100644 --- a/Docs/Formats/SolutionFile.md +++ b/Docs/Formats/SolutionFile.md @@ -55,7 +55,34 @@ referenced project only from the solution, so with `Sources` the projects of the wrapper) go to the solution folder `Engine` and the modules of the installation to `Modules`, built by Debug only. `stellar solution sync` also adds a project you made in the directory of the solution, or a module you started to -depend on. It writes the `.sln` from scratch: solution folders made by hand in the IDE are not kept. +depend on. It writes the `.sln` from scratch: solution folders made by hand in the IDE are not kept. It first writes +the catalog of the [modules of the solution](#modules-of-a-solution), since the references of the projects are read with it. + +## Modules of a solution + +A game keeps its own libraries (the code of a level, a tool, a game system) as modules, which follow the rules of the +engine: a folder with a [`.stellar.module`](ModuleDescriptor.md) file, `"Level": "EndPoint"` (a custom module, +`StellarSdkUsage` `Module`), depending on modules of lower levels, the engine's included. + +```text +Demo/ +├── Demo.stellar.solution +├── Demo/ the game: Stellar.FileSystem;DemoLib +└── DemoLib/ + ├── DemoLib.stellar.module { "Id": "DemoLib", "Level": "EndPoint", "Dependencies": ["Stellar.FileSystem"] } + └── DemoLib.csproj the project: src/Managed/DemoLib/DemoLib.csproj works too +``` + +`stellar solution sync` finds the modules below the directory of the solution (up to three levels, a module ends +the search), and those in `Modules` (folders relative to the solution, for libraries kept elsewhere). It writes them into +`.stellar/stellar.modules.props`, a catalog of the format of the installation's, which the SDK finds from any project +below the solution and imports after the catalog of the installation. From then on the game names `DemoLib` like any +module: the SDK references it, the runtime configuration lists it, and the runtime loads it in a context of its own +after its dependencies and starts its entry point. + +A module of a solution is always taken as sources, in every configuration: it is never packed. Its id must not be one of +the installation, and it cannot depend on another module of its own level. Run `stellar solution sync` again after +adding a module or changing a descriptor. ## `Run` diff --git a/Docs/Migration-0.10.md b/Docs/Migration-0.10.md new file mode 100644 index 0000000..09d3a52 --- /dev/null +++ b/Docs/Migration-0.10.md @@ -0,0 +1,94 @@ +# Migrating to 0.10 + +- [README.md](https://github.com/QuantumDevTeam/StellarEngine-Core#readme) + +What changed for the code that uses the core, from 0.9. The release is small: the failure system got a name of its +own, the logger got its contracts, and the SDK learned the modules of a game. + +| Component | 0.9 | 0.10 | Why | +|---|---|---|---| +| Orchester, Kernel, Core, Runtime | 0.9.0 | 0.10.0 | Breaking: the namespace of the failure system, and `ILogger` | +| Stellar.Sdk | 0.4.0 | 0.4.1 | Compatible: the modules of a solution | +| Stellar.Tools | 0.3.1 | 0.3.2 | Compatible | +| `stellar` (CLI) | 0.2.2 | 0.2.3 | Compatible | +| P/Invoke exports | 3.1 | 3.1 | Nothing changed in the native part | + +Every component has a version of its own: a breaking change raises the second number of that component, and only of +the components it breaks. The orchestra takes the second number when any of its components does. + +## Where `global.json` points + +A project pins `Stellar.Sdk` in its `global.json`, and the local feed holds the version of the installation only, so +after installing 0.10 every pin of `0.4.0` fails to restore. Change it to `0.4.1`: + +```json +{ "msbuild-sdks": { "Stellar.Sdk": "0.4.1" } } +``` + +`stellar project new` and `stellar modules new` write the current one. Then build the engine again and install it +(`scripts/build.ps1 -Configuration Release -Install`), so that the packages of the installation are the new ones. + +## Failures + +The types of the failure system moved from `Stellar.Kernel.Failures` to `Stellar.Kernel.FailureSystem`, named after +the system as `Stellar.Kernel.LoggingSystem` is. Nothing else about them changed. + +| Before | Now | +|---|---| +| `using Stellar.Kernel.Failures;` | `using Stellar.Kernel.FailureSystem;` | +| `Stellar.Kernel.Failures.Catcher`, `Failure`, `FailureException`, `FailureKind`, `FailureLevel`, `FailureReaction`, `IFailureSystem` | the same names in `Stellar.Kernel.FailureSystem` | + +The public members of Stellar.Core and Stellar.Runtime that mention them (`Engine.Failures`, `IRunContext.Failures`, +`IEngineControl.RequestStop(reason, Failure)`, `RuntimeCatchers`) keep their names: only the types they use moved, so a +module needs the new `using` and a rebuild. A module built against 0.9 does not load against 0.10. + +## Logging + +`Stellar.Kernel.LoggingSystem` has its contracts. The logging itself is a module; the Kernel says what it implements. + +| Before | Now | +|---|---| +| `ILogger : IRegistrableQuant` | `ILogger : IQuant`: a logger is found by its identifier, in a catalog, and is not put into a registry | +| `ILogger`: `Log`, `LogWithoutFormat` | the same, and `Start()`, `Stop()`: a logger can be switched on and off | +| nothing | `ILoggerCatalog : ICatalog`, with `AddLogger`, `GetLogger(identifier)`, `PopLogger(identifier)` | +| nothing | `BaseLogger` (for `net` only): one logger that writes into every logger of the `ILoggerCatalog` of the current engine | +| nothing | `LoggerExtensions`: `Info`, `Debug`, `Success`, `Warning`, `Error`, `Exception(message, exception)`, `Separator` | +| nothing | `LogFormat(Format, ColorizedFormat)` | + +A logger of a module is added to the catalog when the module starts and taken out when it stops: + +```csharp +public override int Run(ref readonly TContext context) +{ + _catalog = context.Services?.Find(); + _catalog?.AddLogger(_logger); + return 0; +} + +public override void RequestStop(ref readonly TContext context) => _catalog?.PopLogger(_logger.UID); +``` + +The catalog is published by the logging module. Without one `Find()` is `null`, and `BaseLogger` has +nobody to write to. A class that implemented `ILogger` implements `Start` and `Stop` now. + +## Modules of a solution + +A game keeps its own libraries as modules, and the game names them in `StellarDependencies` like any module of the +engine: a folder with `.stellar.module` (`"Level": "EndPoint"`), found below the solution or listed in `Modules` of +`.stellar.solution`. `stellar solution sync` writes them into `.stellar/stellar.modules.props`, which the SDK imports +after the catalog of the installation. They are always taken as sources, and are loaded by the runtime in a context of +their own after their dependencies. See [`.stellar.solution`](Formats/SolutionFile.md#modules-of-a-solution). + +| Before | Now | +|---|---| +| a library of a game as a plain `ProjectReference`: it compiles, but the runtime never loads it as a module | a module of the solution, named in `StellarDependencies` | +| `Unknown Stellar modules: X` for a library beside the game | the same message, which now also says to run `stellar solution sync` | + +The rest, for those who work on the tools: + +- `StellarSolutionModuleCatalog` (the property) is found from any project below the solution; `StellarUseSolutionModuleCatalog=false` + turns it off. +- The catalog gives every module two properties, `StellarModuleCatalogFile` and `StellarModuleSyncCommand`, so that + STLRB102 checks a descriptor against the catalog it is in and names the command that writes it. +- `ModuleSource.Solution`, `ModuleDiscovery.Discover(directories, depth)`, `ModuleCatalogGenerator.Render(modules, origin)` + and `SolutionModules` in `Stellar.Tools`. The search for modules skips `bin` and `obj`. diff --git a/Docs/Reference/Sdk.Properties.md b/Docs/Reference/Sdk.Properties.md index 355e32e..b4dcccf 100644 --- a/Docs/Reference/Sdk.Properties.md +++ b/Docs/Reference/Sdk.Properties.md @@ -32,6 +32,7 @@ The project wins over `config/`, `config/` over the defaults. | `StellarUseArtifactsOutput` | `true` on the engine side, `false` for games | `false`: the plain `bin/` and `obj/` next to the project | | `StellarArtifactsName` | `$(MSBuildProjectName)` | The folder of the project in `artifacts/bin` and `artifacts/obj` | | `StellarModuleCatalog` | `$(StellarRoot)manifests/.generated/stellar.modules.props` | The catalog of modules | +| `StellarSolutionModuleCatalog` | `.stellar/stellar.modules.props` of the solution above the project, if there is one | The catalog of the modules of the solution, imported after `StellarModuleCatalog`. `StellarUseSolutionModuleCatalog=false` finds none | | `StellarUseModuleCatalog` | `true` | `false`: only the modules of the core exist | | `StellarUseLocalFeed` | `true` | `false`: the local feed is not added to restore | | `StellarImportCustomizations` | `true` | `false`: `config/` of the installation is not imported | diff --git a/Docs/index.md b/Docs/index.md index 0f41a35..e962b5b 100644 --- a/Docs/index.md +++ b/Docs/index.md @@ -41,5 +41,6 @@ The JSON schemas of these files are published here, under [`/schemas/`](https:// - [API reference](xref:Stellar.Kernel), generated from the code of `Stellar.Kernel`, `Stellar.Core`, `Stellar.Runtime` and `Stellar.Tools` - [SDK properties and items](Reference/Sdk.Properties.md) - [Diagnostics](Reference/Diagnostics.md) +- [Migrating to 0.10](Migration-0.10.md) - [Migrating to 0.9](Migration-0.9.md) - [Migrating to 0.8](Migration-0.8.md) diff --git a/Docs/toc.yml b/Docs/toc.yml index bca823b..97adea3 100644 --- a/Docs/toc.yml +++ b/Docs/toc.yml @@ -36,6 +36,8 @@ href: Reference/Sdk.Properties.md - name: Diagnostics href: Reference/Diagnostics.md + - name: Migrating to 0.10 + href: Migration-0.10.md - name: Migrating to 0.9 href: Migration-0.9.md - name: Migrating to 0.8 diff --git a/Kernel/src/Managed/Stellar.Kernel/EntryPoint/IRunContext.cs b/Kernel/src/Managed/Stellar.Kernel/EntryPoint/IRunContext.cs index d869448..ce1e29a 100644 --- a/Kernel/src/Managed/Stellar.Kernel/EntryPoint/IRunContext.cs +++ b/Kernel/src/Managed/Stellar.Kernel/EntryPoint/IRunContext.cs @@ -1,5 +1,5 @@ using Stellar.Kernel.Data.Context; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.LoggingSystem; using Stellar.Kernel.Services; diff --git a/Kernel/src/Managed/Stellar.Kernel/Failures/Catcher.cs b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/Catcher.cs similarity index 99% rename from Kernel/src/Managed/Stellar.Kernel/Failures/Catcher.cs rename to Kernel/src/Managed/Stellar.Kernel/FailureSystem/Catcher.cs index 8c8ee03..fae75b4 100644 --- a/Kernel/src/Managed/Stellar.Kernel/Failures/Catcher.cs +++ b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/Catcher.cs @@ -8,7 +8,7 @@ using Stellar.Kernel.Quantization; using Stellar.Kernel.Services; -namespace Stellar.Kernel.Failures; +namespace Stellar.Kernel.FailureSystem; /// /// Catches failures around suspicious calls, reports them, and lets the work go on, or stops it, as the reaction says. diff --git a/Kernel/src/Managed/Stellar.Kernel/Failures/Failure.cs b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/Failure.cs similarity index 99% rename from Kernel/src/Managed/Stellar.Kernel/Failures/Failure.cs rename to Kernel/src/Managed/Stellar.Kernel/FailureSystem/Failure.cs index d8f0a02..0339414 100644 --- a/Kernel/src/Managed/Stellar.Kernel/Failures/Failure.cs +++ b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/Failure.cs @@ -3,7 +3,7 @@ using Stellar.Kernel.Lifecycle; using Stellar.Kernel.Quantization; -namespace Stellar.Kernel.Failures; +namespace Stellar.Kernel.FailureSystem; /// /// A failure of the engine: what went wrong, where, how seriously, and what was done about it. diff --git a/Kernel/src/Managed/Stellar.Kernel/Failures/FailureException.cs b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/FailureException.cs similarity index 97% rename from Kernel/src/Managed/Stellar.Kernel/Failures/FailureException.cs rename to Kernel/src/Managed/Stellar.Kernel/FailureSystem/FailureException.cs index c936d3f..8ae35db 100644 --- a/Kernel/src/Managed/Stellar.Kernel/Failures/FailureException.cs +++ b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/FailureException.cs @@ -1,6 +1,6 @@ using System; -namespace Stellar.Kernel.Failures; +namespace Stellar.Kernel.FailureSystem; /// /// An exception of the engine: it carries its . diff --git a/Kernel/src/Managed/Stellar.Kernel/Failures/FailureKind.cs b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/FailureKind.cs similarity index 98% rename from Kernel/src/Managed/Stellar.Kernel/Failures/FailureKind.cs rename to Kernel/src/Managed/Stellar.Kernel/FailureSystem/FailureKind.cs index ce7266d..bbcb063 100644 --- a/Kernel/src/Managed/Stellar.Kernel/Failures/FailureKind.cs +++ b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/FailureKind.cs @@ -1,6 +1,6 @@ using System; -namespace Stellar.Kernel.Failures; +namespace Stellar.Kernel.FailureSystem; /// /// Where a failure comes from: the engine, a module, the file system, an audio module of a game. diff --git a/Kernel/src/Managed/Stellar.Kernel/Failures/FailureLevel.cs b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/FailureLevel.cs similarity index 98% rename from Kernel/src/Managed/Stellar.Kernel/Failures/FailureLevel.cs rename to Kernel/src/Managed/Stellar.Kernel/FailureSystem/FailureLevel.cs index 3085862..07370f0 100644 --- a/Kernel/src/Managed/Stellar.Kernel/Failures/FailureLevel.cs +++ b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/FailureLevel.cs @@ -1,6 +1,6 @@ using System; -namespace Stellar.Kernel.Failures; +namespace Stellar.Kernel.FailureSystem; /// /// How serious a failure is: a fixed scale, from the least to the most serious, so levels compare. diff --git a/Kernel/src/Managed/Stellar.Kernel/Failures/IFailureSystem.cs b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/IFailureSystem.cs similarity index 98% rename from Kernel/src/Managed/Stellar.Kernel/Failures/IFailureSystem.cs rename to Kernel/src/Managed/Stellar.Kernel/FailureSystem/IFailureSystem.cs index 9603310..687c9e0 100644 --- a/Kernel/src/Managed/Stellar.Kernel/Failures/IFailureSystem.cs +++ b/Kernel/src/Managed/Stellar.Kernel/FailureSystem/IFailureSystem.cs @@ -2,7 +2,7 @@ using Stellar.Kernel.Data.Catalog; using Stellar.Kernel.Quantization; -namespace Stellar.Kernel.Failures; +namespace Stellar.Kernel.FailureSystem; /// /// The failures of one engine: what is done about them, and who hears of them. diff --git a/Kernel/src/Managed/Stellar.Kernel/FileSystem/DomainNotFoundException.cs b/Kernel/src/Managed/Stellar.Kernel/FileSystem/DomainNotFoundException.cs index e70eb5b..78bb957 100644 --- a/Kernel/src/Managed/Stellar.Kernel/FileSystem/DomainNotFoundException.cs +++ b/Kernel/src/Managed/Stellar.Kernel/FileSystem/DomainNotFoundException.cs @@ -1,4 +1,4 @@ -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; namespace Stellar.Kernel.FileSystem; diff --git a/Kernel/src/Managed/Stellar.Kernel/Lifecycle/IEngineControl.cs b/Kernel/src/Managed/Stellar.Kernel/Lifecycle/IEngineControl.cs index 3f4409e..8073b3d 100644 --- a/Kernel/src/Managed/Stellar.Kernel/Lifecycle/IEngineControl.cs +++ b/Kernel/src/Managed/Stellar.Kernel/Lifecycle/IEngineControl.cs @@ -1,5 +1,5 @@ using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Quantization; namespace Stellar.Kernel.Lifecycle; diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/BaseLogger.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/BaseLogger.cs new file mode 100644 index 0000000..d168d74 --- /dev/null +++ b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/BaseLogger.cs @@ -0,0 +1,81 @@ +#if NET +using System.Collections.Generic; +using Stellar.Kernel.Lifecycle; +using Stellar.Kernel.Quantization; +using Stellar.Kernel.Services; + +namespace Stellar.Kernel.LoggingSystem; + +/// +/// TODO: summary +/// +public sealed class BaseLogger + : ILogger +{ + /// + /// TODO: summary + /// + public static readonly Identifier BaseLoggerIdentifier = Identifier.New(); + + private sealed class BaseLoggerMeta + : IMetaQuant + { + /// + public Identifier UID => BaseLoggerIdentifier; + + /// + /// TODO: summary + /// + public bool IsActive = true; + } + + /// + public Identifier UID => BaseLoggerIdentifier; + + /// + public IMetaQuant Meta { get; } = new BaseLoggerMeta(); + + /// + public IReadOnlyList Metas { get; } = []; + + /// + public TMeta? FindMeta() where TMeta : class, IMetaQuant => + typeof(TMeta) == typeof(BaseLoggerMeta) + ? (TMeta)Meta + : null; + + /// + public void Log(LogLevel level, string message) + { + if (!((BaseLoggerMeta)Meta).IsActive) return; + foreach (var logger in EngineScope.Current?.Services?.Get().Values ?? []) // todo: может упасть, если сервиса нету + { + logger.Log(level, message); + } + } + + /// + public void LogWithoutFormat(string message) + { + if (!((BaseLoggerMeta)Meta).IsActive) return; + foreach (var logger in EngineScope.Current?.Services?.Get().Values ?? []) + { + logger.LogWithoutFormat(message); + } + } + + /// + public void Start() + { + ((BaseLoggerMeta)Meta).IsActive = true; + this.Debug($"Logging started. logger: {UID}"); + } + + /// + public void Stop() + { + ((BaseLoggerMeta)Meta).IsActive = false; + this.Debug($"Logging finished. logger: {UID}"); + } +} +#endif diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILogger.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILogger.cs index c7510f6..8018b26 100644 --- a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILogger.cs +++ b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILogger.cs @@ -6,7 +6,7 @@ namespace Stellar.Kernel.LoggingSystem; /// Engine logger /// public interface ILogger - : IRegistrableQuant + : IQuant { /// /// Create log with formatting @@ -20,4 +20,14 @@ public interface ILogger /// /// just message to write void LogWithoutFormat(string message); + + /// + /// TODO: summary + /// + void Start(); + + /// + /// TODO: summary + /// + void Stop(); } diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILoggerCatalog.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILoggerCatalog.cs new file mode 100644 index 0000000..95434a6 --- /dev/null +++ b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILoggerCatalog.cs @@ -0,0 +1,25 @@ +using Stellar.Kernel.Data.Catalog; + +namespace Stellar.Kernel.LoggingSystem; + +/// +/// TODO: summary +/// +public interface ILoggerCatalog + : ICatalog +{ + /// + /// TODO: summary + /// + void AddLogger(ILogger logger); + + /// + /// TODO: summary + /// + ILogger? GetLogger(Identifier identifier); + + /// + /// TODO: summary + /// + ILogger? PopLogger(Identifier identifier); +} diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogFormat.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogFormat.cs new file mode 100644 index 0000000..44cac79 --- /dev/null +++ b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogFormat.cs @@ -0,0 +1,6 @@ +namespace Stellar.Kernel.LoggingSystem; + +/// +/// TODO: summary +/// +public record struct LogFormat(string Format, string? ColorizedFormat = null); diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LoggerExtensions.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LoggerExtensions.cs new file mode 100644 index 0000000..9b75f0e --- /dev/null +++ b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LoggerExtensions.cs @@ -0,0 +1,70 @@ +#if NET +using System; + +namespace Stellar.Kernel.LoggingSystem; + +/// +/// TODO: summary +/// +public static class LoggerExtensions +{ + /// + /// TODO: summary + /// + public static void Info(this ILogger logger, string message) + { + logger.Log(LogLevel.Info, message); + } + + /// + /// TODO: summary + /// + public static void Debug(this ILogger logger, string message) + { + logger.Log(LogLevel.Debug, message); + } + + /// + /// TODO: summary + /// + public static void Success(this ILogger logger, string message) + { + logger.Log(LogLevel.Success, message); + } + + /// + /// TODO: summary + /// + public static void Warning(this ILogger logger, string message) + { + logger.Log(LogLevel.Warning, message); + } + + /// + /// TODO: summary + /// + public static void Error(this ILogger logger, string message) + { + logger.Log(LogLevel.Error, message); + } + + /// + /// TODO: summary + /// + public static void Exception(this ILogger logger, string message, Exception exception) + { + logger.Log(LogLevel.Exception, + $"{message}\n" + + $"{exception}\n" + + $"{exception.GetType()}: {exception.Message}"); + } + + /// + /// TODO: summary + /// + public static void Separator(this ILogger logger) + { + logger.LogWithoutFormat(""); + } +} +#endif diff --git a/Kernel/src/Managed/Stellar.Kernel/Stellar.Kernel.csproj b/Kernel/src/Managed/Stellar.Kernel/Stellar.Kernel.csproj index f1e78ac..3c5ce23 100644 --- a/Kernel/src/Managed/Stellar.Kernel/Stellar.Kernel.csproj +++ b/Kernel/src/Managed/Stellar.Kernel/Stellar.Kernel.csproj @@ -24,7 +24,7 @@ - + diff --git a/README.md b/README.md index e6c5331..b486cca 100644 --- a/README.md +++ b/README.md @@ -141,5 +141,6 @@ Reference: Workflow: - [Contributing](CONTRIBUTING.md), [Git policy](Docs/Engine/GitPolicy.md), [versioning](Docs/Engine/Versioning.md) +- [Migrating to 0.10](Docs/Migration-0.10.md) - [Migrating to 0.9](Docs/Migration-0.9.md) - [Migrating modules to 0.8](Docs/Migration-0.8.md) diff --git a/Runtime/src/Managed/Stellar.Runtime/Failures/RuntimeCatchers.cs b/Runtime/src/Managed/Stellar.Runtime/Failures/RuntimeCatchers.cs index 1083dbd..90796ff 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Failures/RuntimeCatchers.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Failures/RuntimeCatchers.cs @@ -1,4 +1,4 @@ -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Runtime.Diagnostics; namespace Stellar.Runtime.Failures; diff --git a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/Contexts.cs b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/Contexts.cs index 9a903bf..f202208 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/Contexts.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/Contexts.cs @@ -1,5 +1,5 @@ using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.LoggingSystem; using Stellar.Kernel.Quantization; diff --git a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/EngineControl.cs b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/EngineControl.cs index 87579de..bff1707 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/EngineControl.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/EngineControl.cs @@ -1,5 +1,5 @@ using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; namespace Stellar.Runtime.Lifecycle; diff --git a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/ModuleStarter.cs b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/ModuleStarter.cs index 039ec14..92cc1fc 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/ModuleStarter.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/ModuleStarter.cs @@ -2,7 +2,7 @@ using System.Runtime.ExceptionServices; using Stellar.Kernel.Configuration; using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.LoggingSystem; using Stellar.Kernel.Services; diff --git a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/RuntimeContext.cs b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/RuntimeContext.cs index 152d737..bbbdc7e 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/RuntimeContext.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/RuntimeContext.cs @@ -1,5 +1,5 @@ using Stellar.Kernel.Configuration; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.LoggingSystem; using Stellar.Kernel.Quantization; diff --git a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/RuntimePipeline.cs b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/RuntimePipeline.cs index a619741..77f9b3b 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Lifecycle/RuntimePipeline.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Lifecycle/RuntimePipeline.cs @@ -1,4 +1,4 @@ -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.Profiling; diff --git a/Runtime/src/Managed/Stellar.Runtime/Loop/MainLoop.cs b/Runtime/src/Managed/Stellar.Runtime/Loop/MainLoop.cs index 8d76562..8dc05bd 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Loop/MainLoop.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Loop/MainLoop.cs @@ -1,5 +1,5 @@ using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.Profiling; using Stellar.Kernel.Quantization; diff --git a/Runtime/src/Managed/Stellar.Runtime/Loop/MainLoops.cs b/Runtime/src/Managed/Stellar.Runtime/Loop/MainLoops.cs index 07fa0b0..f526699 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Loop/MainLoops.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Loop/MainLoops.cs @@ -1,4 +1,4 @@ -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Runtime.Failures; using Stellar.Runtime.Lifecycle; diff --git a/Runtime/src/Managed/Stellar.Runtime/Threading/MainThreadDispatcher.cs b/Runtime/src/Managed/Stellar.Runtime/Threading/MainThreadDispatcher.cs index 49b4aba..fa58b44 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Threading/MainThreadDispatcher.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Threading/MainThreadDispatcher.cs @@ -1,5 +1,5 @@ -using Stellar.Kernel.Failures; using System.Collections.Concurrent; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Threading; using Stellar.Runtime.Failures; diff --git a/Runtime/src/Managed/Stellar.Runtime/Threading/MainThreadPump.cs b/Runtime/src/Managed/Stellar.Runtime/Threading/MainThreadPump.cs index df15c84..456cc63 100644 --- a/Runtime/src/Managed/Stellar.Runtime/Threading/MainThreadPump.cs +++ b/Runtime/src/Managed/Stellar.Runtime/Threading/MainThreadPump.cs @@ -1,4 +1,4 @@ -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Runtime.Failures; namespace Stellar.Runtime.Threading; diff --git a/Runtime/tests/Fixtures/Stellar.Runtime.Tests.Host/HostEntryPoint.cs b/Runtime/tests/Fixtures/Stellar.Runtime.Tests.Host/HostEntryPoint.cs index 881aef0..7ffb32c 100644 --- a/Runtime/tests/Fixtures/Stellar.Runtime.Tests.Host/HostEntryPoint.cs +++ b/Runtime/tests/Fixtures/Stellar.Runtime.Tests.Host/HostEntryPoint.cs @@ -2,7 +2,7 @@ using Stellar.Kernel.Configuration; using Stellar.Kernel.Data.Catalog; using Stellar.Kernel.EntryPoint; -using Stellar.Kernel.Failures; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.Quantization; using Stellar.Kernel.Services; diff --git a/Runtime/tests/Stellar.Runtime.Tests/MainLoopTests.cs b/Runtime/tests/Stellar.Runtime.Tests/MainLoopTests.cs index 8f843d9..e7d6b27 100644 --- a/Runtime/tests/Stellar.Runtime.Tests/MainLoopTests.cs +++ b/Runtime/tests/Stellar.Runtime.Tests/MainLoopTests.cs @@ -1,6 +1,6 @@ -using Stellar.Kernel.Failures; using Stellar.Kernel; using Stellar.Kernel.EntryPoint; +using Stellar.Kernel.FailureSystem; using Stellar.Kernel.Lifecycle; using Stellar.Kernel.Profiling; using Stellar.Kernel.Quantization; diff --git a/SDK/src/MSBuild/Stellar.Sdk/Sdk/Stellar.Sdk.Catalog.targets b/SDK/src/MSBuild/Stellar.Sdk/Sdk/Stellar.Sdk.Catalog.targets index fefe3f5..eb68c01 100644 --- a/SDK/src/MSBuild/Stellar.Sdk/Sdk/Stellar.Sdk.Catalog.targets +++ b/SDK/src/MSBuild/Stellar.Sdk/Sdk/Stellar.Sdk.Catalog.targets @@ -25,4 +25,8 @@ + + + diff --git a/SDK/src/MSBuild/Stellar.Sdk/Sdk/Stellar.Sdk.Environment.props b/SDK/src/MSBuild/Stellar.Sdk/Sdk/Stellar.Sdk.Environment.props index ad7ecbd..ab48837 100644 --- a/SDK/src/MSBuild/Stellar.Sdk/Sdk/Stellar.Sdk.Environment.props +++ b/SDK/src/MSBuild/Stellar.Sdk/Sdk/Stellar.Sdk.Environment.props @@ -34,6 +34,16 @@ $(StellarRoot)manifests/.generated/stellar.modules.props + + + <_StellarSolutionCatalogAbove>$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', '.stellar/stellar.modules.props')) + $([MSBuild]::EnsureTrailingSlash('$(_StellarSolutionCatalogAbove)')).stellar/stellar.modules.props + + - <_StellarCanCheckCatalog Condition="'$(StellarIsModule)' == 'true' and Exists('$(StellarModuleDescriptorFile)') and Exists('$(StellarModuleCatalog)')">true + + <_StellarCatalogOfModule>$(StellarModuleCatalogFile) + <_StellarCatalogOfModule Condition="'$(_StellarCatalogOfModule)' == ''">$(StellarModuleCatalog) + stellar modules sync + <_StellarCanCheckCatalog Condition="'$(StellarIsModule)' == 'true' and Exists('$(StellarModuleDescriptorFile)') and Exists('$(_StellarCatalogOfModule)')">true <_StellarDescriptorTicks Condition="'$(_StellarCanCheckCatalog)' == 'true'">$([System.IO.File]::GetLastWriteTime('$(StellarModuleDescriptorFile)').Ticks) - <_StellarCatalogTicks Condition="'$(_StellarCanCheckCatalog)' == 'true'">$([System.IO.File]::GetLastWriteTime('$(StellarModuleCatalog)').Ticks) + <_StellarCatalogTicks Condition="'$(_StellarCanCheckCatalog)' == 'true'">$([System.IO.File]::GetLastWriteTime('$(_StellarCatalogOfModule)').Ticks) <_StellarCatalogStale Condition="'$(_StellarCanCheckCatalog)' == 'true' and $(_StellarDescriptorTicks) > $(_StellarCatalogTicks)">true @@ -25,9 +29,9 @@ Text="StellarSdkUsage=EngineCore is Stellar.Core itself. A core system is EngineCoreModule."/> + Text="$(_StellarDescriptorAbove)$(StellarModuleId).stellar.module describes this project, but the module catalog does not know it yet: run 'stellar modules sync' (a module of the installation) or 'stellar solution sync' (a module of a solution)."/> + Text="$(StellarModuleDescriptorFile) changed after the module catalog was generated: run '$(StellarModuleSyncCommand)'."/> -/// stellar solution sync: writes the .sln again, after a project was added or "Engine" switched. +/// stellar solution sync: writes the catalog of the modules of the solution, then the .sln again, after a +/// project or a module was added or "Engine" switched. /// public sealed class SyncSolutionCommand : Command @@ -31,6 +32,9 @@ public override int Execute(CommandContext context, SyncSolutionSettings setting ?? throw new ToolException($"No {StellarSolution.Extension} in {directory} or above it"); var home = StellarInstallation.Locate(); + + // First: the references of the projects are read with this catalog + SolutionModules.Sync(solution, home, ConsoleToolLogger.Instance); var path = solution.Sync(new SolutionGenerator(home.Root, new MSBuildProjectReferenceReader(), ConsoleToolLogger.Instance)); AnsiConsole.MarkupLine($"[green]Solution written:[/] {path.EscapeMarkup()} [grey](engine: {(solution.File.Engine ?? "Packages").EscapeMarkup()})[/]"); diff --git a/SDK/src/Stellar.Tools/Modules/ModuleCatalogGenerator.cs b/SDK/src/Stellar.Tools/Modules/ModuleCatalogGenerator.cs index 9d7cd86..75094a1 100644 --- a/SDK/src/Stellar.Tools/Modules/ModuleCatalogGenerator.cs +++ b/SDK/src/Stellar.Tools/Modules/ModuleCatalogGenerator.cs @@ -27,7 +27,9 @@ public static class ModuleCatalogGenerator /// /// The enabled modules. /// The text of the MSBuild file. - public static string Render(IEnumerable modules) + /// What the file was generated from, for its header. + public static string Render(IEnumerable modules, + string origin = "'stellar modules sync' from the module descriptors and manifests/engine.manifest.json") { var sorted = modules.OrderBy(module => module.Id, System.StringComparer.Ordinal).ToList(); var project = new XElement("Project"); @@ -59,6 +61,9 @@ public static string Render(IEnumerable modules) var group = new XElement("PropertyGroup", new XAttribute("Condition", $"'$(StellarModuleId)' == '{module.Id}'"), new XElement("StellarModuleKnown", "true"), + Fill("StellarModuleCatalogFile", "$(MSBuildThisFileFullPath)"), + Fill("StellarModuleSyncCommand", + module.Source == ModuleSource.Solution ? "stellar solution sync" : "stellar modules sync"), Fill("StellarModuleLevel", module.Descriptor.Level.ToString()), Fill("StellarModuleVersion", module.Descriptor.Version ?? string.Empty), Fill("StellarModuleDependencies", string.Join(";", module.Descriptor.Dependencies)), @@ -81,8 +86,7 @@ public static string Render(IEnumerable modules) } var document = new XDocument( - new XComment( - " Generated by 'stellar modules sync' from the module descriptors and manifests/engine.manifest.json. Do not edit. "), + new XComment($" Generated by {origin}. Do not edit. "), project); return document + "\n"; diff --git a/SDK/src/Stellar.Tools/Modules/ModuleDiscovery.cs b/SDK/src/Stellar.Tools/Modules/ModuleDiscovery.cs index 9fac67a..cf5a412 100644 --- a/SDK/src/Stellar.Tools/Modules/ModuleDiscovery.cs +++ b/SDK/src/Stellar.Tools/Modules/ModuleDiscovery.cs @@ -23,10 +23,21 @@ public static IReadOnlyList Discover(StellarInstallation installation, M if (!settings.Enabled) return new string[0]; + return Discover(settings.Directories.Select(installation.Resolve), settings.Depth); + } + + /// + /// Finds the descriptor files below some folders: the search of an installation, and of a solution. + /// + /// The folders to search; those that do not exist are skipped. + /// How many levels below each folder a module may be. + /// The descriptor files, sorted. + public static IReadOnlyList Discover(IEnumerable directories, int depth) + { var found = new List(); - foreach (var directory in settings.Directories.Select(installation.Resolve).Where(Directory.Exists)) - Search(directory, settings.Depth, found); + foreach (var directory in directories.Where(Directory.Exists)) + Search(directory, depth, found); return found.Distinct().OrderBy(path => path, System.StringComparer.Ordinal).ToList(); } @@ -38,7 +49,11 @@ private static void Search(string directory, int depth, List found) foreach (var child in Directory.GetDirectories(directory).OrderBy(path => path, System.StringComparer.Ordinal)) { - if (Path.GetFileName(child).StartsWith(".")) + var name = Path.GetFileName(child); + + // Hidden folders and build output hold no modules of theirs + if (name.StartsWith(".") || name.Equals("bin", System.StringComparison.OrdinalIgnoreCase) || + name.Equals("obj", System.StringComparison.OrdinalIgnoreCase)) continue; var descriptor = ModuleDescriptorFile.Find(child); diff --git a/SDK/src/Stellar.Tools/Modules/ModuleResolver.cs b/SDK/src/Stellar.Tools/Modules/ModuleResolver.cs index ea86c45..3f11785 100644 --- a/SDK/src/Stellar.Tools/Modules/ModuleResolver.cs +++ b/SDK/src/Stellar.Tools/Modules/ModuleResolver.cs @@ -181,7 +181,7 @@ private static ModuleDescriptor Apply(ModuleDescriptor descriptor, ModuleOverrid return descriptor; } - private static void ApplyConventions(ModuleDescriptor descriptor, string directory) + internal static void ApplyConventions(ModuleDescriptor descriptor, string directory) { descriptor.Version ??= StellarVersions.Engine; descriptor.Project ??= ModuleConventions.FindManagedProject(directory, descriptor.Id) ?? string.Empty; @@ -189,7 +189,7 @@ private static void ApplyConventions(ModuleDescriptor descriptor, string directo descriptor.TestProjects ??= ModuleConventions.FindTestProjects(directory); } - private static ModuleDescriptor Copy(ModuleDescriptor source) + internal static ModuleDescriptor Copy(ModuleDescriptor source) { return new ModuleDescriptor { diff --git a/SDK/src/Stellar.Tools/Modules/ResolvedModule.cs b/SDK/src/Stellar.Tools/Modules/ResolvedModule.cs index 00ac238..6a54baa 100644 --- a/SDK/src/Stellar.Tools/Modules/ResolvedModule.cs +++ b/SDK/src/Stellar.Tools/Modules/ResolvedModule.cs @@ -17,7 +17,10 @@ public enum ModuleSource External, /// Declared by the manifest only: the module exists as a package. - Package + Package, + + /// A module of a solution (level EndPoint), found by stellar solution sync beside the game. + Solution } /// diff --git a/SDK/src/Stellar.Tools/Solutions/SolutionModules.cs b/SDK/src/Stellar.Tools/Solutions/SolutionModules.cs new file mode 100644 index 0000000..61fabf5 --- /dev/null +++ b/SDK/src/Stellar.Tools/Solutions/SolutionModules.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Stellar.Kernel.Configuration.Manifest; +using Stellar.Kernel.Modules; +using Stellar.Tools.Diagnostics; +using Stellar.Tools.Environment; +using Stellar.Tools.Modules; + +namespace Stellar.Tools.Solutions; + +/// +/// The modules of a solution: the libraries of a game, found beside it and put into a catalog of their own, so that +/// the game names them as it names any module of the engine. +/// +/// +/// A module of a solution is a folder with a <Id>.stellar.module file, as everywhere: found below the +/// directory of the solution, or listed in Modules of the .stellar.solution file. It is a custom module, +/// level (StellarSdkUsage Module), and depends only on modules of +/// lower levels, those of the installation included. +/// The catalog is .stellar/stellar.modules.props in the solution, the format of the catalog of the +/// installation. The SDK imports it after that one. Modules of a game are never packed, so they are always taken as +/// sources. +/// +public static class SolutionModules +{ + /// The folder of the generated files of a solution. + public const string CatalogFolder = ".stellar"; + + /// The file name of the catalog. + public const string CatalogFileName = "stellar.modules.props"; + + /// The version of a module whose descriptor has none. + public const string DefaultVersion = "1.0.0"; + + private const int SearchDepth = 3; + + /// + /// Gets the path of the catalog of a solution. + /// + /// The directory of the solution. + /// The path; the file may not exist. + public static string CatalogPath(string solutionDirectory) + { + return Path.Combine(solutionDirectory, CatalogFolder, CatalogFileName); + } + + /// + /// Finds the modules of a solution and checks them against the modules of the installation. + /// + /// The solution. + /// The modules of the installation, which the new ones may depend on. + /// The modules of the solution, sorted by identifier. + /// Thrown if a module breaks the rules. + public static IReadOnlyList Resolve( + StellarSolution solution, IReadOnlyCollection installationModules) + { + var errors = new List(); + var files = new List(ModuleDiscovery.Discover([solution.Directory], SearchDepth)); + + foreach (var entry in solution.File.Modules.Where(entry => !string.IsNullOrWhiteSpace(entry))) + { + var directory = Path.GetFullPath(Path.Combine(solution.Directory, entry)); + var file = ModuleDescriptorFile.Find(directory); + + if (file is null) + errors.Add($"{StellarSolution.Extension}: {entry} has no module descriptor ({directory})"); + else if (!files.Contains(file, StringComparer.OrdinalIgnoreCase)) + files.Add(file); + } + + var modules = new List(); + + foreach (var file in files) + { + ModuleDescriptor descriptor; + try + { + descriptor = ModuleResolver.Copy(ModuleDescriptorFile.Read(file)); + } + catch (ToolException exception) + { + errors.Add(exception.Message); + continue; + } + + var directory = Path.GetDirectoryName(file)!; + + if (descriptor.Level != ModuleLevel.EndPoint) + { + errors.Add($"{descriptor.Id}: a module of a solution is a custom module, level {ModuleLevel.EndPoint}, " + + $"not {descriptor.Level} ({file})"); + continue; + } + + descriptor.Version ??= DefaultVersion; + ModuleResolver.ApplyConventions(descriptor, directory); + + // The core is implicit, as for the modules of the installation + descriptor.Dependencies = descriptor.Dependencies + .Where(dependency => !ModuleResolver.CoreModules.Contains(dependency)).ToArray(); + + var module = new ResolvedModule(descriptor, directory, ModuleSource.Solution, ModuleLink.Sources); + + if (module.ProjectPath is not { } project) + errors.Add($"{descriptor.Id}: no managed project found in {directory}"); + else if (!File.Exists(project)) + errors.Add($"{descriptor.Id}: the project {project} does not exist"); + + modules.Add(module); + } + + if (errors.Count == 0) + { + var graph = ModuleGraph.Analyze(installationModules.Concat(modules).Select(module => module.Descriptor)); + errors.AddRange(graph.Errors); + } + + if (errors.Count != 0) + throw new ToolException( + $"The modules of {solution.Name} are inconsistent:\n {string.Join("\n ", errors)}"); + + return modules.OrderBy(module => module.Id, StringComparer.Ordinal).ToList(); + } + + /// + /// Finds the modules of a solution and writes their catalog; with none, an old catalog is removed. + /// + /// The solution. + /// The installation the modules are built against. + /// The output. + /// The modules of the solution. + /// Thrown if the modules of the installation or the solution break the rules. + public static IReadOnlyList Sync( + StellarSolution solution, StellarInstallation installation, IToolLogger logger) + { + var modules = Resolve(solution, ModuleSynchronizer.Load(installation).LoadOrder); + var path = CatalogPath(solution.Directory); + + if (modules.Count == 0) + { + if (File.Exists(path)) + { + File.Delete(path); + logger.Info($"No modules in {solution.Name}: {path} removed"); + } + + return modules; + } + + var text = ModuleCatalogGenerator.Render(modules, "'stellar solution sync' from the module descriptors of the solution"); + if (FileWriter.WriteAllText(path, text)) + logger.Info($"Module catalog of the solution updated: {modules.Count} module(s), {path}"); + else + logger.Verbose("Module catalog of the solution is up to date"); + + return modules; + } +} diff --git a/SDK/src/Stellar.Tools/Solutions/StellarSolution.cs b/SDK/src/Stellar.Tools/Solutions/StellarSolution.cs index 2abbba5..bd0a88c 100644 --- a/SDK/src/Stellar.Tools/Solutions/StellarSolution.cs +++ b/SDK/src/Stellar.Tools/Solutions/StellarSolution.cs @@ -23,6 +23,12 @@ public sealed class StellarSolutionFile /// Gets or sets how stellar run runs the solution. /// public RunConfiguration? Run { get; set; } + + /// + /// Gets or sets folders of modules of the solution outside its directory, relative to it. The modules below the + /// directory of the solution are found without being listed. + /// + public List Modules { get; set; } = []; } /// diff --git a/SDK/tests/Stellar.Tools.Tests/SolutionModulesTests.cs b/SDK/tests/Stellar.Tools.Tests/SolutionModulesTests.cs new file mode 100644 index 0000000..d579603 --- /dev/null +++ b/SDK/tests/Stellar.Tools.Tests/SolutionModulesTests.cs @@ -0,0 +1,131 @@ +using Stellar.Kernel.Configuration.Manifest; +using Stellar.Kernel.Modules; +using Stellar.Tools.Diagnostics; +using Stellar.Tools.Environment; +using Stellar.Tools.Modules; +using Stellar.Tools.Solutions; + +namespace Stellar.Tools.Tests; + +public class SolutionModulesTests +{ + private static readonly ResolvedModule[] Installed = + [ + new(new ModuleDescriptor { Id = "Stellar.FileSystem", Level = ModuleLevel.CoreModule, Version = "0.9.0" }, + null, ModuleSource.Discovered, ModuleLink.Default) + ]; + + private static StellarSolution Solution(TempDirectory directory, string json = "{}") + { + directory.Write("Game.stellar.solution", json); + return StellarSolution.Find(directory.Path)!; + } + + private static void Module(TempDirectory directory, string folder, string id, string json = "") + { + var body = json.Length == 0 ? string.Empty : ", " + json; + directory.Write($"{folder}/{id}.stellar.module", $$"""{ "Id": "{{id}}", "Level": "EndPoint"{{body}} }"""); + directory.Write($"{folder}/{id}.csproj", ""); + } + + [Fact] + public void AModuleBesideTheGame_IsFound_AsACustomModuleTakenFromSources() + { + using var directory = new TempDirectory(); + directory.Write("Game/Game.csproj", ""); + Module(directory, "GameLib", "GameLib"); + directory.Write("GameLib/bin/Debug/Copy.stellar.module", """{ "Id": "Copy" }"""); + + var module = SolutionModules.Resolve(Solution(directory), Installed).Should().ContainSingle().Subject; + + module.Id.Should().Be("GameLib"); + module.Source.Should().Be(ModuleSource.Solution); + module.Link.Should().Be(ModuleLink.Sources); + module.Descriptor.Version.Should().Be(SolutionModules.DefaultVersion); + module.ProjectPath.Should().EndWith(Path.Combine("GameLib", "GameLib.csproj")); + } + + [Fact] + public void AModuleOutsideTheDirectory_IsFound_WhenTheSolutionListsIt() + { + using var directory = new TempDirectory(); + directory.Write("game/Game.stellar.solution", """{ "Modules": ["../shared/Lib"] }"""); + Module(directory, "shared/Lib", "Lib"); + var solution = StellarSolution.Find(Path.Combine(directory.Path, "game"))!; + + SolutionModules.Resolve(solution, Installed).Select(module => module.Id).Should().Equal("Lib"); + } + + [Fact] + public void AListedFolderWithoutADescriptor_IsAnError() + { + using var directory = new TempDirectory(); + var solution = Solution(directory, """{ "Modules": ["Nothing"] }"""); + Directory.CreateDirectory(Path.Combine(directory.Path, "Nothing")); + + var action = () => SolutionModules.Resolve(solution, Installed); + + action.Should().Throw().WithMessage("*Nothing*no module descriptor*"); + } + + [Fact] + public void AModule_OfAnotherLevel_IsRefused() + { + using var directory = new TempDirectory(); + directory.Write("Lib/Lib.stellar.module", """{ "Id": "Lib", "Level": "HighLevel" }"""); + directory.Write("Lib/Lib.csproj", ""); + + var action = () => SolutionModules.Resolve(Solution(directory), Installed); + + action.Should().Throw().WithMessage("*Lib*EndPoint*HighLevel*"); + } + + [Fact] + public void AModule_MayDependOnAModuleOfTheInstallation_AndTheCoreIsImplicit() + { + using var directory = new TempDirectory(); + Module(directory, "Lib", "Lib", """ "Dependencies": ["Stellar.FileSystem", "Stellar.Kernel", "Stellar.Core"] """); + + var module = SolutionModules.Resolve(Solution(directory), Installed).Single(); + + module.Descriptor.Dependencies.Should().Equal("Stellar.FileSystem"); + } + + [Fact] + public void AnUnknownDependency_AndAnIdOfTheInstallation_AreRefused() + { + using var unknown = new TempDirectory(); + Module(unknown, "Lib", "Lib", """ "Dependencies": ["Nope"] """); + using var twice = new TempDirectory(); + Module(twice, "Lib", "Stellar.FileSystem"); + + var first = () => SolutionModules.Resolve(Solution(unknown), Installed); + var second = () => SolutionModules.Resolve(Solution(twice), Installed); + + first.Should().Throw().WithMessage("*unknown module Nope*"); + second.Should().Throw().WithMessage("*Stellar.FileSystem*twice*"); + } + + [Fact] + public void Sync_WritesTheCatalog_AndRemovesItWhenTheModulesAreGone() + { + using var directory = new TempDirectory(); + var installation = FakeCore.Installed(directory); + directory.Write("game/Game.stellar.solution", "{}"); + Module(directory, "game/GameLib", "GameLib"); + var solution = StellarSolution.Find(Path.Combine(directory.Path, "game"))!; + var catalog = SolutionModules.CatalogPath(solution.Directory); + + SolutionModules.Sync(solution, installation, NullToolLogger.Instance); + + var text = File.ReadAllText(catalog); + text.Should().Contain("Include=\"GameLib\"").And.Contain("LinkMode=\"Sources\"") + .And.Contain("Source=\"Solution\"").And.Contain("Level=\"EndPoint\"") + .And.Contain("stellar solution sync").And.Contain("$(MSBuildThisFileFullPath)"); + + File.Delete(Path.Combine(directory.Path, "game", "GameLib", "GameLib.stellar.module")); + SolutionModules.Sync(solution, installation, NullToolLogger.Instance); + + File.Exists(catalog).Should().BeFalse(); + } +} diff --git a/Shared/Build/Stellar.Versions.props b/Shared/Build/Stellar.Versions.props index 5484547..9ed9d35 100644 --- a/Shared/Build/Stellar.Versions.props +++ b/Shared/Build/Stellar.Versions.props @@ -7,15 +7,15 @@ --> - 0.9.0 + 0.10.0 - 0.9.0 - 0.9.0 - 0.9.0 - 0.3.1 - 0.4.0 - 0.2.2 + 0.10.0 + 0.10.0 + 0.10.0 + 0.3.2 + 0.4.1 + 0.2.3 0.9.0 diff --git a/Shared/Schemas/stellar.solution.schema.json b/Shared/Schemas/stellar.solution.schema.json index 7a34969..5eb9cd4 100644 --- a/Shared/Schemas/stellar.solution.schema.json +++ b/Shared/Schemas/stellar.solution.schema.json @@ -9,6 +9,11 @@ "enum": ["Packages", "Sources"], "description": "How the projects take the engine: its packages (the default), or its sources in Debug, listed in the solution after 'stellar solution sync'" }, + "Modules": { + "type": "array", + "items": { "type": "string" }, + "description": "Folders of modules of the solution outside its directory, relative to it. Modules (folders with an .stellar.module file, level EndPoint) below the directory are found without being listed; 'stellar solution sync' writes them into .stellar/stellar.modules.props" + }, "Run": { "type": "object", "description": "How 'stellar run' runs the solution", diff --git a/global.json b/global.json index 5f68d40..e7a2998 100644 --- a/global.json +++ b/global.json @@ -5,6 +5,6 @@ "allowPrerelease": false }, "msbuild-sdks": { - "Stellar.Sdk": "0.4.0" + "Stellar.Sdk": "0.4.1" } } From e6b96888abc539198adde6ca6d0b80b6ed21b685 Mon Sep 17 00:00:00 2001 From: Timur Shestakov <153988210+MarcT1me@users.noreply.github.com> Date: Sat, 21 Nov 2026 09:04:51 +0700 Subject: [PATCH 3/7] Restrict pull requests to the default branch (#13) * Remove the repository CLA copy; point to the central CLA * Restrict pull requests to the default branch * Close pull requests opened against the mirror --- .github/workflows/close-mirror-prs.yml | 34 +++++++++++++++++++++++ .github/workflows/restrict-master-prs.yml | 9 ++++++ 2 files changed, 43 insertions(+) create mode 100644 .github/workflows/close-mirror-prs.yml create mode 100644 .github/workflows/restrict-master-prs.yml diff --git a/.github/workflows/close-mirror-prs.yml b/.github/workflows/close-mirror-prs.yml new file mode 100644 index 0000000..ded78e9 --- /dev/null +++ b/.github/workflows/close-mirror-prs.yml @@ -0,0 +1,34 @@ +name: Close mirror pull requests + +on: + pull_request_target: + types: [opened, reopened] + +permissions: + pull-requests: write + issues: write + +jobs: + close: + if: vars.STELLAR_MIRROR == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + with: + script: | + const pr = context.payload.pull_request; + if (!pr) return; + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + body: 'This repository is a generated mirror. Please open the change in the component repository instead.', + }); + + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pr.number, + state: 'closed', + }); diff --git a/.github/workflows/restrict-master-prs.yml b/.github/workflows/restrict-master-prs.yml new file mode 100644 index 0000000..b07b852 --- /dev/null +++ b/.github/workflows/restrict-master-prs.yml @@ -0,0 +1,9 @@ +name: Restrict pull requests to the default branch + +on: + pull_request_target: + types: [opened, reopened] + +jobs: + restrict: + uses: QuantumDevTeam/.github/.github/workflows/restrict-master-prs.yml@master From 22ebb5f505339986d90bc8af5738a3a22e6a3fab Mon Sep 17 00:00:00 2001 From: MarcT1me Date: Tue, 24 Nov 2026 22:51:00 +0700 Subject: [PATCH 4/7] [KERNEL] move the logger formats to the contracts and order the log levels --- .../LoggingSystem/BaseLogger.cs | 81 -------- .../LoggingSystem/ILoggerCatalog.cs | 18 +- .../Stellar.Kernel/LoggingSystem/LogFormat.cs | 14 +- .../Stellar.Kernel/LoggingSystem/LogLevel.cs | 16 +- .../LoggingSystem/LoggerFormat.cs | 195 ++++++++++++++++++ 5 files changed, 217 insertions(+), 107 deletions(-) delete mode 100644 Kernel/src/Managed/Stellar.Kernel/LoggingSystem/BaseLogger.cs create mode 100644 Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LoggerFormat.cs diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/BaseLogger.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/BaseLogger.cs deleted file mode 100644 index d168d74..0000000 --- a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/BaseLogger.cs +++ /dev/null @@ -1,81 +0,0 @@ -#if NET -using System.Collections.Generic; -using Stellar.Kernel.Lifecycle; -using Stellar.Kernel.Quantization; -using Stellar.Kernel.Services; - -namespace Stellar.Kernel.LoggingSystem; - -/// -/// TODO: summary -/// -public sealed class BaseLogger - : ILogger -{ - /// - /// TODO: summary - /// - public static readonly Identifier BaseLoggerIdentifier = Identifier.New(); - - private sealed class BaseLoggerMeta - : IMetaQuant - { - /// - public Identifier UID => BaseLoggerIdentifier; - - /// - /// TODO: summary - /// - public bool IsActive = true; - } - - /// - public Identifier UID => BaseLoggerIdentifier; - - /// - public IMetaQuant Meta { get; } = new BaseLoggerMeta(); - - /// - public IReadOnlyList Metas { get; } = []; - - /// - public TMeta? FindMeta() where TMeta : class, IMetaQuant => - typeof(TMeta) == typeof(BaseLoggerMeta) - ? (TMeta)Meta - : null; - - /// - public void Log(LogLevel level, string message) - { - if (!((BaseLoggerMeta)Meta).IsActive) return; - foreach (var logger in EngineScope.Current?.Services?.Get().Values ?? []) // todo: может упасть, если сервиса нету - { - logger.Log(level, message); - } - } - - /// - public void LogWithoutFormat(string message) - { - if (!((BaseLoggerMeta)Meta).IsActive) return; - foreach (var logger in EngineScope.Current?.Services?.Get().Values ?? []) - { - logger.LogWithoutFormat(message); - } - } - - /// - public void Start() - { - ((BaseLoggerMeta)Meta).IsActive = true; - this.Debug($"Logging started. logger: {UID}"); - } - - /// - public void Stop() - { - ((BaseLoggerMeta)Meta).IsActive = false; - this.Debug($"Logging finished. logger: {UID}"); - } -} -#endif diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILoggerCatalog.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILoggerCatalog.cs index 95434a6..690b751 100644 --- a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILoggerCatalog.cs +++ b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/ILoggerCatalog.cs @@ -6,20 +6,4 @@ namespace Stellar.Kernel.LoggingSystem; /// TODO: summary /// public interface ILoggerCatalog - : ICatalog -{ - /// - /// TODO: summary - /// - void AddLogger(ILogger logger); - - /// - /// TODO: summary - /// - ILogger? GetLogger(Identifier identifier); - - /// - /// TODO: summary - /// - ILogger? PopLogger(Identifier identifier); -} + : ICatalog; diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogFormat.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogFormat.cs index 44cac79..b611c6a 100644 --- a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogFormat.cs +++ b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogFormat.cs @@ -1,6 +1,18 @@ namespace Stellar.Kernel.LoggingSystem; /// -/// TODO: summary +/// {0} - date yyyy-MMM-dd
+/// {1} - time HH:mm:ss.fff
+/// {2} - engine clock name
+/// {3} - engine clock time HH:mm:ss.fff
+/// {4} - LogLevel
+/// {5} - Engine instance name
+/// {6} - Logger instance name
+/// {7} - Thread ID
+/// {8} - C# Type name
+/// {9} - C# Method name
+/// {10} - message
///
+/// Format string +/// Colorized Format string (ASCII) public record struct LogFormat(string Format, string? ColorizedFormat = null); diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogLevel.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogLevel.cs index 78f6e54..9957153 100644 --- a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogLevel.cs +++ b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LogLevel.cs @@ -6,32 +6,32 @@ namespace Stellar.Kernel.LoggingSystem; public enum LogLevel { /// - /// Any Information + /// Debug message or information /// - Info, + Debug = 0, /// - /// Debug message or information + /// Any Information /// - Debug, + Info = 1, /// /// Operation succeed /// - Success, + Success = 2, /// /// A Warning /// - Warning, + Warning = 3, /// /// An Error /// - Error, + Error = 4, /// /// An Exception /// - Exception + Exception = 5 } diff --git a/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LoggerFormat.cs b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LoggerFormat.cs new file mode 100644 index 0000000..f83eb4b --- /dev/null +++ b/Kernel/src/Managed/Stellar.Kernel/LoggingSystem/LoggerFormat.cs @@ -0,0 +1,195 @@ +using System; + +namespace Stellar.Kernel.LoggingSystem; + +/// +/// Full logger formats alias +/// +/// Info log format +/// Debug log format +/// Success log format +/// Warning log format +/// Error log format +/// Exception log format +public readonly record struct LoggerFormat( + LogFormat Info, + LogFormat Debug, + LogFormat Success, + LogFormat Warning, + LogFormat Error, + LogFormat Exception) +{ + /// + /// Default Logger format + /// + public static readonly LoggerFormat Default = new( + new() + { + Format = "{0}:{1} | {2}:{3} | {4} | {5}:{6}:{7} : {8}.{9} - {10}", + ColorizedFormat = "\e[32m{0}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{1}\e[0m " + + "\e[31m|\e[0m " + + "\e[32m{2}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{3}\e[0m " + + "\e[31m|\e[0m " + + "\e[1;38m{4}\e[0m " + + "\e[31m|\e[0m " + + "\e[36m{5}\e[0m" + + "\e[31m:\e[0m" + + "\e[36m{6}\e[0m " + + "\e[31m:\e[0m" + + "\e[36m{7}\e[0m " + + "\e[31m:\e[0m " + + "\e[36m{8}\e[0m " + + "\e[31m.\e[0m" + + "\e[36m{9}\e[0m " + + "\e[31m-\e[0m " + + "\e[1;38m{10}\e[0m" + }, + new() + { + Format = "{0}:{1} | {2}:{3} | {4} | {5}:{6}:{7} : {8}.{9} - {10}", + ColorizedFormat = "\e[32m{0}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{1}\e[0m " + + "\e[31m|\e[0m " + + "\e[32m{2}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{3}\e[0m " + + "\e[31m|\e[0m " + + "\e[1;33m{4}\e[0m " + + "\e[31m|\e[0m " + + "\e[36m{5}\e[0m" + + "\e[31m:\e[0m" + + "\e[36m{6}\e[0m " + + "\e[31m:\e[0m" + + "\e[36m{7}\e[0m " + + "\e[31m:\e[0m " + + "\e[36m{8}\e[0m " + + "\e[31m.\e[0m" + + "\e[36m{9}\e[0m " + + "\e[31m-\e[0m " + + "\e[1;33m{10}\e[0m" + }, + new() + { + Format = "{0}:{1} | {2}:{3} | {4} | {5}:{6}:{7} : {8}.{9} - {10}", + ColorizedFormat = "\e[32m{0}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{1}\e[0m " + + "\e[31m|\e[0m " + + "\e[32m{2}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{3}\e[0m " + + "\e[31m|\e[0m " + + "\e[1;32m{4}\e[0m " + + "\e[31m|\e[0m " + + "\e[36m{5}\e[0m" + + "\e[31m:\e[0m" + + "\e[36m{6}\e[0m " + + "\e[31m:\e[0m" + + "\e[36m{7}\e[0m " + + "\e[31m:\e[0m " + + "\e[36m{8}\e[0m " + + "\e[31m.\e[0m" + + "\e[36m{9}\e[0m " + + "\e[31m-\e[0m " + + "\e[1;32m{10}\e[0m" + }, + new() + { + Format = "{0}:{1} | {2}:{3} | {4} | {5}:{6}:{7} : {8}.{9} - {10}", + ColorizedFormat = "\e[32m{0}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{1}\e[0m " + + "\e[31m|\e[0m " + + "\e[32m{2}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{3}\e[0m " + + "\e[31m|\e[0m " + + "\e[1;34m{4}\e[0m " + + "\e[31m|\e[0m " + + "\e[36m{5}\e[0m" + + "\e[31m:\e[0m" + + "\e[36m{6}\e[0m " + + "\e[31m:\e[0m" + + "\e[36m{7}\e[0m " + + "\e[31m:\e[0m " + + "\e[36m{8}\e[0m " + + "\e[31m.\e[0m" + + "\e[36m{9}\e[0m " + + "\e[31m-\e[0m " + + "\e[1;34m{10}\e[0m" + }, + new() + { + Format = "{0}:{1} | {2}:{3} | {4} | {5}:{6}:{7} : {8}.{9} - {10}", + ColorizedFormat = "\e[32m{0}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{1}\e[0m " + + "\e[31m|\e[0m " + + "\e[32m{2}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{3}\e[0m " + + "\e[31m|\e[0m " + + "\e[1;31m{4}\e[0m " + + "\e[31m|\e[0m " + + "\e[36m{5}\e[0m" + + "\e[31m:\e[0m" + + "\e[36m{6}\e[0m" + + "\e[31m:\e[0m" + + "\e[36m{7}\e[0m " + + "\e[31m:\e[0m " + + "\e[36m{8}\e[0m " + + "\e[31m.\e[0m" + + "\e[36m{9}\e[0m " + + "\e[31m-\e[0m " + + "\e[1;38m{10}\e[0m" + }, + new() + { + Format = "{0}:{1} | {2}:{3} | {4} | {5}:{6}:{7} : {8}.{9} - {10}", + ColorizedFormat = "\e[32m{0}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{1}\e[0m " + + "\e[31m|\e[0m " + + "\e[32m{2}\e[0m" + + "\e[31m:\e[0m" + + "\e[2;32m{3}\e[0m " + + "\e[31m|\e[0m " + + "\e[1;31m{4}\e[0m " + + "\e[31m|\e[0m " + + "\e[36m{5}\e[0m" + + "\e[31m:\e[0m" + + "\e[36m{6}\e[0m " + + "\e[31m:\e[0m" + + "\e[36m{7}\e[0m " + + "\e[31m:\e[0m " + + "\e[36m{8}\e[0m " + + "\e[31m.\e[0m" + + "\e[36m{9}\e[0m " + + "\e[31m-\e[0m " + + "\e[1;31m{10}\e[0m" + } + ); + + /// + /// Gets LogFormat for a LogLevel + /// + /// Log level + /// a LogFormat for given LogLevel + /// if LogLevel is out of LogLevel enum + public LogFormat ForLevel(LogLevel level) => level switch + { + LogLevel.Info => Info, + LogLevel.Debug => Debug, + LogLevel.Success => Success, + LogLevel.Warning => Warning, + LogLevel.Error => Error, + LogLevel.Exception => Exception, + _ => throw new ArgumentException("LoggerFormat.ForLevel operate only levels writen in LogLevel enum", + nameof(level), null) + }; +} From 4efe298864c9ac860f607d78bd4c3679d31fe092 Mon Sep 17 00:00:00 2001 From: MarcT1me Date: Tue, 24 Nov 2026 22:51:55 +0700 Subject: [PATCH 5/7] [DOCS] describe the logger contracts and git in an installation --- Docs/Engine/PostInstallSetup.md | 58 +++++++++++++++++++++++++++++++++ Docs/Engine/toc.yml | 2 ++ Docs/Migration-0.10.md | 17 +++++----- 3 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 Docs/Engine/PostInstallSetup.md diff --git a/Docs/Engine/PostInstallSetup.md b/Docs/Engine/PostInstallSetup.md new file mode 100644 index 0000000..b02eb18 --- /dev/null +++ b/Docs/Engine/PostInstallSetup.md @@ -0,0 +1,58 @@ +# Setting up the machine after the install + +- [README.md](../../README.md) + +What to know once the installation stands: how git behaves in a tree of nested repositories. + +## Git in a tree of repositories + +An installation is several repositories in one folder ([Repository](Repository.md)): + +| Folder | Repository | +|---|---| +| `/` | StellarEngine-Core | +| `/modules//` | one repository per module | +| `/tools//` | one repository per tool | + +Git has no idea of this tree. A command acts on the nearest `.git` found going up from the folder it runs in, and the +core ignores `modules/` and `tools/`, so: + +- `git status` in `` never mentions a module, and in a module never mentions the core; +- inside a module the folder is its own repository: its own history, its own branches, its own `origin`; +- `modules/` and `tools/` hold files of their own (`Directory.Build.props`, `README.md`, ...) that `stellar install` + wrote: they belong to no repository. + +Standing in the folder of a module is enough, `git status` there is the status of that module. `-C` is for running a +command in another folder without leaving yours: + +```powershell +git -C modules/Stellar.FileSystem status +``` + +Three checks that tell where you are: + +```powershell +git rev-parse --show-toplevel # the root of the repository the command acts on +git status --short --branch # the branch, whether it follows a remote, what changed +ls -Force # .git is a hidden folder: without -Force PowerShell does not list it +``` + +If `git rev-parse --show-toplevel` fails with "not a git repository", the folder is not inside any repository: a module +that has not been through `git init` yet, or a copy of an installation made without the `.git` folders. + +### A new module needs its repository + +`stellar modules new` creates the files only. A module has a repository of its own once it went through `git init`, +`git remote add origin ` and a first push of its branch; until then it has no history anyone else can see and the +mirror (`scripts/mirror.ps1`) has nothing to take from it. + +### "Dubious ownership" + +Git refuses a repository whose folder belongs to another account than the one running it, which happens to folders +created from an elevated shell or copied from another machine. The refusal names the exact command to run: + +```powershell +git config --global --add safe.directory +``` + +Do it only for folders you trust; there is no need for `*`. diff --git a/Docs/Engine/toc.yml b/Docs/Engine/toc.yml index c47ba0b..50e6efc 100644 --- a/Docs/Engine/toc.yml +++ b/Docs/Engine/toc.yml @@ -10,6 +10,8 @@ href: Modules.md - name: Installation and repositories href: Repository.md +- name: Setting up the machine + href: PostInstallSetup.md - name: Project items: - name: README diff --git a/Docs/Migration-0.10.md b/Docs/Migration-0.10.md index 09d3a52..20c1546 100644 --- a/Docs/Migration-0.10.md +++ b/Docs/Migration-0.10.md @@ -48,12 +48,12 @@ module needs the new `using` and a rebuild. A module built against 0.9 does not | Before | Now | |---|---| -| `ILogger : IRegistrableQuant` | `ILogger : IQuant`: a logger is found by its identifier, in a catalog, and is not put into a registry | +| `ILogger : IRegistrableQuant` | `ILogger : IQuant`: a logger is found by its name, in a catalog, and is not put into a registry | | `ILogger`: `Log`, `LogWithoutFormat` | the same, and `Start()`, `Stop()`: a logger can be switched on and off | -| nothing | `ILoggerCatalog : ICatalog`, with `AddLogger`, `GetLogger(identifier)`, `PopLogger(identifier)` | -| nothing | `BaseLogger` (for `net` only): one logger that writes into every logger of the `ILoggerCatalog` of the current engine | +| nothing | `ILoggerCatalog : ICatalog`: the loggers of an engine by name, with the members of any catalog | | nothing | `LoggerExtensions`: `Info`, `Debug`, `Success`, `Warning`, `Error`, `Exception(message, exception)`, `Separator` | -| nothing | `LogFormat(Format, ColorizedFormat)` | +| `LogLevel`: `Info`, `Debug`, `Success`, `Warning`, `Error`, `Exception` | in the order of severity: `Debug` is 0 and `Info` is 1; the rest keep their values. Rebuild what stores or compares the numbers | +| nothing | `LogFormat(Format, ColorizedFormat)`, and `LoggerFormat`: one `LogFormat` per level (`ForLevel`), with `LoggerFormat.Default` | A logger of a module is added to the catalog when the module starts and taken out when it stops: @@ -61,15 +61,16 @@ A logger of a module is added to the catalog when the module starts and taken ou public override int Run(ref readonly TContext context) { _catalog = context.Services?.Find(); - _catalog?.AddLogger(_logger); + _catalog?.TryAdd(Name, _logger); return 0; } -public override void RequestStop(ref readonly TContext context) => _catalog?.PopLogger(_logger.UID); +public override void RequestStop(ref readonly TContext context) => _catalog?.Remove(Name); ``` -The catalog is published by the logging module. Without one `Find()` is `null`, and `BaseLogger` has -nobody to write to. A class that implemented `ILogger` implements `Start` and `Stop` now. +The catalog is published by the logging module, which also publishes the `ILogger` that writes into every logger of the +catalog. Without one `Find()` is `null`. A class that implemented `ILogger` implements +`Start` and `Stop` now. ## Modules of a solution From fe5dc280f7a3d739f551647fb8068d290c495c46 Mon Sep 17 00:00:00 2001 From: MarcT1me Date: Tue, 24 Nov 2026 22:52:14 +0700 Subject: [PATCH 6/7] [SCRIPTS] [DOCS] push the mirror with a deploy key --- .github/workflows/mirror.yml | 37 ++++++++++++++++++++++++------------ Docs/Engine/Repository.md | 7 ++++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index d23b363..2bacbf0 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -4,14 +4,21 @@ name: Mirror # # The mirror is never worked in: every commit of it is a snapshot made by scripts/mirror.ps1, here or on a machine. # This workflow takes the list of components from the .orchestra file of the last snapshot, clones each at its -# default branch, makes a new snapshot when anything changed, pushes it, and starts the docs workflow (a push made -# with the token of a workflow starts no other workflow by itself). +# default branch, makes a new snapshot when anything changed and pushes it. A push with a deploy key starts the +# workflows of the mirror as any push does: the docs workflow builds the site. # # It lives in the core like everything the mirror holds, but runs only where the repository variable # STELLAR_MIRROR is 'true' (Settings -> Secrets and variables -> Actions -> Variables): in the mirror. # Public components work with the token of the workflow. A component it cannot clone (a private repository) is kept # as the mirror has it; the secret STELLAR_MIRROR_TOKEN (a fine-grained token with read access to their contents) # lets the workflow refresh private ones too. +# +# The rulesets of the mirror let nobody write its branch, and the token of a workflow can neither pass a ruleset nor +# change a file of .github/workflows/, which a snapshot does whenever the core did. So the snapshot is pushed over SSH +# with a deploy key. Set once, in the mirror: +# - Settings -> Deploy keys: the public half, with write access; +# - Settings -> Secrets and variables -> Actions: the private half, as STELLAR_MIRROR_DEPLOY_KEY; +# - Settings -> Rules -> the ruleset of the branch: "Deploy keys" in the bypass list. # The first snapshot comes from a machine: scripts/mirror.ps1 -Push. After that this workflow is the only writer: # on a machine, mirror.ps1 without -Push shows the next snapshot, Run workflow here publishes it. @@ -22,7 +29,6 @@ on: permissions: contents: write - actions: write concurrency: group: mirror @@ -45,7 +51,6 @@ jobs: shell: pwsh env: COMPONENTS_TOKEN: ${{ secrets.STELLAR_MIRROR_TOKEN || github.token }} - MIRROR_TOKEN: ${{ github.token }} run: | if (-not (Test-Path .orchestra)) { throw 'No .orchestra here: make the first snapshot on a machine with scripts/mirror.ps1 -Push' @@ -66,8 +71,6 @@ jobs: } $mirrorRepository = 'https://github.com/${{ github.repository }}' - # The mirror itself is written with the token of this workflow - Set-Credentials $mirrorRepository $env:MIRROR_TOKEN $workspace = Join-Path $env:RUNNER_TEMP 'orchestra' $components = @((Get-Content .orchestra -Raw | ConvertFrom-Json).Components) @@ -97,7 +100,22 @@ jobs: - name: Snapshot and push id: snapshot shell: pwsh + env: + DEPLOY_KEY: ${{ secrets.STELLAR_MIRROR_DEPLOY_KEY }} run: | + if (-not $env:DEPLOY_KEY) { + throw 'No STELLAR_MIRROR_DEPLOY_KEY: the ruleset of the mirror lets only its deploy key write (see the head of mirror.yml)' + } + $ssh = Join-Path $env:RUNNER_TEMP 'mirror-ssh' + New-Item -ItemType Directory $ssh | Out-Null + # LF and a newline at the end, or ssh does not take the key + [System.IO.File]::WriteAllText("$ssh/key", $env:DEPLOY_KEY.Replace("`r", '').Trim() + "`n") + chmod 600 "$ssh/key" + # The host key of github.com (https://api.github.com/meta): never trusted on first use + [System.IO.File]::WriteAllText("$ssh/known_hosts", + "github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl`n") + $env:GIT_SSH_COMMAND = "ssh -i $ssh/key -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$ssh/known_hosts" + $workspace = '${{ steps.workspace.outputs.path }}' $keep = @('${{ steps.workspace.outputs.keep }}' -split ',' | Where-Object { $_ }) @@ -109,7 +127,7 @@ jobs: # Parameters by name (a hashtable): an array splatted into a script binds by position, and '-Tag' once # became the branch of the mirror - $arguments = @{ Remote = 'https://github.com/${{ github.repository }}.git'; Push = $true; Keep = $keep } + $arguments = @{ Remote = 'git@github.com:${{ github.repository }}.git'; Push = $true; Keep = $keep } if ($release) { $arguments.Tag = $tag } & "$workspace/scripts/mirror.ps1" @arguments "release=$($release.ToString().ToLowerInvariant())" >> $env:GITHUB_OUTPUT @@ -150,8 +168,3 @@ jobs: if ($version.Contains('-')) { $flags += '--prerelease' } gh release create '${{ steps.snapshot.outputs.tag }}' --repo '${{ github.repository }}' --verify-tag --title "StellarEngine $version" --notes-file $notesFile @flags if ($LASTEXITCODE -ne 0) { throw 'gh release create failed' } - - - name: Build the site - env: - GH_TOKEN: ${{ github.token }} - run: gh workflow run docs.yml --repo '${{ github.repository }}' --ref master diff --git a/Docs/Engine/Repository.md b/Docs/Engine/Repository.md index 4e6f7eb..7b501c8 100644 --- a/Docs/Engine/Repository.md +++ b/Docs/Engine/Repository.md @@ -194,10 +194,15 @@ A version with a suffix (`0.9.0-rc.1`) is a pre-release, which the installer tak `.github/workflows/mirror.yml` runs in the mirror (where the repository variable `STELLAR_MIRROR` is `true`) every night and on demand: it clones every component the last `.orchestra` names, at its default branch, makes a snapshot -when anything changed, pushes it and starts the docs workflow. A component it cannot clone (a private repository) is +when anything changed and pushes it, which starts the docs workflow. A component it cannot clone (a private repository) is kept as the mirror has it (`scripts/mirror.ps1 -Keep`); the secret `STELLAR_MIRROR_TOKEN` lets it read private ones too. The first snapshot comes from a machine: `scripts/mirror.ps1 -Push`. +The rulesets of the mirror let nobody write its branch, so the workflow pushes over SSH with a deploy key of the +mirror: its private half is the secret `STELLAR_MIRROR_DEPLOY_KEY`, and the ruleset has *Deploy keys* in its bypass +list. The token of a workflow does not do: it passes no ruleset, and cannot change the files of `.github/workflows/`. +A new component gets into `.orchestra` with a snapshot made on a machine that holds the key. + After that the workflow is the only writer of the mirror: on a machine, `scripts/mirror.ps1` without `-Push` shows what the next snapshot would be, and Run workflow publishes it. A snapshot is always made on top of the last one of the mirror; one that cannot read the mirror stops instead of starting a history of its own. From ee0d3584680663945e883e4479f345e91c2f423b Mon Sep 17 00:00:00 2001 From: MarcT1me Date: Tue, 24 Nov 2026 22:52:58 +0700 Subject: [PATCH 7/7] [SCRIPTS] grant the pull request guard its permissions --- .github/workflows/restrict-master-prs.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/restrict-master-prs.yml b/.github/workflows/restrict-master-prs.yml index b07b852..665d43f 100644 --- a/.github/workflows/restrict-master-prs.yml +++ b/.github/workflows/restrict-master-prs.yml @@ -4,6 +4,11 @@ on: pull_request_target: types: [opened, reopened] +permissions: + contents: read + pull-requests: write + issues: write + jobs: restrict: uses: QuantumDevTeam/.github/.github/workflows/restrict-master-prs.yml@master