Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
5 changes: 5 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ CI/CD workflows for the Stickler project.
| `security.yaml` | push, PR | Bandit + ASH security scans; uploads `security-reports` artifact |
| `security-pr-comment.yaml` | `workflow_run` after Security Scan | Posts/updates the ASH summary as a PR comment |
| `docs.yml` | push to `main` (src/docs paths) | Deploys MkDocs site to GitHub Pages |
| `docs-check.yml` | PR (docs/source/dependency/workflow paths) | Builds docs with the docs group and rejects link/navigation diagnostics; cancels superseded builds; no deployment |
| `workflow.yml` | release published | Builds and publishes to PyPI and TestPyPI (trusted publishing via OIDC) |

## 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
31 changes: 31 additions & 0 deletions .github/workflows/docs-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check Documentation

on:
pull_request:
paths:
Comment on lines +4 to +5

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, 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.md saying this check must stay non-required (or a paths-filter step that always reports) would prevent the surprise.

- '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
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/
26 changes: 24 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,29 @@ Verify the site builds without errors:
uv run mkdocs build
```

This generates the static site in `site/` and validates all internal links and references.
This generates the static site in `site/` and reports link diagnostics. An ordinary
build does not fail on warnings; use the checker below to enforce them. Link
validation levels are shared in `mkdocs.yml`, so `mkdocs serve` shows them too.

To run the pull-request check from the repository root:

```bash
uv run --frozen python docs/check_links.py
uv run --frozen pytest tests/test_docs_build.py
```

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. 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 @@ -68,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`.
103 changes: 103 additions & 0 deletions docs/check_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""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 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):
def __init__(self):
super().__init__(level=logging.WARNING)
self.count = 0

def emit(self, record):
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


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

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.

Non-blocking. This re-creates the CLI's build sequence but skips its _enable_warnings(), so Python DeprecationWarnings from mkdocs or plugins never reach the mkdocs logger and aren't counted. That's a difference from mkdocs build --strict, which counts them, and the module docstring says this fails on MkDocs diagnostics. Worth either routing them the same way or noting the difference.

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())
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/
13 changes: 12 additions & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
unrecognized_links: warn
absolute_links: warn

theme:
name: material
palette:
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pytest tests/ -n auto
```
tests/
├── test_top_level_exports.py # Top-level package re-exports
├── test_docs_build.py # Real MkDocs link-check acceptance builds
├── structured_object_evaluator/ # Core evaluation tests
│ ├── test_structured_model.py # StructuredModel tests
│ ├── test_comparators.py # Comparator integration
Expand Down
Loading