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
112 changes: 86 additions & 26 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
name: Docs

# Builds the documentation site with DocFX and publishes it to GitHub Pages. One workflow, two sites:
# - in StellarEngine-Core: the site of the core (docfx.json): Docs/, the API reference, the schemas, the installer;
# - in the mirror (StellarEngine-Mono), recognized by the .orchestra file scripts/mirror.ps1 puts at its root:
# the site of the orchestra (scripts/orchestra-site.ps1), the core and every module in one site.
# Pull requests and manual runs on other branches only build; the site is deployed from master only.
# Repository setting required once: Settings -> Pages -> Source = "GitHub Actions".
# Publishes the documentation of this repository to GitHub Pages for the Prometheus site (the team site).
# GitHub Pages is only the storage of the site: static files (the installer, the schemas), the documentation as data
# (bundle/) and a small embed that redirects to the site when the site is up.
#
# This file is a thin wrapper and does not need updates: the steps (ci.py, the bundle builder, the embed) are
# downloaded from the site on every run (/docs-kit.zip), so they are always the same version as the site.
# What to build is described by the repository itself in prometheus.json (format prometheus-repo/1, see the DOCS
# page of the site); without it: Docs/ and the API of the projects in docfx.json.
# If the site is down, the static files and a page that leads to the site are published; the next run fixes the rest.
#
# Repository settings:
# Settings -> Pages -> Source = "GitHub Actions" (once)
# Variables (optional): PROMETHEUS_SITE (https://notagood.org by default),
# PROMETHEUS_PROJECT, PROMETHEUS_TITLE (override prometheus.json)
# Secrets (optional): PROMETHEUS_SYNC_KEY an API key of the site with the "sync" scope: the site learns about
# the new build at once instead of on its next check
# Pull requests and manual runs on other branches only build; Pages is deployed from master only.

on:
push:
Expand All @@ -24,49 +35,88 @@ env:
DOCFX_VERSION: '2.81.0'
DOTNET_NOLOGO: 'true'
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
PROMETHEUS_SITE: ${{ vars.PROMETHEUS_SITE || 'https://notagood.org' }}
PROMETHEUS_PROJECT: ${{ vars.PROMETHEUS_PROJECT }}
PROMETHEUS_TITLE: ${{ vars.PROMETHEUS_TITLE }}
OUT: artifacts/pages

jobs:
build:
name: Build site
runs-on: ubuntu-latest
name: Build
runs-on: ubuntu-latest # pwsh, python3 and bash are there: "prepare" scripts may use any of them
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup .NET
if: hashFiles('global.json') != ''
uses: actions/setup-dotnet@v5
with:
global-json-file: global.json

# Installed outside the checkout so the repository NuGet.config (local "packages" feed) is not involved.
- name: Setup .NET (no global.json)
if: hashFiles('global.json') == ''
uses: actions/setup-dotnet@v5
with:
dotnet-version: '9.0.x'

# Installed outside the checkout so a repository NuGet.config (a local feed) is not involved.
- name: Install DocFX
working-directory: ${{ runner.temp }}
run: dotnet tool install docfx --version "$DOCFX_VERSION" --tool-path "$RUNNER_TEMP/docfx"

- name: Choose the site
id: site
shell: pwsh
- name: Prometheus
id: prometheus
continue-on-error: true
run: |
# The local feed of an installation: empty here, but NuGet wants the folder it names to exist
New-Item -ItemType Directory -Force packages | Out-Null
if (Test-Path .orchestra) {
./scripts/orchestra-site.ps1
"config=docfx.orchestra.json" >> $env:GITHUB_OUTPUT
"output=artifacts/docs/orchestra-site" >> $env:GITHUB_OUTPUT
} else {
"config=docfx.json" >> $env:GITHUB_OUTPUT
"output=artifacts/docs/site" >> $env:GITHUB_OUTPUT
}
set -euo pipefail
# NuGet wants the local feed folder of an installation to exist, even empty
mkdir -p packages
curl -fsSL --retry 2 "$PROMETHEUS_SITE/docs-kit.zip" -o "$RUNNER_TEMP/kit.zip"
unzip -q -o "$RUNNER_TEMP/kit.zip" -d "$RUNNER_TEMP/kit"
python3 -m pip install --quiet pyyaml
python3 "$RUNNER_TEMP/kit/ci.py" --out "$OUT" --docfx "$RUNNER_TEMP/docfx/docfx"

# metadata (the API reference from the managed projects), then build
- name: Build documentation
run: '"$RUNNER_TEMP/docfx/docfx" "${{ steps.site.outputs.config }}" --warningsAsErrors'
# The site is down or the build failed: publish the static files and a page that leads to the site.
# Self-contained on purpose (no kit): the installer and the schemas keep their addresses whatever happens.
- name: Fallback
if: steps.prometheus.outcome == 'failure'
run: |
echo "::warning title=Prometheus::The documentation was not built (is $PROMETHEUS_SITE up?); publishing the static files only"
mkdir -p "$OUT" && touch "$OUT/.nojekyll"
python3 - <<'PY'
import glob, html, json, os, re, shutil
out = os.environ["OUT"]
cfg = json.load(open("prometheus.json", encoding="utf-8-sig")) if os.path.isfile("prometheus.json") else {}
static = cfg.get("static") or next((a.get("docfx") if isinstance(a, dict) else a for a in cfg.get("api") or []), None) \
or ("docfx.json" if os.path.isfile("docfx.json") else None)
for config in ([static] if isinstance(static, str) else static or []):
if not os.path.isfile(config):
continue
base = os.path.dirname(os.path.abspath(config))
for r in json.load(open(config, encoding="utf-8-sig")).get("build", {}).get("resource", []):
src, dest = os.path.join(base, r.get("src", "")), os.path.join(out, r.get("dest", ""))
for pattern in r.get("files", []):
for f in glob.glob(os.path.join(src, pattern), recursive=True):
if os.path.isfile(f):
t = os.path.join(dest, os.path.relpath(f, src))
os.makedirs(os.path.dirname(t), exist_ok=True)
shutil.copy2(f, t)
repo = os.environ.get("GITHUB_REPOSITORY", "").rsplit("/", 1)[-1]
project = os.environ.get("PROMETHEUS_PROJECT") or cfg.get("project") or re.sub(r"[^a-z0-9]+", "-", repo.lower()).strip("-")
url = html.escape(f"{os.environ['PROMETHEUS_SITE'].rstrip('/')}/docs/{project}")
title = html.escape(os.environ.get("PROMETHEUS_TITLE") or cfg.get("title") or repo)
with open(os.path.join(out, "index.html"), "w", encoding="utf-8") as f:
f.write(f'<!DOCTYPE html><html><head><meta charset="utf-8"><title>{title}</title>'
f'<meta http-equiv="refresh" content="0; url={url}"></head>'
f'<body><p><a href="{url}">{title} documentation</a></p></body></html>')
PY

- name: Upload Pages artifact
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
uses: actions/upload-pages-artifact@v5
with:
path: ${{ steps.site.outputs.output }}
path: ${{ env.OUT }}

deploy:
name: Deploy to GitHub Pages
Expand All @@ -87,3 +137,13 @@ jobs:
- name: Deploy
id: deployment
uses: actions/deploy-pages@v5

# The site would notice the new bundle on its next check anyway; this makes it immediate.
- name: Nudge the site
continue-on-error: true
env:
KEY: ${{ secrets.PROMETHEUS_SYNC_KEY }}
run: |
if [ -z "$KEY" ]; then echo "::notice::PROMETHEUS_SYNC_KEY is not set: the site picks the docs up on its next check"; exit 0; fi
sleep 30 # Pages needs a moment to serve the new files
curl -fsS -X POST -H "Authorization: Bearer $KEY" "$PROMETHEUS_SITE/api/v1/sync"
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
shell: pwsh
run: |
New-Item -ItemType Directory -Force packages | Out-Null
./scripts/build.ps1 -Configuration Debug -SkipTests -Install -NoUserRegistration
./scripts/build.ps1 -Configuration Debug -SkipTests -Install -NoUserRegistration -SkipModules

- name: Build and test the module
if: env.IS_CORE != 'true'
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
/StellarEngine.*.slnf
# The bare repository scripts/mirror.ps1 builds the snapshots of the orchestra in
/.mirror/
# The DocFX project of the orchestra site, generated by scripts/orchestra-site.ps1
/docfx.orchestra.json

# ---- Build output ----
[Bb]in/
Expand Down
2 changes: 1 addition & 1 deletion Docs/Architecture/NativeAbi.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ The native core follows the handle and umbrella rules of the Kernel:
```

A native project of a module gets the include directories, `STELLAR_KERNEL_STATIC` and the import libraries from
`Shared/Build/Stellar.Native.Module.props` (see [Modules](https://quantumdevteam.github.io/StellarEngine-Mono/guide/Modules.html)); the toolchain itself comes from
`Shared/Build/Stellar.Native.Module.props` (see [Modules](../Engine/Modules.md)); the toolchain itself comes from
`Shared/Build/Stellar.Native.props`, shared with the core. Inside a module, paths start at the root of the module.

Headers of the C++/CLI wrapper end with `.cli.h`: MSVC also searches the folders of the open includes, and a wrapper
Expand Down
2 changes: 1 addition & 1 deletion Docs/Architecture/Sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The SDK itself comes from the local feed through `NuGet.config`. `stellar projec
generate both files; a project under the root of the installation also finds the `NuGet.config` of the root.

A module project needs even less: it is nearly empty, and the SDK takes its kind, version and dependencies from its
descriptor. See [Modules](https://quantumdevteam.github.io/StellarEngine-Mono/guide/Modules.html). Every property: [Sdk.Properties](../Reference/Sdk.Properties.md).
descriptor. See [Modules](../Engine/Modules.md). Every property: [Sdk.Properties](../Reference/Sdk.Properties.md).

## Kinds of projects

Expand Down
2 changes: 1 addition & 1 deletion Docs/Architecture/Tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Later additions win, and anything no compiler claims is packed as is by `RawReso
| `stellar uninstall [path]` | Remove an installation: unregister it, drop its packages from the NuGet cache, remove what the installer made; `--all`, `--artifacts`, `--dry-run` |
| `stellar modules list` | Show the manifest in load order |
| `stellar modules sync` | Find the modules, apply the manifest, check the rules, regenerate the catalog |
| `stellar modules new`, `templates`, `add`, `enable`, `disable`, `reset`, `build` | See [Modules](https://quantumdevteam.github.io/StellarEngine-Mono/guide/Modules.html) |
| `stellar modules new`, `templates`, `add`, `enable`, `disable`, `reset`, `build` | See [Modules](../Engine/Modules.md) |
| `stellar solution sync [directory]` | Write the `.sln` again: the projects of the solution, the engine when `"Engine"` is `Sources` |
| `stellar run [target]` | Build and run a game or a tool of the solution, or several at once; see [`.stellar.solution`](../Formats/SolutionFile.md) |
| `stellar project new <template> <name>` | Create a solution and its project in a folder of its own; `--flat` for the project alone |
Expand Down
2 changes: 1 addition & 1 deletion Docs/Engine/Architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
> It is intended to explain *how the system is structured* and *why it is structured this way*,
> without going into low-level implementation details.

- [README.md](../../README.md)
- [README.md](https://github.com/QuantumDevTeam/StellarEngine-Core#readme)

---

Expand Down
2 changes: 1 addition & 1 deletion Docs/Engine/DesignPhilosophy.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
> It explains *why* the project exists, *how decisions are made*,
> and *what kind of system StellarEngine intentionally aims to be*.

- [README.md](../../README.md)
- [README.md](https://github.com/QuantumDevTeam/StellarEngine-Core#readme)

---

Expand Down
103 changes: 103 additions & 0 deletions Docs/Engine/Documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Writing the documentation

- [README.md](https://github.com/QuantumDevTeam/StellarEngine-Core#readme)

The documentation of the engine is Markdown in the repositories, next to the code it describes. The docs site reads
it; nothing about it is edited on the site.

## Where it is read

Every repository publishes a bundle of its documentation to its GitHub Pages: its `Docs/` and the API reference made
from the XML comments of its code. The docs site shows the bundles, one project each:

| Project | Repository | What |
|---|---|---|
| `stellar-engine` | StellarEngine-Mono, the mirror | the whole engine: the guide (`Docs/Engine` of the core), the core with its API, every module and tool |
| `stellar-core` | StellarEngine-Core | the core alone: `Docs/` without `Docs/Engine`, its API |
| a module or a tool | its own repository | its `Docs/` |

The address of the docs site is set once, in `StellarDocsUri` of `Shared/Build/Stellar.Versions.props`, with the
projects of the core and of the engine next to it. The tools take them from there; Markdown never names the site.
GitHub Pages also keeps the installer and the JSON schemas at the addresses of `StellarSiteUri`.

## What a repository publishes

`prometheus.json` at the root of a repository says what goes into its bundle: the project, its title, where its
version is, the folders of articles, the API, the static files, and where links out of the bundle go.

```json
{
"format": "prometheus-repo/1",
"project": "stellar-filesystem",
"title": "Stellar.FileSystem",
"version": { "file": "Stellar.FileSystem.stellar.module", "regex": "\"Version\"\\s*:\\s*\"([^\"]+)\"" },
"docs": [ { "path": "Docs" } ],
"static": "docfx.json"
}
```

A module gets one from `stellar modules new`. Its `project` is a guess made from the id of the module: it must be the
name of the card of the module on the docs site.

The core does not write its description by hand. Its `prometheus.json` names `scripts/prometheus.ps1`, which the docs
workflow runs first: it writes the description of the core, or, in the mirror, that of the whole engine, with every
module and tool that has a `Docs/toc.yml`. Only this script knows the layout of the engine. To look at what it
writes:

```powershell
powershell -File scripts/prometheus.ps1 -Print
```

The format of `prometheus.json` belongs to the docs site, which documents every field.

## Links

| To | Write | Example |
|---|---|---|
| a page of the same bundle | a relative path to the `.md` file | `[Modules](Modules.md)` |
| a page of the same repository, published by another project | a relative path too; `links` of `prometheus.json` says which project | from `Docs/Architecture/Sdk.md`: `[Modules](../Engine/Modules.md)` |
| a page of another repository | `prometheus:<project>/<page>`, the page being its path in `Docs/` without `.md` | `[the guide](prometheus:stellar-engine/guide/Install)` |
| a file that is not documentation (README, LICENSE) | its address on GitHub | `https://github.com/QuantumDevTeam/StellarEngine-Core#readme` |

Relative links work on GitHub as well as on the site. A `prometheus:` link works on the site only: use it between
repositories, where nothing else can.

Never write the address of the docs site or of GitHub Pages into a page: when the site moves, the pages stay right.

## Checking it on a machine

The builder of the bundle comes from the docs site, in `docs-kit.zip`. A bundle built on a machine shows the broken
links of the pages before a push. In the core, the description is written to a file of its own first, so that
`prometheus.json` of the repository stays as it is:

```powershell
powershell -File scripts/prometheus.ps1 -Output artifacts/prometheus.json
python build_bundle.py --config artifacts/prometheus.json --out artifacts/bundle
```

A module has its description committed: `python build_bundle.py --out artifacts/bundle` in its folder.

The whole run of the workflow, the static files and the embed included, is `ci.py` of the same kit, in the folder of
the repository. It runs the `prepare` script of `prometheus.json` (PowerShell 7, or Windows PowerShell where there is
no other), which writes the description into `artifacts/prometheus/`: `prometheus.json` of the repository stays as it
is.

```powershell
$env:PROMETHEUS_SITE = 'https://notagood.org'
python ci.py --out artifacts/pages --skip-metadata
```

`--skip-metadata` takes the API made before (`docfx metadata docfx.json`); without it, `--docfx` names the `docfx`
to run.

A `warning` line names a link that does not lead anywhere. The docs workflow prints the same lines, and publishes
anyway.

## Publishing

A push to the default branch runs the docs workflow of the repository: it builds the bundle and puts it on GitHub
Pages, and the docs site picks it up within minutes (at once, when the repository has the key of the site). A
release of the mirror makes the new version of the engine appear on the site.

Settings of a repository, once: Settings → Pages → Source = GitHub Actions; the card of the project on the docs site
points at `https://quantumdevteam.github.io/<repository>/bundle/`.
Loading
Loading