Skip to content

docs: take the chart version from Chart.yaml - #481

Merged
uniqueg merged 6 commits into
devfrom
docs/chart-version
Oct 24, 2026
Merged

uniqueg merged 6 commits into
devfrom
docs/chart-version

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Maintainer decision of 2026-10-24: take the current version of the library chart foca-common from one source, as FOCA's own version since #453/PR #462 (mirroring cloud-registry's chart-version placeholder of cloud-registry PR #224 where it fits; there the chart version follows the app version, here it is independent).

  • Docs hook (docs/hooks.py): new placeholder, chart_version in double curly braces (CHART_VARIABLE), replaced with the version of charts/foca-common/Chart.yaml (read with PyYAML; only final X.Y.Z versions, as only those are released, else the build fails). Each file is only read if its placeholder is used.
  • Docs: the placeholder replaces the hard-coded current chart version in the dependency snippet and helm show chart command of docs/helm-chart.md, and the verification commands of docs/deployment.md. Statements about particular chart releases ("before/since foca-common 0.2.0", "from version 0.2.0 on") stay as they are. docs/contributing.md describes the placeholder and the guard.
  • Drift guard (tests/test_version_mentions.py): also fails if the current chart version is hard-coded as the chart's version: foca-common:X, foca-common X, chart-vX, Helm's --version X with foca-common (also on a continuation line), and the version of a dependency on the line after name: foca-common. Allowed: Chart.yaml, the example app's chart (Chart.yaml, Chart.lock: Helm can't take the version from elsewhere), the changelog, the migration guides, and "before/since/from/up to/until" statements. Checked against the old docs (all 5 hard-coded lines are caught) and for chart versions 0.3.0, 1.0.0 and 1.1.0 (no false positives, e.g., from OpenAPI info.version).

Verification

  • pytest with MongoDB 7 (coverage), after merging dev (incl. feat!: tighten group checks and error details #475, refactor!: remove get_enforcer() #477, fix(chart): use a keep-alive of 100 s #478): 2368 passed, 1 skipped; coverage report: 100%
  • mypy: no issues; ruff check: clean; pre-commit run --all-files: all hooks passed
  • mkdocs build --strict: no warnings; the built pages show the chart version (0.2.0)
  • CI: all 30 checks passed (2 skipped: image push/publish). Sourcery: 5 comments; fixed: mkdocs serve watches Chart.yaml, "foca-common version X" is found; declined (replied, resolved): read the chart version once per build (the hook reads CITATION.cff per page the same way), version-first prose and multi-line continued Helm commands (rare forms; broader patterns would flag other versions).
  • Review: adversarial + quality reviewers, two rounds; fixed: dependency version matched only after name: foca-common (it matched any version: line), Helm --version forms, a hook test for an invalid chart, docstring and docs wording.

Declined review findings

  • Let the tests use hooks.chart_version() instead of reading Chart.yaml themselves: declined, the tests keep an independent oracle, and test_version_mentions.py doesn't load the hooks.
  • Bundle the pattern constants per version kind into a NamedTuple: optional, declined to keep the guard's structure as it was.
  • Dependencies with other keys between name and version are not caught: accepted (the docs use name, version, repository); a test pins it.

Notes

  • The docs of dev may show a chart version that is not released yet, as the chart's version is raised with its first change after a release (documented in docs/contributing.md). Taking the latest chart-v* tag instead would need tags in the docs build; left as is.

Open questions

None.

Closes #472

🤖 Generated with Claude Code

uniqueg and others added 4 commits October 24, 2026 16:35
The docs hard-coded the version of the library chart foca-common (in
the dependency snippet of docs/helm-chart.md and the verification
commands of docs/deployment.md), which went stale with each chart
release. Add the placeholder {{ chart_version }} to the docs hook,
replaced with the version of charts/foca-common/Chart.yaml (final
versions only), use it in the docs, and extend the drift guard to the
current chart version, allowing Chart.yaml, the example app's chart,
the changelog, the migration guides and statements of what applies
before, since or up to a chart release.

Closes #472

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Match the version of a dependency only after its name: foca-common, so
that versions of API specs and service info don't count, and match Helm
commands with --version. Test an invalid chart via the hook, use the
placeholder for inspecting a release, and split the hook's module
docstring and the contributing guide's paragraph.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Also match --version before the chart or after other options, on a
continuation line, and after a commented dependency name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Documentation now derives the independent foca-common chart version from charts/foca-common/Chart.yaml through a validated MkDocs placeholder, while comprehensive tests and a repository-wide drift guard prevent hard-coded chart-version references outside approved release-specific contexts.

Sequence diagram for chart version substitution in documentation

sequenceDiagram
    participant MkDocs
    participant Hook as docs/hooks.py
    participant Chart as charts/foca-common/Chart.yaml
    participant Page as Documentation page
    MkDocs->>Hook: on_page_markdown(markdown, page, config, files)
    alt CHART_VARIABLE is present
        Hook->>Chart: read_text(encoding="utf-8")
        Hook->>Hook: chart_version(chart)
        Hook->>Hook: substitute_chart_version(markdown, version)
        Hook-->>MkDocs: rendered markdown with chart version
    else CHART_VARIABLE is absent
        Hook-->>MkDocs: unchanged markdown
    end
Loading

Flow diagram for chart version drift prevention

flowchart TD
    Chart[Chart.yaml version] --> Docs[Documentation placeholders]
    Docs --> Build[mkdocs build]
    Build --> Rendered[Rendered chart-version commands]
    Chart --> Guard[test_version_mentions.py]
    Guard -->|approved references only| Pass[Tests pass]
    Guard -->|hard-coded chart version found| Fail[Tests fail]
Loading

File-Level Changes

Change Details Files
Added dynamic chart-version substitution to the documentation build.
  • Introduced a {{ chart_version }} placeholder and replacement helper.
  • Loaded charts/foca-common/Chart.yaml only when the placeholder is present.
  • Validated chart versions as final X.Y.Z releases and failed builds for invalid values.
  • Updated Helm and deployment documentation to use the placeholder.
  • Documented chart version sourcing, validation, and development-version behavior.
docs/hooks.py
docs/helm-chart.md
docs/deployment.md
docs/contributing.md
Expanded documentation hook tests for chart version handling.
  • Covered substitution in prose and code blocks alongside the existing release placeholder.
  • Verified independent source files and lazy file reads.
  • Tested valid and invalid chart metadata, including prerelease and malformed versions.
  • Verified the updated documentation renders the current chart version.
tests/test_docs_hooks.py
Added drift detection for hard-coded library chart versions.
  • Added patterns for OCI/package references, release tags, Helm --version forms, continued commands, and dependency declarations.
  • Added explicit allowlists for chart sources, examples, release documentation, migrations, and test files.
  • Supported line-aware exceptions for historical release statements and tested false-positive cases.
  • Applied the guard to the current version from Chart.yaml.
tests/test_version_mentions.py

Assessment against linked issues

Issue Objective Addressed Explanation
#472 Add a {{ chart_version }} docs placeholder that reads and validates the foca-common version from charts/foca-common/Chart.yaml, replacing it in pages (including code blocks) while leaving unrelated template expressions unchanged. ✅
#472 Replace hard-coded references to the current chart version in documentation, while retaining references to specific historical releases. ✅
#472 Extend the chart-version drift guard with appropriate release-reference allowlists and tests, and document the placeholder and versioning guidance for contributors. ✅

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 (d956270) to head (75abd8b).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #481   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        29           
  Lines         3444      3444           
=========================================
  Hits          3444      3444           
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 15:11

@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 5 issues

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

## Individual Comments

### Comment 1
<location path="docs/hooks.py" line_range="37" />
<code_context>
 VARIABLE = "{{ version }}"
 # Version that the docs show if `CITATION.cff` has no `version`
 UNRELEASED = "X.Y.Z"
+CHART = Path("charts/foca-common/Chart.yaml")
+# Placeholder of the version of the library chart in pages
+CHART_VARIABLE = "{{ chart_version }}"
</code_context>
<issue_to_address>
**Live preview keeps stale chart version**

When a contributor changes `charts/foca-common/Chart.yaml` while `mkdocs serve` is running, `on_page_markdown` reads the chart version, but `mkdocs.yml` does not watch `Chart.yaml`, so MkDocs does not rebuild the affected pages and the live preview continues showing the old version.

Add `charts/foca-common/Chart.yaml` to the files watched by MkDocs.

Also at `docs/hooks.py:155-158`.
</issue_to_address>

### Comment 2
<location path="docs/hooks.py" line_range="156-159" />
<code_context>
+        )
+        markdown = substitute_version(markdown, version)
+    if CHART_VARIABLE in markdown:
+        markdown = substitute_chart_version(
+            markdown, chart_version((root / CHART).read_text(encoding="utf-8"))
+        )
+    return markdown
</code_context>
<issue_to_address>
**Build can mix chart versions**

When `charts/foca-common/Chart.yaml` is edited while a documentation build is rendering pages, `on_page_markdown` reads `Chart.yaml` separately for every page containing the placeholder. If that file changes between rendering two such pages, one build emits pages with different chart versions, so readers see inconsistent commands and dependency examples.

Read and validate the chart version once per build, then use that same value for every page.
</issue_to_address>

### Comment 3
<location path="tests/test_version_mentions.py" line_range="103" />
<code_context>
+# Mentions of the chart version: the chart (an OCI reference, its package,
+# or in prose), its release tag, and the `version` of a dependency on it
+CHART_MENTIONS = (
+    r"(?i:\bfoca-common)(?:[:@\-]|\s+v?)v?{version}{end}",
+    r"\bchart-v{version}{end}",
+    # Helm commands (`helm show chart <ref>/foca-common --version X`, also
</code_context>
<issue_to_address>
**Chart version prose goes undetected**

When a tracked file describes the chart as “foca-common version X.Y.Z”, `CHART_MENTIONS` does not match this wording, so the drift-guard test passes even when the current chart version is hard-coded.

Add a pattern that matches a version following “foca-common version”.
</issue_to_address>

### Comment 4
<location path="tests/test_version_mentions.py" line_range="103" />
<code_context>
+# Mentions of the chart version: the chart (an OCI reference, its package,
+# or in prose), its release tag, and the `version` of a dependency on it
+CHART_MENTIONS = (
+    r"(?i:\bfoca-common)(?:[:@\-]|\s+v?)v?{version}{end}",
+    r"\bchart-v{version}{end}",
+    # Helm commands (`helm show chart <ref>/foca-common --version X`, also
</code_context>
<issue_to_address>
**Version-first mentions go undetected**

When the current chart version appears before `foca-common` in prose or in a continued Helm command, `CHART_MENTIONS` and the reverse-order Helm pattern do not match these forms, so the drift test passes while the current chart version is hard-coded.

Extend the mention patterns to match reverse-order prose and continued Helm commands with `--version` before the chart reference.

Also at `tests/test_version_mentions.py:108`, `tests/test_version_mentions.py:112`.
</issue_to_address>

### Comment 5
<location path="tests/test_version_mentions.py" line_range="112" />
<code_context>
+    # Patterns with a newline are matched against the previous and the
+    # current line: Helm commands continued on the next line, and the
+    # `version` of a dependency on the line after its `name`
+    r"(?i:\bfoca-common)\S*(?:\s+\S+)*?\s*\\\n\s*--version[=\s]+[\"']?{version}{end}",
+    r"\bname:\s*[\"']?foca-common[\"']?\s*(?:#.*)?\n\s*version:\s*[\"']?{version}{end}",
+)
</code_context>
<issue_to_address>
**Some continued Helm commands evade the guard**

When a Helm command puts an option such as `--untar` on its own continued line between the chart reference and `--version`, `mentions` checks a continued command using only the immediately previous line and the current line. If another continued option intervenes, the chart reference and hard-coded `--version` are never matched together, so the drift test passes with a stale version in a valid multiline command.

Track the start of an ongoing Helm command across continuation lines, or match the complete continued command before checking its chart version.
</issue_to_address>

Sourcery assessment

Approval pending. 5 findings to address first.

Blocking findings: docs/hooks.py:37, docs/hooks.py:159, tests/test_version_mentions.py:103, tests/test_version_mentions.py:103, tests/test_version_mentions.py:112


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

Comment thread docs/hooks.py Resolved
Comment thread docs/hooks.py Resolved
Comment thread tests/test_version_mentions.py Resolved
Comment thread tests/test_version_mentions.py Resolved
Comment thread tests/test_version_mentions.py Resolved
uniqueg and others added 2 commits October 24, 2026 17:15
Rebuild the docs on changes of the chart version in mkdocs serve, and
also find "foca-common version X" in the drift guard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 907c3ee into dev Oct 24, 2026
32 checks passed
@uniqueg
uniqueg deleted the docs/chart-version branch October 24, 2026 15:40
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 chart version from Chart.yaml

1 participant