Skip to content

docs: take the version from one source - #462

Merged
uniqueg merged 5 commits into
devfrom
docs/version-one-source
Oct 24, 2026
Merged

uniqueg merged 5 commits into
devfrom
docs/version-one-source

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

The current release version now comes from one source, as in Cloud Registry (elixir-cloud-aai/cloud-registry#224) and proTES (elixir-cloud-aai/protes#299):

  • MkDocs hook (docs/hooks.py, hooks: and exclude_docs in mkdocs.yml): pages write the version as the version placeholder in double curly braces. The hook replaces it with the version of CITATION.cff, read with the new release_version() of scripts/citation.py. Without a version, the docs show X.Y.Z, as in proTES. Only that exact form is replaced, so the Helm templates of docs/helm-chart.md and the --format '{{ json .SBOM }}' of docker buildx stay as they are. That is why the docs don't use mkdocs-macros. CITATION.cff is added to watch, so mkdocs serve rebuilds when the version changes.

  • Docs: docs/deployment.md (the verification and inspection commands, "replace ... with the version to verify", the digest example) and docs/getting-started.md (example image tags, which named the upcoming 0.18.0) use the placeholder. README.md no longer names the release behind its line counts; the date is enough.

  • Drift guard (tests/test_version_mentions.py): fails if the current release version is mentioned as a release of FOCA in a tracked file outside an allowlist. Mentions it looks for: tag, image, package (also with extras and specifiers), PyPI and Read the Docs paths, and "release"/"version" in prose. The allowlist:

    • files: CITATION.cff, the changelog, the migration guides (docs/migration-X.Y.md), and the tests of the release tooling;
    • parts of lines: links to release notes and assets, "Migrating to X" links and headings, "From FOCA X on", the comments of pinned actions, and the rev: lines of pre-commit hooks.

    It runs in the existing test job (coverage run -m pytest, testpaths tests).

  • Release docs: "Versioning and releases" in docs/contributing.md describes the rule.

There is no chart-version placeholder: unlike in the apps, FOCA's library chart is versioned independently of the release (charts/foca-common/Chart.yaml, bumped with every change), so CITATION.cff can't supply it.

Verification

  • pytest -m "not mongodb" under coverage: 2003 passed, 1 skipped; coverage report: 100% (the MongoDB tests need a server and run in CI).

  • ruff check, ruff format --check, mypy (now also on docs/hooks.py): clean.

  • pre-commit run --all-files: all hooks passed.

  • mkdocs build --strict: clean. The built site has no placeholder left, foca:0.17.0 appears in the deployment page, and the {{ json ... }} formats are kept.

  • On origin/dev docs, the drift test fails with the 11 hard-coded lines this PR fixes, and passes with the PR. A scan with 0.18.0 and 0.19.0 as the release version finds nothing outside the allowlist.

  • CI: all checks passed, including the unit tests on every Python and MongoDB version, the docs build and the Read the Docs preview.

Review

The full review ran: adversarial and quality reviewers, plus a second adversarial round after the fixes. Fixed:

  • the guard now also finds package specifiers, extras, PyPI and RTD paths, [v...], workflow refs, "FOCA (X)" and "the X release" (medium);
  • tool pins are skipped;
  • CITATION.cff is watched;
  • docs/deployment.md is rewrapped.

Sourcery found 3 issues:

  • fixed: whitespace around version operators, and exceptions that were too broad (only the guides themselves and only rev: lines are allowed now);
  • declined: "worktrees skip the drift guard". Path.exists() is true for a worktree's .git file, and the test ran and passed in a git worktree add checkout.

Declined review findings

  • Revert the rewrap of the second "From FOCA 0.17.0 on" paragraph (low): declined. The rewrap is deliberate. The guard checks one line at a time, so "From FOCA X on" has to be on one line to match its allowlist pattern.
  • test_docs_use_placeholder reads the version through the hook's own release_version() (low): kept, as in Cloud Registry. tests/test_citation.py tests release_version() directly.
  • Shorten the paragraph in the contributing guide (low): kept. It is as detailed as in Cloud Registry and proTES.
  • False positives if FOCA ever reaches 1.0.0 (low): not reachable before then. For example, "version 1.0.0" of the service-info spec and appVersion: "1.0.0" examples would match. They can be fixed with placeholders when that release comes.

Open questions

None.

Closes #453

🤖 Generated with Claude Code

uniqueg and others added 4 commits October 24, 2026 13:10
Pages write the current release version as a placeholder, replaced by
an MkDocs hook (docs/hooks.py) with the version of CITATION.cff, as in
Cloud Registry. Only that exact form is replaced, so the Helm templates
of docs/helm-chart.md and the --format of docker buildx are left as
they are (which mkdocs-macros would not do).

scripts/citation.py gets release_version(), which the hook reads. The
verification commands of docs/deployment.md use the placeholder.

Refs #453

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tests/test_version_mentions.py fails if the current release version (of
CITATION.cff) is mentioned as a release of FOCA in a tracked file
outside an allowlist: CITATION.cff, the changelog, the migration guides,
the tests of the release tooling, links to release notes and assets,
"Migrating to X" links and headings, and "From FOCA X on". As in Cloud
Registry and proTES.

The README no longer names the release of its line counts (the date
does), and the contributing guide describes the rule.

Closes #453

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Find the package with extras and version specifiers, PyPI and Read the
Docs paths without "v", "[v1.2.3]", pinned refs of FOCA's workflows,
"FOCA (1.2.3)" and "the 1.2.3 release". Skip the versions of tools: the
pins of .pre-commit-config.yaml and the comments of pinned actions.

Rebuild the docs preview when CITATION.cff changes, and rewrap the
paragraphs of docs/deployment.md with the placeholder.

Refs #453

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The example image tags of docs/getting-started.md named the upcoming
release (0.18.0), which the guard would flag once CITATION.cff has it.
They use the placeholder now, with Python 3.12, which the images of
every release have.

Refs #453

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v0.18.0 milestone Oct 24, 2026
@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR makes CITATION.cff the single source for the current release version, renders that value into MkDocs pages through a narrowly scoped hook, and adds a comprehensive drift guard to prevent hard-coded release references from reappearing while documenting the workflow and updating affected examples.

Sequence diagram for rendering the documentation release version

sequenceDiagram
    participant MkDocs
    participant Hook as docs/hooks.py
    participant Citation as CITATION.cff
    participant Parser as scripts/citation.py
    MkDocs->>Hook: on_page_markdown(markdown, page, config, files)
    Hook->>Hook: substitute_version(markdown, version)
    Hook->>Citation: read_text(encoding)
    Hook->>Parser: release_version(text)
    Parser-->>Hook: version or None
    Hook-->>MkDocs: Markdown with version or X.Y.Z
Loading

Flow diagram for preventing release-version drift

flowchart LR
    Citation[CITATION.cff version]
    Files[Tracked repository files]
    Guard[test_version_mentions.py]
    Allowlist[Allowlist for release notes and tooling]
    Result{Hard-coded release mention?}
    Citation --> Guard
    Files --> Guard
    Allowlist --> Guard
    Guard --> Result
    Result -->|Yes, outside allowlist| Fail[Fail test]
    Result -->|No| Pass[Pass test]
Loading

File-Level Changes

Change Details Files
Centralize the documentation release version in CITATION.cff and substitute a typed placeholder during MkDocs rendering.
  • Add a typed MkDocs page hook that reads the citation version, falls back to X.Y.Z, and preserves unrelated template syntax.
  • Configure the hook, exclude its source from published docs, and watch CITATION.cff for live rebuilds.
  • Add release_version() to the citation tooling with validation for missing, duplicate, and invalid versions.
  • Replace hard-coded release examples in deployment and getting-started documentation with the placeholder.
docs/hooks.py
mkdocs.yml
scripts/citation.py
docs/deployment.md
docs/getting-started.md
tests/test_citation.py
tests/test_docs_hooks.py
pyproject.toml
Prevent future release-version drift across tracked project files with an allowlisted scanner.
  • Detect release mentions in tags, images, packages, URLs, workflow refs, prose, and version-like metadata while excluding unrelated versions and templates.
  • Allow historical release documentation, migration references, release-tool tests, tool pins, and explicitly release-specific statements.
  • Run the guard through the existing pytest test job and cover matching and allowlist behavior with parametrized tests.
tests/test_version_mentions.py
Document the single-source versioning workflow and remove a stale release-specific README reference.
  • Explain how CITATION.cff, the release tag, documentation placeholders, and drift checks interact.
  • Clarify limitations for GitHub-rendered README content and independently versioned chart releases.
  • Remove the old FOCA release number from the README line-count note.
docs/contributing.md
README.md

Assessment against linked issues

Issue Objective Addressed Explanation
#453 Use the version in CITATION.cff as the single source for release-version placeholders in the documentation. ✅
#453 Avoid hard-coding the current release version in documentation and other tracked content, and add a CI test that detects mentions outside an appropriate allowlist. ✅
#453 Document the versioning rule for future releases. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (83b9926) to head (6241b86).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #462   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           28        28           
  Lines         3266      3266           
=========================================
  Hits          3266      3266           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 24, 2026 11:23

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_version_mentions.py" line_range="188" />
<code_context>
+        The paths, as `git ls-files` lists them.
+    """
+    git = shutil.which("git")
+    if git is None or not (ROOT / ".git").exists():
+        pytest.skip("needs a Git checkout")
+    listed = subprocess.run(  # noqa: S603 (fixed arguments, no shell)
</code_context>
<issue_to_address>
**Worktrees skip the drift guard**

When the suite runs from a Git worktree, where `.git` is a file, `test_release_version_not_hard_coded` is skipped because `_tracked_files` treats a worktree’s `.git` file as no Git checkout; the test suite then passes without detecting hard-coded release versions.

Detect a Git checkout with a Git command such as `git rev-parse`, rather than checking whether `.git` is a directory.
</issue_to_address>

### Comment 2
<location path="tests/test_version_mentions.py" line_range="56" />
<code_context>
+    r"/en/v?{version}{end}",
+    # The image, the package (also with extras and any version specifier,
+    # and on PyPI, `project/foca/1.2.3/`) and FOCA in prose
+    r"(?i:\bfoca)(?:\[[^\]]*\])?(?:[:\-@/]|\s+\(?|[<>=~!]=?=?)v?{version}{end}",
+    r"(?<![0-9.]){version}{end} releases?\b",
+    r"(?i:\b(?:release|version)s?)\s+v?{version}{end}",
</code_context>
<issue_to_address>
**Whitespace hides package versions**

When a tracked file uses a valid package requirement with whitespace around its version operator, the package-name pattern in `mentions()` rejects whitespace-separated version operators, so `test_release_version_not_hard_coded` misses the release and CI passes with a hard-coded version.

Update the package pattern in `mentions()` to match version operators and versions separated by whitespace, including requirements with extras or parentheses.
</issue_to_address>

### Comment 3
<location path="tests/test_version_mentions.py" line_range="34" />
<code_context>
+ALLOWED_FILES = (
+    "CITATION.cff",
+    # Versions of the hooks' tools (e.g., `rev: v1.2.3`), never FOCA's
+    ".pre-commit-config.yaml",
+    "docs/changelog.md",
+    "tests/test_citation.py",
</code_context>
<issue_to_address>
**Version guard skips unrelated files**

When a tracked file under either broad exception contains a current-release FOCA mention, the scan skips the entire matching file, so a FOCA release version added to a non-guide `docs/migration-*` file or a non-pin setting in `.pre-commit-config.yaml` is never checked, and CI passes with a hard-coded version.

Restrict the migration exception to guide Markdown files and exempt only the tool-pin lines in `.pre-commit-config.yaml`.

Also at `tests/test_version_mentions.py:43`.
</issue_to_address>

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: tests/test_version_mentions.py:188, tests/test_version_mentions.py:56, tests/test_version_mentions.py:34


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/test_version_mentions.py Resolved
Comment thread tests/test_version_mentions.py Resolved
Comment thread tests/test_version_mentions.py Resolved
Allow only the migration guides themselves (docs/migration-X.Y.md) by
path, and only the rev lines of pre-commit hooks instead of the whole
.pre-commit-config.yaml. Also find package requirements with
whitespace around the operator (e.g., "foca >= 1.2.3").

Refs #453

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit dc4b4c6 into dev Oct 24, 2026
32 checks passed
@uniqueg
uniqueg deleted the docs/version-one-source branch October 24, 2026 11:37
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.

docs: take the version from one source

1 participant