Skip to content

docs: inject the latest git tag into the tutorial snippets - #32

Merged
coretl merged 3 commits into
DiamondLightSource:mainfrom
coretl:docs-inject-latest-tag
Jun 26, 2026
Merged

coretl merged 3 commits into
DiamondLightSource:mainfrom
coretl:docs-inject-latest-tag

Conversation

@coretl

@coretl coretl commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

What

The tutorial's copy-paste blocks pinned this project at a literal <tag> placeholder readers had to fix by hand. This replaces them with a __LATEST_TAG__ sentinel and adds a build-only MyST transform that swaps it for the repo's latest tag at build time, so the rendered snippets carry a real, current ref (v0.16.0 today).

How

  • docs/_ext/inject-latest-tag.mjs — a document-stage MyST transform that replaces __LATEST_TAG__ in text/code nodes. Build-only (never runs in the browser, unlike version-switcher.mjs), so it's free to touch git. Lives under docs/_ext/, not plugins/, since it's docs tooling, not the shipped widget.
  • package.json — a latest-tag script (git describe --tags --abbrev=0, falling back to git fetch --tags && describe for the shallow CI checkout, which has no tags) feeds LATEST_TAG into docs/docs-dev via a LATEST_TAG=… sh -c '…' wrapper so the env actually reaches myst.
  • docs/myst.yml — registers the plugin.
  • docs/tutorials/adding-to-a-fresh-repo.md — the 4 copy-paste code blocks + the inline pin use __LATEST_TAG__; reworded the two prose lines that referenced the old placeholder.

If no tag resolves, the transform leaves the sentinel and emits a build warning rather than silently shipping __LATEST_TAG__.

Scope & known limitation

  • Tutorial only — reference/ and explanations/ keep the literal <tag>.
  • MyST's auto per-page Markdown download (book-theme "Downloads" menu) still shows the sentinel: it's a source snapshot serialized before transforms run, so it's outside the transform's reach. Left as-is by design — it's "the source," consistent with the GitHub "Edit this page" link. The rendered pages (the actual copy-paste surface) are all correct.

Verification

  • Clean build → every rendered tutorial page shows v0.16.0; no sentinel in the rendered HTML.
  • npm test → 22/22; biome clean; prek passes.

🤖 Generated with Claude Code

coretl and others added 3 commits June 26, 2026 13:30
The tutorial's copy-paste blocks pinned this project at a literal `<tag>`
placeholder readers had to fix by hand. Replace those with a `__LATEST_TAG__`
sentinel and add a build-only MyST transform (docs/_ext/inject-latest-tag.mjs)
that swaps it for the repo's latest tag (`git describe --tags --abbrev=0`) at
build time, so the rendered snippets carry a real, current ref.

The tag comes from a LATEST_TAG env set by the `docs`/`docs-dev` npm scripts
(which fetch tags first so it works in a shallow CI checkout); the transform
falls back to `git describe` directly and warns rather than silently shipping
the sentinel if no tag resolves.

Scope: tutorial only; reference/architecture keep the literal `<tag>`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The shallow default clone has no tags, so a build-command deriving a version
from `git describe` (this repo's docs, to pin the tutorial snippets at the
latest release) found none in CI and fell back to the sentinel. Fetch full
history + tags unconditionally; tags are cheap and any consumer's build-command
can now rely on them.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Now that docs.yml checks out with fetch-depth 0, the tags are always present in
CI, so the LATEST_TAG env + the `latest-tag` npm helper (with its shallow-clone
fetch fallback) are redundant. Drop them and let the transform call
`git describe` directly; restore the plain `docs`/`docs-dev` scripts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coretl
coretl merged commit 4025d9d into DiamondLightSource:main Jun 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant