-
Notifications
You must be signed in to change notification settings - Fork 2
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
Draft
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/tof-447-add-docs-ci-gates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 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 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,44 @@ | ||
| 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. | ||
| # 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
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()) | ||
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.