-
Notifications
You must be signed in to change notification settings - Fork 7
TOF-447: Add docs CI gates: frontmatter, links, redirects, code samples, OpenAPI #180
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d2aac6b
Initial plan
Copilot 24e2662
Add docs CI gates: frontmatter, code samples, links, redirects
Copilot 37a61cc
Fix false positives and false negatives in the docs CI gates
tylergoerzen-mxp f3f1fb2
Add OpenAPI gate, enforce description and unique titles, pin actions
tylergoerzen-mxp 9123aea
Merge origin/main into copilot/tof-447-add-docs-ci-gates
tylergoerzen-mxp 2df3572
Baseline existing violations so the gates only block new ones; reject…
tylergoerzen-mxp ec6590c
Stop tracking Python bytecode
tylergoerzen-mxp 92e9f36
Note the baseline in the workflow
tylergoerzen-mxp 09a6745
Fail wildcard redirect destinations that match no page
tylergoerzen-mxp 7bdfb92
Merge branch 'main' into copilot/tof-447-add-docs-ci-gates
tylergoerzen-mxp 2d6ee04
Merge origin/main into copilot/tof-447-add-docs-ci-gates
hywel-mixpanel 47c446a
Fix docs CI violations on pages added since the gates were written
hywel-mixpanel e8b2f12
Merge branch 'main' into copilot/tof-447-add-docs-ci-gates
hywel-mixpanel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Docs CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| concurrency: | ||
| group: docs-ci-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| checks: | ||
| name: Docs checks | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | ||
| with: | ||
| python-version: "3.12" | ||
| - name: Install OpenAPI validator | ||
| run: pip install --quiet pyyaml openapi-spec-validator | ||
| # continue-on-error is deliberately absent: each check is a hard gate. | ||
| # Violations that already existed on main are listed in | ||
| # scripts/docs-ci-baseline.json and don't fail; only new ones do. | ||
| # Steps run in order and the job reports the first failure. | ||
| - name: Check frontmatter | ||
| run: python scripts/check_frontmatter.py | ||
| - name: Check code samples | ||
| if: '!cancelled()' | ||
| run: python scripts/check_code_samples.py | ||
| - name: Check internal links | ||
| if: '!cancelled()' | ||
| run: python scripts/check_links.py | ||
| - name: Check redirects | ||
| if: '!cancelled()' | ||
| run: python scripts/check_redirects.py | ||
| - name: Check OpenAPI specs | ||
| if: '!cancelled()' | ||
| run: python scripts/check_openapi.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| .DS_Store | ||
| .vscode | ||
| __pycache__/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| CI gate: every fenced code block in MDX files must declare a language. | ||
|
|
||
| A fenced block opening looks like: | ||
| ```python | ||
| ```javascript | ||
| ```bash | ||
|
|
||
| A block with no language identifier: | ||
| ``` | ||
|
|
||
| will cause this check to fail. | ||
|
|
||
| Excluded directories (same as other checks): | ||
| - snippets/ | ||
| - openapi/ | ||
| """ | ||
|
|
||
| import sys | ||
| import glob | ||
| import os | ||
| import re | ||
|
|
||
| EXCLUDED_DIRS = {"snippets", "openapi"} | ||
|
|
||
| def check_file(path: str, display: str) -> list[str]: | ||
| errors = [] | ||
| with open(path, encoding="utf-8") as fh: | ||
| content = fh.read() | ||
|
|
||
| fence_len = 0 # 0 = outside a block; otherwise the opening fence's length | ||
| for lineno, line in enumerate(content.splitlines(), 1): | ||
| stripped = line.strip() | ||
| if not stripped.startswith("```"): | ||
| continue | ||
| ticks = len(stripped) - len(stripped.lstrip("`")) | ||
| rest = stripped[ticks:].strip() | ||
| if fence_len: | ||
| # Only a bare fence at least as long as the opener closes the block, | ||
| # so a ```python block nested inside ````mdx does not end it early. | ||
| if ticks >= fence_len and not rest: | ||
| fence_len = 0 | ||
| continue | ||
| if not rest: | ||
| errors.append( | ||
| f"{display}:{lineno}: code block is missing a language identifier" | ||
| ) | ||
| fence_len = ticks | ||
|
|
||
| return errors | ||
|
|
||
|
|
||
| def is_excluded(path: str) -> bool: | ||
| parts = path.replace(os.sep, "/").split("/") | ||
| return any(part in EXCLUDED_DIRS for part in parts) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
| mdx_files = glob.glob(os.path.join(root, "**", "*.mdx"), recursive=True) | ||
|
|
||
| checked = 0 | ||
| all_errors: list[str] = [] | ||
| for path in sorted(mdx_files): | ||
| rel = os.path.relpath(path, root) | ||
| if is_excluded(rel): | ||
| continue | ||
| all_errors.extend(check_file(path, rel)) | ||
| checked += 1 | ||
|
|
||
| if all_errors: | ||
| print("Code-sample check FAILED:") | ||
| for err in all_errors: | ||
| print(f" {err}") | ||
| return 1 | ||
|
|
||
| print(f"Code-sample check PASSED ({checked} files checked).") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| CI gate: every MDX page needs a non-empty title and description in its YAML | ||
| front-matter, and no two pages may share a title. | ||
|
|
||
| Known violations on main are listed in docs-ci-baseline.json (see | ||
| ci_baseline.py); only new violations fail the check. | ||
|
|
||
| Directories that are intentionally excluded from the check: | ||
| - snippets/ (reusable MDX components, not standalone pages) | ||
| - links/ (external-link stubs that use 'url' instead of a body) | ||
| - openapi/ (OpenAPI spec files, not MDX pages) | ||
| """ | ||
|
|
||
| import re | ||
| import sys | ||
| import glob | ||
| import os | ||
|
|
||
| from ci_baseline import report | ||
|
|
||
| EXCLUDED_DIRS = {"snippets", "links", "openapi"} | ||
|
|
||
| FRONTMATTER_RE = re.compile(r"^---\s*\n(.*?)\n---", re.DOTALL) | ||
|
|
||
|
|
||
| def check_file(path: str, display: str) -> tuple[list[str], str | None]: | ||
| """Return (errors, title). Title is None when absent or empty.""" | ||
| errors = [] | ||
| with open(path, encoding="utf-8") as fh: | ||
| content = fh.read() | ||
|
|
||
| m = FRONTMATTER_RE.match(content) | ||
| if not m: | ||
| errors.append(f"{display}: missing front-matter block") | ||
| return errors, None | ||
|
|
||
| fm = m.group(1) | ||
| title = None | ||
| title_match = re.search(r"^\s*title\s*:\s*(.*)$", fm, re.MULTILINE) | ||
| if not title_match: | ||
| errors.append(f"{display}: front-matter is missing required 'title' field") | ||
| else: | ||
| title = title_match.group(1).strip().strip("\"'") | ||
| if not title: | ||
| errors.append(f"{display}: front-matter 'title' is empty") | ||
| title = None | ||
|
|
||
| # A description is what search results and llms.txt entries render, so a | ||
| # page without one is invisible to both. | ||
| desc_match = re.search(r"^\s*description\s*:\s*(.*)$", fm, re.MULTILINE) | ||
| if not desc_match: | ||
| errors.append(f"{display}: front-matter is missing required 'description' field") | ||
| elif not desc_match.group(1).strip().strip("\"'"): | ||
| errors.append(f"{display}: front-matter 'description' is empty") | ||
|
|
||
| return errors, title | ||
|
|
||
|
|
||
| def is_excluded(path: str) -> bool: | ||
| parts = path.replace(os.sep, "/").split("/") | ||
| return any(part in EXCLUDED_DIRS for part in parts) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
| mdx_files = glob.glob(os.path.join(root, "**", "*.mdx"), recursive=True) | ||
|
|
||
| checked = 0 | ||
| all_errors: list[str] = [] | ||
| titles: dict[str, list[str]] = {} | ||
| for path in sorted(mdx_files): | ||
| rel = os.path.relpath(path, root) | ||
| if is_excluded(rel): | ||
| continue | ||
| errors, title = check_file(path, rel) | ||
| all_errors.extend(errors) | ||
| if title: | ||
| titles.setdefault(title, []).append(rel) | ||
| checked += 1 | ||
|
|
||
| # Two pages sharing a rendered title are indistinguishable in search | ||
| # results and to answer engines. One entry per page (not per group) keeps | ||
| # baseline entries stable when a group shrinks during cleanup. | ||
| for title, pages in sorted(titles.items()): | ||
| if len(pages) > 1: | ||
| for page in sorted(pages): | ||
| all_errors.append(f'{page}: title "{title}" is also used by another page') | ||
|
|
||
| return report("frontmatter", "Frontmatter check", all_errors, f"{checked} files checked") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.