diff --git a/.github/workflows/verify_index.yml b/.github/workflows/verify_index.yml new file mode 100644 index 0000000..46ec784 --- /dev/null +++ b/.github/workflows/verify_index.yml @@ -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 diff --git a/scripts/verify_index.py b/scripts/verify_index.py new file mode 100644 index 0000000..56c0ed0 --- /dev/null +++ b/scripts/verify_index.py @@ -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)