Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ 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 the token of an app 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 with the
# token of a GitHub App of the organization. Set once:
# - the app: repository permissions Contents and Workflows, read and write; installed on the mirror only;
# - the mirror, Settings -> Secrets and variables -> Actions: the variable STELLAR_MIRROR_APP_ID (its client ID) and
# the secret STELLAR_MIRROR_APP_KEY (its private key);
# - the mirror, Settings -> Rules -> the ruleset of the branch: the app 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.

Expand All @@ -22,7 +30,6 @@ on:

permissions:
contents: write
actions: write

concurrency:
group: mirror
Expand All @@ -40,12 +47,21 @@ jobs:
# Its own credentials would add a second Authorization header to every request to github.com
persist-credentials: false

# Writes the mirror: a token of this job only, for this repository and these two permissions
- name: Token of the mirror app
id: app
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.STELLAR_MIRROR_APP_ID }}
private-key: ${{ secrets.STELLAR_MIRROR_APP_KEY }}
permission-contents: write
permission-workflows: write

- name: Clone the components
id: workspace
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'
Expand All @@ -66,8 +82,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)
Expand Down Expand Up @@ -97,7 +111,15 @@ jobs:
- name: Snapshot and push
id: snapshot
shell: pwsh
env:
MIRROR_TOKEN: ${{ steps.app.outputs.token }}
run: |
# The same form of credentials as for the components: in a header, for both spellings of the repository
$basic = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("x-access-token:$env:MIRROR_TOKEN"))
foreach ($url in 'https://github.com/${{ github.repository }}', 'https://github.com/${{ github.repository }}.git') {
git config --global --replace-all "http.$url.extraheader" "AUTHORIZATION: basic $basic"
}

$workspace = '${{ steps.workspace.outputs.path }}'
$keep = @('${{ steps.workspace.outputs.keep }}' -split ',' | Where-Object { $_ })

Expand Down Expand Up @@ -150,8 +172,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
5 changes: 5 additions & 0 deletions .github/workflows/restrict-master-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Core/src/Managed/Stellar.Core/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Managed/Stellar.Core/EntryPoints/RunContext.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Managed/Stellar.Core/Failures/FailureSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion Core/src/Managed/Stellar.Core/Global/CoreEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,6 +106,7 @@ public static CoreEngine For(IEngineInstance engine)
/// <returns>Whether it had one.</returns>
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);
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Managed/Stellar.Core/Global/Engine.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 6 additions & 2 deletions Core/tests/Managed/Stellar.Core.Tests/FailureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion Docs/Architecture/Sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions Docs/Engine/Modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
58 changes: 58 additions & 0 deletions Docs/Engine/PostInstallSetup.md
Original file line number Diff line number Diff line change
@@ -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 |
|---|---|
| `<root>/` | StellarEngine-Core |
| `<root>/modules/<Module>/` | one repository per module |
| `<root>/tools/<Tool>/` | 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 `<root>` 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 <url>` 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 <path of that folder>
```

Do it only for folders you trust; there is no need for `*`.
6 changes: 5 additions & 1 deletion Docs/Engine/Repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,14 @@ 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 with the token of a GitHub App, installed
on the mirror only and in the bypass list of the ruleset (`STELLAR_MIRROR_APP_ID`, `STELLAR_MIRROR_APP_KEY`). The token
of a workflow does not do: it passes no ruleset, and cannot change the files of `.github/workflows/`.

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.
Expand Down
2 changes: 2 additions & 0 deletions Docs/Engine/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion Docs/Formats/SolutionFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [`<Id>.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: <StellarDependencies>Stellar.FileSystem;DemoLib</StellarDependencies>
└── 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`

Expand Down
Loading