Repository navigation
fix: check documentation links on pull requests #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
26a3baa
63da7e1
36fb938
ac23eae
e57a48d
de3dfd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Check Documentation | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'docs/**' | ||
| - 'src/**' | ||
| - 'pyproject.toml' | ||
| - 'uv.lock' | ||
| - '.github/workflows/docs-check.yml' | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Set up uv | ||
| uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 | ||
| with: | ||
| python-version: "3.12" | ||
| - name: Build and check documentation links | ||
| run: uv run --frozen --only-group docs python docs/check_links.py | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """Build docs, tolerating each of six known annotation warnings once per build. | ||
|
|
||
| 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 MkDocsException | ||
|
|
||
| # Issue #355's existing annotation warnings. Files and messages stay explicit; | ||
| # line numbers can move without changing the diagnostic. | ||
| _GRIFFE_WARNINGS = { | ||
| "griffe: src/stickler/structured_object_evaluator/" + warning | ||
| for warning in ( | ||
| "bulk_structured_model_evaluator.py: No type or annotation for parameter 'df'", | ||
| "models/structured_model.py: No type or annotation for parameter '**kwargs'", | ||
| "models/structured_model.py: No type or annotation for returned value 1", | ||
| "models/comparable_field.py: No type or annotation for parameter '**field_kwargs'", | ||
| "models/comparable_field.py: No type or annotation for returned value 1", | ||
| "models/field.py: No type or annotation for parameter '**kwargs'", | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| class _LinkWarnings(logging.Handler): | ||
| def __init__(self): | ||
| super().__init__(level=logging.WARNING) | ||
| self.count = 0 | ||
| self.remaining_warnings = _GRIFFE_WARNINGS.copy() | ||
|
|
||
| def emit(self, record): | ||
| message = record.getMessage().replace("\\", "/") | ||
| if record.levelno == logging.WARNING and record.name == "mkdocs.plugins.griffe": | ||
| # griffe uses absolute paths when invoked from docs/ (make check). | ||
| message = re.sub( | ||
| r"^griffe: (?:.*?/)?(src/stickler/[^:]+):\d+: ", | ||
| r"griffe: \1: ", | ||
| message, | ||
| ) | ||
| if message in self.remaining_warnings: | ||
| self.remaining_warnings.remove(message) | ||
| return | ||
| self.count += 1 | ||
|
|
||
|
|
||
| def check_links(config_file: str, site_dir: str | None = None) -> int: | ||
| """Build a site and return nonzero for broken links; build errors propagate.""" | ||
| counter = _LinkWarnings() | ||
| logger = logging.getLogger("mkdocs") | ||
| logger.addHandler(counter) | ||
| try: | ||
| # Configuration and plugin loading can emit warnings before build(). | ||
| config = load_config(config_file=config_file, site_dir=site_dir) | ||
| config.plugins.on_startup(command="build", dirty=False) | ||
| try: | ||
| build(config) | ||
|
Comment on lines
+59
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking. This re-creates the CLI's build sequence but skips its |
||
| finally: | ||
| config.plugins.on_shutdown() | ||
| finally: | ||
| logger.removeHandler(counter) | ||
| counter.close() | ||
| if counter.count: | ||
| logger.error( | ||
| "Documentation check failed: %d warning(s) or error(s).", | ||
| counter.count, | ||
| ) | ||
| return 1 | ||
| return 0 | ||
|
|
||
|
|
||
| def main() -> int: | ||
| """Run the same build-only check locally and in pull-request CI.""" | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument( | ||
| "-f", "--config-file", default=str(Path(__file__).with_name("mkdocs.yml")) | ||
| ) | ||
| parser.add_argument("-d", "--site-dir") | ||
| args = parser.parse_args() | ||
| logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s") | ||
| try: | ||
| return check_links(args.config_file, args.site_dir) | ||
| except MkDocsException as error: | ||
| logging.getLogger("mkdocs").error("%s", error) | ||
| return 1 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ nav: | |
| - Comparators/ | ||
| - Evaluation/ | ||
| - Use-Cases/ | ||
| - Document_Packet_Splitting.md | ||
| - Best-Practices/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,17 @@ site_url: https://awslabs.github.io/stickler/ | |
| repo_url: https://github.com/awslabs/stickler | ||
| repo_name: awslabs/stickler | ||
|
|
||
| # Use the same diagnostics in local serve/build and the PR checker. | ||
| validation: | ||
| nav: | ||
| not_found: warn | ||
|
Comment on lines
+7
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should fix. Adding |
||
| omitted_files: warn | ||
| links: | ||
| not_found: warn | ||
| anchors: warn | ||
| unrecognized_links: warn | ||
| absolute_links: warn | ||
|
|
||
| theme: | ||
| name: material | ||
| palette: | ||
|
|
@@ -71,4 +82,4 @@ plugins: | |
| extra_javascript: | ||
| # Workaround for site_url breaking mermaid rendering; see the following for more info: | ||
| # https://github.com/squidfunk/mkdocs-material/issues/3742#issuecomment-1076068038 | ||
| - https://unpkg.com/mermaid@11/dist/mermaid.min.js | ||
| - https://unpkg.com/mermaid@11/dist/mermaid.min.js | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, for the future. With
paths:, PRs outside those paths never report this check. That's fine today, but if "Check Documentation" is ever made a required status check, those PRs will wait forever. A line in.github/workflows/README.mdsaying this check must stay non-required (or a paths-filter step that always reports) would prevent the surprise.