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

Add script and workflow to verify index.toml #127

Merged
merged 3 commits into from
Sep 20, 2024
Merged
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
21 changes: 21 additions & 0 deletions .github/workflows/verify_index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Verify index

on:
pull_request:
paths:
- "notebook/*.ipynb"
- "index.toml"

jobs:
verify-index:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Verify index content
run: python scripts/verify_index.py
43 changes: 43 additions & 0 deletions scripts/verify_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from pathlib import Path

import tomllib

if __name__ == "__main__":
root_path = Path(__file__).parent.parent

index_file = root_path / "index.toml"
index_data = tomllib.loads(index_file.read_text())

notebooks = list(root_path.glob("notebooks/*.ipynb"))

failed = False
indexed_notebooks = [
notebook["notebook"]
for notebook in index_data["cookbook"]
if "notebook" in notebook
]
for notebook in notebooks:
if notebook.name not in indexed_notebooks:
print(f"Notebook '{notebook.name}' not found in 'index.toml'")
failed = True

for notebook in index_data["cookbook"]:
if "notebook" not in notebook:
print(f"Notebook '{notebook}' has no file")
failed = True
continue

if not (root_path / f"notebooks/{notebook['notebook']}").exists():
print(f"Notebook '{notebook['notebook']}' file not found")
failed = True

if "title" not in notebook:
print(f"Notebook '{notebook['notebook']}' has no title")
failed = True

if not notebook.get("topics"):
print(f"Notebook '{notebook['notebook']}' has no topics")
failed = True

if failed:
exit(1)