Skip to content
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

feat(ci): add reference check for all markdown files #14

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
27 changes: 18 additions & 9 deletions .github/scripts/check_doc_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@ def get_created_md_files():

return created_files

def get_all_md_files():
"""
Recursively collects all Markdown (.md, .mdx) files under /docusaurus/docs.
Returns:
list[Path]: A list of relative paths to all Markdown files in the docs directory.
"""
return [
path.relative_to(REPO_ROOT)
for path in DOCS_DIR.rglob("*.md*")
if path.is_file()
]

def is_file_referenced(file_path):
"""
Checks if a given file is referenced in the Git repository.
This function searches the Git repository for occurrences of the file name
and determines if the file is referenced in any other files.
Args:
file_path (Path): The path to the file to check.
Returns:
Expand All @@ -52,16 +62,15 @@ def is_file_referenced(file_path):
return len(matches) > 0

def main():
created_files = get_created_md_files()
if not created_files:
print("No new Markdown files detected.")
return

print(f"Checking {len(created_files)} new Markdown files...")
md_files = get_created_md_files()
if not md_files:
print("No new Markdown files detected. Checking all Markdown files instead.")
md_files = get_all_md_files()
print(f"Checking {len(md_files)} Markdown files...")

unreferenced = []

for md_file in created_files:
for md_file in md_files:
if not is_file_referenced(md_file):
unreferenced.append(md_file)

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-references.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Run reference check
run: |
pip install --upgrade pip
python scripts/check_doc_references.py
python .github/scripts/check_doc_references.py