Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: reject new documentation reference warnings
  • Loading branch information
hugosmoreira committed Oct 10, 2026
commit ac23eae4b493215a5687dcc73362206f65bd31c3
4 changes: 4 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ CI/CD workflows for the Stickler project.

## Conventions

`Check Documentation` must remain a non-required check: its path filter means
unrelated PRs do not report a status. Making it required would leave those PRs
waiting indefinitely.

- **SHA pinning**: all `uses:` references are pinned to full 40-character
commit SHAs with a trailing `# vX.Y.Z` comment (supply-chain hardening;
mutable tags can be repointed). Dependabot (`.github/dependabot.yml`)
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/docs-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
- 'src/**'
- 'pyproject.toml'
- 'uv.lock'
- '.python-version'
- '.github/workflows/docs-check.yml'

permissions:
Expand All @@ -28,7 +27,5 @@ jobs:
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
with:
python-version: "3.12"
- name: Install dependencies
run: uv sync --frozen --no-default-groups --group docs
- name: Build and check documentation links
run: uv run --frozen --no-default-groups --group docs python docs/check_links.py
run: uv run --frozen --only-group docs python docs/check_links.py
15 changes: 8 additions & 7 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# automatic navigation generation from directory structure.

# Declare phony targets (targets that don't represent files)
.PHONY: install docs build deploy clean
.PHONY: install docs build check deploy clean

# install: Install all documentation dependencies
#
Expand Down Expand Up @@ -35,18 +35,19 @@ docs:

# build: Build static site for production
#
# Generates the complete static site in the site/ directory. This validates:
# - All Markdown files compile correctly
# - Internal links resolve properly
# - API documentation generates without errors
# - Theme assets are bundled correctly
# Generates the complete static site in site/ and reports diagnostics.
# Warnings do not fail an ordinary build; use make check to enforce them.
#
# The site/ directory can be served by any static web server.
#
# Usage: make build
build:
uv run mkdocs build

# check: Build the site and enforce the pull-request documentation gate
check:
uv run --frozen --only-group docs python check_links.py

# deploy: Deploy site to GitHub Pages
#
# Builds the site and deploys it to the gh-pages branch using MkDocs' built-in
Expand All @@ -70,4 +71,4 @@ deploy:
#
# Usage: make clean
clean:
rm -rf site/
rm -rf site/
17 changes: 11 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ uv run --frozen python docs/check_links.py
uv run --frozen pytest tests/test_docs_build.py
```

The checker fails on MkDocs warnings and errors, including awesome-nav failures,
missing pages/images/anchors, and unrecognized or absolute links. Existing griffe
and autorefs warnings remain visible without failing the check; their errors
still fail. External URLs are not fetched. The read-only `docs-check.yml` workflow
The checker fails on logged MkDocs warnings and errors, including awesome-nav
failures, orphan pages, missing pages/images/anchors, broken API references, and
unrecognized or absolute links. It tolerates only the nine existing griffe/autorefs
warnings identified by logger, message and source location in `check_links.py`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: once the line numbers are gone, "identified by logger, message and source location" should read something like "identified by logger, file and message", and "changed messages/locations" on the next line becomes "changed messages".

They remain visible; changed messages/locations and all errors fail. Python
warnings such as `DeprecationWarning` are not routed into the gate. External URLs
are not fetched. Run `make check` from this directory for the same gate.
The read-only `docs-check.yml` workflow
runs for documentation, source, dependency, or checker-workflow changes and never
deploys the site. It installs only the docs group; the regular test workflow runs
deploys the site. Its `uv run --only-group docs` installs the docs group without
installing the project; the regular test workflow runs
the checker's tests.

## Deployment
Expand All @@ -85,4 +90,4 @@ Automatic deployment is configured in `.github/workflows/docs.yml`. The workflow

---

> **Note**: A `Makefile` is provided for convenience with targets: `install`, `docs`, `build`, `deploy`, and `clean`.
> **Note**: A `Makefile` is provided for convenience with targets: `install`, `docs`, `build`, `check`, `deploy`, and `clean`.
56 changes: 43 additions & 13 deletions docs/check_links.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
"""Build docs, failing on MkDocs diagnostics except known API warnings."""
"""Build docs, failing on logged MkDocs diagnostics except nine known warnings.

Python warnings (such as DeprecationWarning) are not routed into this gate.
"""

import argparse
import logging
import re
from pathlib import Path

from mkdocs.commands.build import build
from mkdocs.config import load_config
from mkdocs.exceptions import Abort
from mkdocs.exceptions import MkDocsException

# Issue #355's existing annotation warnings. Keep messages and source locations
# explicit: a changed diagnostic needs review, not a blanket plugin exemption.
_GRIFFE_WARNINGS = {
"griffe: src/stickler/structured_object_evaluator/" + warning
for warning in (
"bulk_structured_model_evaluator.py:965: No type or annotation for parameter 'df'",
"models/structured_model.py:1842: No type or annotation for parameter '**kwargs'",
"models/structured_model.py:1845: No type or annotation for returned value 1",
"models/comparable_field.py:102: No type or annotation for parameter '**field_kwargs'",
"models/comparable_field.py:105: No type or annotation for returned value 1",
"models/field.py:51: No type or annotation for parameter '**kwargs'",
)
}
_AUTOREFS_WARNING = re.compile(
r"mkdocs_autorefs: API-Reference/models\.md: from (?:.*?/)?"
r"src/stickler/structured_object_evaluator/models/structured_model\.py:262: "
r"\(stickler\.structured_object_evaluator\.models\.structured_model\.StructuredModel\) "
r"Could not find cross-reference target ''(?:tp|fd|derived)''"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should fix. The :<line> in these entries is what breaks on harmless edits. Repro: prepend # comment to structured_model.py. The warnings move to 1843/1846/263, and the check fails with 5 warnings even though no diagnostic changed.

Suggestion, keeping your "explicit, not a blanket exemption" intent:

  • Drop the line numbers from _GRIFFE_WARNINGS, and strip :<digits> from the incoming message in the re.sub at line 46, which already normalizes the path.
  • Use :\d+ instead of :262 in _AUTOREFS_WARNING.
  • Optionally, tolerate each known entry at most once, so a second copy of the same warning (say, a new **kwargs without an annotation in field.py) still counts.

Separately, and optional: the three autorefs warnings come from the unfenced >>> example at structured_model.py:412-414. Wrapping it in a ```python fence removes all three (we checked), and then _AUTOREFS_WARNING can go entirely.



class _LinkWarnings(logging.Handler):
Expand All @@ -15,16 +39,22 @@ def __init__(self):
self.count = 0

def emit(self, record):
# These sources emit the site's existing API annotation/cross-reference
# warnings. Errors remain fatal, including errors from these plugins.
if record.levelno == logging.WARNING and any(
record.name == name or record.name.startswith(name + ".")
for name in (
"mkdocs.plugins.griffe",
"mkdocs.plugins.mkdocs_autorefs",
)
):
return
message = record.getMessage().replace("\\", "/")
if record.levelno == logging.WARNING:
if record.name == "mkdocs.plugins.griffe":
# griffe uses absolute paths when invoked from docs/ (make check).
message = re.sub(
r"^griffe: (?:.*?/)?src/stickler/",
"griffe: src/stickler/",
message,
)
if message in _GRIFFE_WARNINGS:
return
if (
record.name == "mkdocs.plugins.mkdocs_autorefs._internal.plugin"
and _AUTOREFS_WARNING.fullmatch(message)
):
return
self.count += 1


Expand Down Expand Up @@ -64,7 +94,7 @@ def main() -> int:
logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s")
try:
return check_links(args.config_file, args.site_dir)
except Abort as error:
except MkDocsException as error:
logging.getLogger("mkdocs").error("%s", error)
return 1

Expand Down
1 change: 1 addition & 0 deletions docs/docs/Guides/.nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ nav:
- Comparators/
- Evaluation/
- Use-Cases/
- Document_Packet_Splitting.md
- Best-Practices/
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repo_name: awslabs/stickler
validation:
nav:
not_found: warn
Comment on lines +7 to +9

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should fix. nav.omitted_files is left at its default, info, so a page that's in docs/ but in no .nav.yml builds, can't be reached from navigation, and the check passes. There's one today. This build logs at INFO:

The following pages exist in the docs directory, but are not included in the "nav" configuration:
  - Guides/Document_Packet_Splitting.md

Adding omitted_files: warn under nav: catches it. You'll also need to either add that page to Guides/.nav.yml or explicitly exclude it, or the site won't pass its own check.

omitted_files: warn
links:
not_found: warn
anchors: warn
Expand Down
Loading