Repository navigation
docs: take the version from one source - #462
Conversation
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]>
Reviewer's GuideThis 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 versionsequenceDiagram
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
Flow diagram for preventing release-version driftflowchart 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]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #462 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 28 28
Lines 3266 3266
=========================================
Hits 3266 3266
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
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]>
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:andexclude_docsinmkdocs.yml): pages write the version as theversionplaceholder in double curly braces. The hook replaces it with theversionofCITATION.cff, read with the newrelease_version()ofscripts/citation.py. Without a version, the docs showX.Y.Z, as in proTES. Only that exact form is replaced, so the Helm templates ofdocs/helm-chart.mdand the--format '{{ json .SBOM }}'ofdocker buildxstay as they are. That is why the docs don't use mkdocs-macros.CITATION.cffis added towatch, somkdocs serverebuilds when the version changes.Docs:
docs/deployment.md(the verification and inspection commands, "replace ... with the version to verify", the digest example) anddocs/getting-started.md(example image tags, which named the upcoming 0.18.0) use the placeholder.README.mdno 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:CITATION.cff, the changelog, the migration guides (docs/migration-X.Y.md), and the tests of the release tooling;rev:lines of pre-commit hooks.It runs in the existing
testjob (coverage run -m pytest, testpathstests).Release docs: "Versioning and releases" in
docs/contributing.mddescribes 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), soCITATION.cffcan't supply it.Verification
pytest -m "not mongodb"undercoverage: 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 ondocs/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.0appears in the deployment page, and the{{ json ... }}formats are kept.On
origin/devdocs, 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:
[v...], workflow refs, "FOCA (X)" and "the X release" (medium);CITATION.cffis watched;docs/deployment.mdis rewrapped.Sourcery found 3 issues:
rev:lines are allowed now);Path.exists()is true for a worktree's.gitfile, and the test ran and passed in agit worktree addcheckout.Declined review findings
test_docs_use_placeholderreads the version through the hook's ownrelease_version()(low): kept, as in Cloud Registry.tests/test_citation.pytestsrelease_version()directly.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