Skip to content
NCodeGroupPublic

About

The shared documentation toolchain for NCode libraries.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

421 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

NCode Docs

CI OpenSSF Scorecard

The shared documentation toolchain for NCode libraries: an Astro Starlight project, the NCode theme, the plugins that include compiled samples and keep links working under a base path, and the reusable GitHub Actions workflow that builds a library's site and publishes it to that library's GitHub Pages.

This repository is public for transparency and doesn't take outside contributions, as CONTRIBUTING.md says.

A library repository holds its pages and nothing of the toolchain:

In the library In this repository
Pages (.mdx), site.config.json The Starlight project, package.json, the lockfile
Its own components and images The theme, the fonts, the shared components
Its sample tests The sample and link plugins
A short workflow that calls it The reusable workflow that does the work

A library carries no npm manifest and no lockfile: the npm dependency graph lives here, once, and a library refers to it by one pinned commit. ADR-1001 has the reasons.

Adopting it in a library

  1. Add the content folder, docs/site/ by default, with a site.config.json and an index.mdx. CONTRACT.md is the reference for both; fixture/ is a complete small example.
  2. Mark the samples in the library's tests with // begin-snippet: Key and // end-snippet (Samples).
  3. Add the caller workflow (The caller workflow).
  4. Copy the launcher, fixture/build/site.mjs, into the library's build/ folder, to build and serve the site from its main checkout or any worktree of it (Local preview).
  5. Set up GitHub Pages and the site's address at <name>.ncode.io once (One-time setup).
  6. Tell Dependabot about the pin: the github-actions entry of the library's .github/dependabot.yml already covers workflow files, so the pinned commit moves with each release of this repository.
  7. Add *.mdx to whatever the library's own gate checks for line endings and encoding. Nothing is built inside the library, so its .gitignore needs no new line.

Content layout

docs/site/
  site.config.json             the site's settings
  index.mdx                    the landing page
  quick-start.mdx              /quick-start/
  guides/derive-a-key.mdx      /guides/derive-a-key/
  _components/Diagram.astro    the library's own components
  _assets/lifecycle.png        the library's own images
tests/**/*.cs                  the files that hold sample regions
.github/workflows/docs.yml     the caller workflow

Configuration

docs/site/site.config.json, checked against schema/site.config.schema.json before anything is built:

{
  "$schema": "https://raw.githubusercontent.com/NCodeGroup/docs/main/schema/site.config.schema.json",
  "title": "NCode.Buffers",
  "description": "One sentence about the library.",
  "product": "Buffers",
  "version": "v5",
  "repository": { "url": "https://github.com/NCodeGroup/Buffers", "branch": "main" },
  "site": { "url": "https://buffers.ncode.io" },
  "sidebar": [
    { "label": "Start here", "items": ["quick-start"] },
    { "label": "Guides", "items": [{ "autogenerate": { "directory": "guides" } }] }
  ]
}
Key Required Meaning
title Yes The site's name: browser titles, search, link previews
description Yes One sentence about the library
repository.url Yes The repository, for the header's link and edit links
repository.branch No The default branch. Default main
site.url Yes The site's URL with its base path, used when the workflow passes none
sidebar Yes The navigation: groups in order
product No The name beside the mark. Default: title
mark No ncode (default) or ncode-identity
version No The label on the header's readout
social No The header's links. Default: GitHub
samples No Globs of the sample files, under the repository root. Default ["tests/**/*.cs"]
editLinks No Default true
lastUpdated No Default true
requiredHeadings No Headings the pages a glob names must have, in order. Default: none

requiredHeadings keeps a skeleton on every page a glob names; the build stops on a page without a listed heading or with the headings out of order:

"requiredHeadings": [{ "pages": ["guides/*"], "headings": ["## Checklist"] }]

CONTRACT.md has the full form of each key, sidebar items included.

The caller workflow

.github/workflows/docs.yml in the library. It is fixture/.github/workflows/docs.yml with the pin replaced by a release's commit:

name: Documentation site

on:
  push:
    branches: [main]
  pull_request:
    types: [opened, synchronize, reopened]
  workflow_dispatch:

permissions: {}

concurrency:
  group: docs-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}

jobs:
  site:
    permissions:
      contents: read # checks out this repository
      pages: write # reads the site's URL, and creates the deployment
      id-token: write # proves to GitHub Pages where the deployment comes from
    uses: NCodeGroup/docs/.github/workflows/site.yml@<full commit SHA> # <version>
    with:
      content-path: docs/site
      deploy: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}

Every pull request builds the site, so a page that does not build fails its check, and keeps the result for a week as the github-pages artifact. The build job then loads every page in the runner's Google Chrome at 1440, 1280, 1024 and 390 px, and fails when an element leaves its page's content column or hides part of its content sideways (CONTRACT.md, sections 7 and 8). The artifact is uploaded first, so a failing pull request's site can still be browsed. Only a run on the default branch deploys. The three permissions are the most the called jobs use: the build job reads, and the deploy job, which runs none of the library's code, writes.

Input Default Meaning
content-path docs/site The content folder, relative to the repository root
deploy false Whether to publish; only the default branch ever does
toolchain-ref the pinned commit The commit of this repository to build with

The workflow also has one output, page-url: the URL of the published site, empty when the run did not deploy.

The workflow builds with this repository at the same commit the uses: line pins, which it reads from job.workflow_repository and job.workflow_sha. toolchain-ref is for a host where those are missing: a run that knows no commit stops at its first step and says so. Deployments run one at a time, in the workflow's own concurrency group, whatever the caller's concurrency says.

One-time setup

Every NCodeGroup site is served under ncode.io, one subdomain per site, at https://<name>.ncode.io/, where <name> is the library's name in lower case: https://buffers.ncode.io/ for NCodeGroup/Buffers (its ADR-1026) and https://brand.ncode.io/ for NCodeGroup/brand (its ADR-1015).

Already in place for every site:

  • ncode.io is registered at Porkbun, and its DNS is hosted on Cloudflare. Every record is DNS only (the grey cloud), never proxied, so GitHub Pages can issue each site's certificate, and a CAA record allows letsencrypt.org, the certificate authority GitHub Pages uses. The zone is signed with DNSSEC, which covers every record a library adds.
  • The NCodeGroup organization has verified ncode.io under its Settings > Pages > Verified domains, which covers every subdomain, so no other GitHub account can serve a site under it. A new site needs no change to the organization's settings.
  • A deploying run of the workflow reads the site's URL from the repository's Pages settings through actions/configure-pages, so the custom domain decides the base path the site is built for. site.url in site.config.json is the URL a pull request's build and the package's project website use.

docs/ncode-io.md records how the domain is set up, each fact with its source and the date it was read: its registration, its zone's records and DNSSEC keys, the organization's verified domain, each site's custom domain, who can change each part, the order for turning DNSSEC off or changing its key, and how to check it.

For a library whose site is to be served at https://<name>.ncode.io/, in this order; each step says who can do it: a repository administrator, someone who can edit the ncode.io zone in Cloudflare, or anyone who can open a pull request to the library.

  1. Settings > Pages > Build and deployment > Source: GitHub Actions. The repository's settings, by an administrator, before the workflow's first run on the default branch.
  2. Settings > Environments > github-pages > Deployment branches and tags: Selected branches and tags, with one rule, the default branch. Leave required reviewers and the wait timer off. The repository's settings, by an administrator, before the workflow's first run on the default branch.
  3. Cloudflare, the ncode.io zone: add a CNAME record <name> → ncodegroup.github.io, with its proxy status DNS only. The Cloudflare zone, by someone who can edit it.
  4. The library's site.config.json: set site.url to https://<name>.ncode.io, with no trailing slash. Record the address in the library's own decision record and changelog, as its conventions say. A pull request to the library.
  5. Settings > Pages > Custom domain: <name>.ncode.io. Once GitHub has issued the certificate, check Enforce HTTPS. The repository's settings, by an administrator.
  6. Redeploy: once the custom domain is set, run the library's site workflow on the default branch, with Run workflow on its page under Actions, which its workflow_dispatch trigger offers. A deploy that ran before step 5 built the site for the /<Repo>/ base path, so its stylesheets and scripts return 404 at https://<name>.ncode.io/. Anyone with write access to the repository.
  7. About > Website, on the repository's page: https://<name>.ncode.io/. GitHub shows it beside the repository. The repository's settings, by an administrator.
  8. The package's project URL: for a .NET library, PackageProjectUrl in the packed project, set to https://<name>.ncode.io/. A package gallery shows it as the project's website, such as nuget.org's "Project website", and it reaches the gallery with the next published version. A project that leaves it empty gets the repository's URL from its template. The repository link stays where the package's Source Link metadata puts it. A pull request to the library.
  9. Check: http://<name>.ncode.io/ redirects to HTTPS, https://ncodegroup.github.io/<Repo>/ redirects to https://<name>.ncode.io/, a page's stylesheet loads, and the page's canonical link, <link rel="canonical">, names https://<name>.ncode.io/. Anyone.

A pull request build needs none of it: it builds the site for site.url.

Writing a page

A page is an .mdx file with a title. The rest is in CONTRACT.md; the four rules that matter most:

Samples

A page never holds a copy of code that must compile. It names a region of a compiled test, and the build fills the block:

```cs snippet=QuickStart title="Signatures.cs" {4}
```
// begin-snippet: QuickStart
using var keyOwner = BufferFactory.Rent(32, isSensitive: true, out Span<byte> key);
// end-snippet

A key no sample file defines, a key defined twice, a region never closed and a malformed marker each fail the build, naming the page or the sample file, and the key. The language comes first in the fence, and the key has no quotes: cs snippet=Key.

Repository files

A page never holds a hand copy of a build file either. An empty block with file=<path>, a path from the repository root, shows the file whole, or from the line that holds from to the first line from there that holds to:

```xml file=Directory.Build.props from="<ItemGroup Condition=" to="</ItemGroup>"
```

The build fills the block, titles it with the path, and puts a caption under it that links those lines on GitHub at the commit the site was built from. A file that does not exist, text that is on no line or on several, and a language the code blocks do not highlight each fail the build. CONTRACT.md section 4 has the rest.

Links

Write internal links from the site's root, with a trailing slash, and never with the base path: [derive a key](/guides/derive-a-key/). The build adds the base path, so the page works under /Buffers/ and at the root of a custom domain. A broken link, a relative link, a link written with the base path, and a link the build could not put the base path on each fail the build, in a page, in its frontmatter and in the sidebar.

Components

import { Steps, Tabs, TabItem, Status, Pitfalls } from '@ncodegroup/docs/components';
import Diagram from '@site/components/Diagram.astro';
import lifecycle from '@site/assets/lifecycle.png';

@ncodegroup/docs/components is Starlight's components and this toolchain's own, Status, Readout, Braces and Pitfalls among them; @site/… is the library's _components/ and _assets/. A page imports from nowhere else.

A library's component is designed for a content column of about 36rem: CONTRACT.md section 7 gives the column's width at each window width, and how a component lays out data with many columns. The layout check fails an element that leaves the column, and a Markdown table too wide for it. Write an inline component on the text line it belongs to; marked data-inline, the layout check fails one that stands apart (CONTRACT.md section 7). The same section gives the guidance for pages that read calmly.

NCode.Buffers' components at release v5.3.2 lay out data with many columns as a card per entry: EntryCard.astro with EntryField.astro for cards written in a page, and ApiMap.astro and BufferBehaviorMatrix.astro for a table whose rows are drawn as cards. CONTRACT.md section 7 says what each one does and links the page it is on.

Local preview

With both repositories cloned side by side, from this repository's folder:

npm ci --ignore-scripts
npm run dev '--' ../Buffers

That serves the library's site at http://localhost:4321/<base path>/ and follows edits to its pages, its sample files and the files its pages include. npm run preview '--' ../Buffers builds the site as CI does and serves the result, with the search working. Both take --content <path> for a content folder other than docs/site, and --port <number>. Nothing is written to the library.

npm run site '--' build ../Buffers --out <folder> builds without serving. One checkout of the toolchain runs several of these commands at once, for several libraries or several worktrees of one, as long as each build writes its own --out folder.

npm run site '--' check ../Buffers --out <folder> loads that built site in a browser and fails as the workflow does. It uses the browser npm run browser installs, or a Chromium-based browser that --browser <path> or DOCS_BROWSER names, such as Microsoft Edge.

From the library's own folder, in its main checkout or in a plan's worktree under .claude/worktrees/, run the launcher the library copies from fixture/build/site.mjs:

node build/site.mjs dev
node build/site.mjs build --out ../site-out
node build/site.mjs check --out ../site-out

It builds the checkout it is in. It finds the toolchain in a folder named docs beside the library's main checkout, because git rev-parse --path-format=absolute --git-common-dir names the main checkout's .git folder from the main checkout and from every worktree; --toolchain <folder> or DOCS_TOOLCHAIN names another. Every other option goes to scripts/site.mjs as it is, and a relative path in one starts from the current folder. It runs node, never npm, so it needs no separator.

The separator is written '--', quoted, so that PowerShell passes it to npm: PowerShell drops a bare -- before npm's npm.ps1 shim runs, and npm then reads the options after it, such as --out, as its own. A POSIX shell such as bash reads '--' as --, so each command runs as written in both.

Development

The quickest way to start is the dev container: open the repository in a GitHub Codespace, or in VS Code with the Dev Containers extension, and .devcontainer/devcontainer.json installs PowerShell 7 and the project's tools and packages, so the commands below run as they are. CONTRIBUTING.md says what to install without it.

Run from the repository root in PowerShell 7:

Task Command
Install npm ci --ignore-scripts
Build npm run build
Install the test browser npm run browser
Test npm run test
Lint npm run lint
Format npm run format
Check the coverage ./.template/Test-Coverage.ps1
Check the file headers ./.template/Test-FileHeaders.ps1
Check the Markdown links node .template/check-markdown.mjs

npm run build builds fixture/, a stand-in library, into dist/. npm run test builds the fixture under /Fixture/ and at a domain's root, breaks a copy of it in each way a sample or a link can be wrong, checks the vendored brand files against their lock, and loads the built site in a browser.

npm run lint checks the code with Biome, as CI does before it builds, and npm run format applies Biome's formatting and safe fixes; biome.json holds the rules.

npm run test also writes the coverage of the toolchain's code to lcov.info, and ./.template/Test-Coverage.ps1 fails below 90% of its statements or 80% of its branches. CI runs it after the tests, and a release waits for it.

./.template/Test-FileHeaders.ps1 checks that each JavaScript, TypeScript and Astro file and each stylesheet starts with the copyright line and the SPDX-License-Identifier: Apache-2.0 line, as CI does, and -Fix adds them; CONTRIBUTING.md says where the lines go in an Astro component and a stylesheet.

The browser is the headless Chromium that the locked playwright-core drives. npm run browser downloads it, once for each version of playwright-core; on Linux, npm run browser '--' --with-deps also installs the system libraries it needs. Where the browser is not installed the browser check is skipped and says so. DOCS_REQUIRE_BROWSER=1 makes that a failure, and CI sets it.

Node.js is the version .node-version names, with npm 11.10 or later: .npmrc sets engine-strict, so an older npm stops at npm ci instead of ignoring the release-age rule. Where the machine's npm is older, run the install through a newer one: npx npm@11 ci --ignore-scripts. npm run works with any npm.

What is in this repository

Path What
.github/workflows/site.yml The reusable workflow
astro.config.mjs, ec.config.mjs The Starlight project, and its code blocks
scripts/site.mjs Builds, serves or previews one library's site
vendor/brand/vendoring/vendor-brand.mjs Brand's script that vendors a release of NCodeGroup/brand and checks the vendored files, vendored with them
scripts/brand-watch.mjs, .github/workflows/brand-watch.yml Checks NCodeGroup/brand every day and keeps one issue open while it has a release newer than the vendored one
src/snippets/ Reads sample regions and fills snippet= blocks
src/includes/ Reads the repository files pages name and fills file= blocks
src/headings/ Checks the headings requiredHeadings requires
src/brand/ Checks the brand tokens a library's components read
src/links/ Adds the base path to links; checks the built pages
src/highlighting/ C# 14 extension blocks for the C# grammar
src/tables/ Labels each Markdown table's cells with their column names, so a table stacks on a phone
src/layout/ Serves a built site and loads each page in a browser, to check that its content fits its column
src/components/ The shared components, and the three Starlight overrides
src/styles/theme.css Starlight's markup, restyled with the brand tokens
vendor/brand/ The brand's tokens, fonts, Starlight mapping, syntax theme and marks, vendored from a release
schema/site.config.schema.json The site configuration's schema
fixture/ A stand-in library: what npm run build builds and the tests check
fixture/build/site.mjs The launcher a library copies into its build/ folder
test/ The tests, for Node's own test runner
biome.json Biome's formatter and linter rules
CONTRACT.md What a library holds, and what the build does with it

The theme

The look is NCode's design system, Instrument, from NCodeGroup/brand. vendor/brand/ holds the files vendor/brand/brand.lock.json names from one of its releases, in the release's own folders: the tokens, the fonts, css/starlight.css, which sets Starlight's own properties from the tokens, the code blocks' syntax theme, the marks, the favicons and the script that vendors them, vendoring/vendor-brand.mjs. They are never edited here: npm run check:vendor, which the tests run, fails when a file differs from the SHA-256 the lock pins. src/styles/theme.css restyles Starlight's markup and ec.config.mjs frames the code blocks, both with the brand's public tokens alone: its type roles, with running text in the reading role on the --nc-measure column, its colour roles and its measures, and the Starlight properties css/starlight.css sets. Neither states a colour of its own or reads a step of a colour ramp or of the type scale, which a brand release may change, and the tests fail when either reads such a step or a custom property no vendored stylesheet defines (ADR-1008). The theme also keeps the sidebar, the page and the "On this page" panel together in the middle of a window wider than the three, as the brand's own documentation scene does, and gives a hero with no image one column (ADR-1020).

Updating and releasing

  • Packages. Exact versions in package.json, and each at least three days old when it is taken: .npmrc sets min-release-age=3, and Dependabot's cooldown says the same. npm install <package>@<version> for a version younger than that stops at once, also with --force, with npm error code ETARGET and No matching version found for <package>@<version> with a date before <date>, where <date> is three days ago. The version exists, whatever the error's next line says: npm takes it once it is three days old, so wait until then, or take the newest version npm offers. shiki and @astrojs/markdown-satteri are pinned to the versions Astro and Starlight resolve, so they move together with them in one pull request.
  • The brand. npm run update:brand '--' <version> vendors another release of NCodeGroup/brand. Dependabot can't see vendored files, so the brand-watch workflow, .github/workflows/brand-watch.yml, checks NCodeGroup/brand every day: while the lock pins an older release than the newest, it keeps one open issue labeled brand-update and dependencies, "Update the brand to ", with the release's links and these steps, and closes it once the lock pins the newest release. npm run watch:brand '--' --dry-run shows what it would do for NCodeGroup/docs; a later --repo=<owner/name> names another repository. The update needs the GitHub CLI, signed in, and writes the files only once gh attestation verify proves the release's archive was built by brand's publish workflow for its tag. A brand release is taken when it is published, without the packages' three-day wait (ADR-1008). The update also writes the release's own vendoring/vendor-brand.mjs, the script it runs (ADR-1009). Then npm run build, npm run test and node scripts/screenshots.mjs: a release that renames or removes a token the theme reads fails the tests.
  • Checking an update. npm ci --ignore-scripts, npm run build, npm run browser and npm run test, then the screenshots: Starlight is 0.x and a minor release may change the markup the theme styles.
  • Releasing. A release is a version tag on the default branch, with a GitHub release: .github/workflows/tag-release.yml makes both when a pull request whose description has a Release: <version> line merges. Libraries pin the tag's commit SHA in their caller workflow, with the version in a comment, and Dependabot proposes the next one in each library. A library's site changes only when that pull request merges.
  • A change a library needs (a shared component, a configuration key) is made here, released, and then taken by the library through its pin. Nothing library-specific is committed here.

AI-Assisted Workflow

This repository is set up for plan-then-execute coding: Claude Opus plans each change into PLAN.md, a cheaper model executes it one verified step at a time, and any step that needs a decision goes back to Opus. AGENTS.md is the index of the instructions every agent follows.

Work in Claude Code or GitHub Copilot, and switch whenever you like: both have the same commands, and PLAN.md is the only state they share, so one can plan and the other execute. Each bills its own subscription.

Tool Plan Execute Re-plan one step Review Land, then finish
Claude Code /plan-feature <what to build> (or /plan-bugfix, /plan-refactor, /plan-tests, …), or /plan-issue #42 for an issue, then review PLAN.md /orchestrate-plan /replan-step N /review-plan-diff /ship-plan, then /finish-plan
Copilot Chat in VS Code The Copilot Planner agent on Opus, or /plan-feature or /plan-issue #42 Run all steps with subagents, or Execute next step Re-plan with the planner Review the work /ship-plan, then /finish-plan
Copilot CLI copilot --model claude-opus-5.5, then /plan-feature or /plan-issue #42 /orchestrate-plan /replan-step N /review-plan-diff /ship-plan, then /finish-plan

In Claude Code, plan in Accept edits mode and execute in Auto.

Each plan gets its own git worktree under .claude/worktrees/, in every tool, so several sessions can work on different plans at once.

The workflow files come from a Copier template, which owns them: never edit .template/, .template-version, .githooks/pre-push, .github/instructions/project-template.instructions.md, .copier-answers.yml, CLAUDE.md or the commands, agents and skills the template generates. To change how agents work here, edit AGENTS.md or a file it lists. To pull in template improvements, run .\.template\Update-Project.ps1: it updates itself, replaces the template's files, merges template changes into the shared settings files, and never touches AGENTS.md or this README. To plan the update first, with a trial run, the project files that need changing and the checks, run /plan-template-update. The weekly template-update workflow opens an issue, labeled template-update, when a newer template version is out, and closes it once the project has updated; /plan-issue plans it.

Project

License

NCode Docs is licensed under the Apache License 2.0. The files in vendor/brand/ come from NCodeGroup/brand under the same license, except the fonts in vendor/brand/fonts/, licensed under the SIL Open Font License 1.1 with their license files beside them, and the names NCode, NCode Group and NCode Identity and the marks in vendor/brand/logo/: trademarks of NCode Group, whose artwork is copyright NCode Group, all rights reserved, and which the Apache License 2.0 does not cover. vendor/brand/TRADEMARKS.md says how they may be used.

About

The shared documentation toolchain for NCode libraries.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages