Skip to content

Commit 4d5d952

Browse files
Add GH action
1 parent f50c286 commit 4d5d952

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

.github/workflows/notebooks.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Validate notebooks
2+
3+
on:
4+
push:
5+
paths:
6+
- "examples/**/*.ipynb"
7+
- "data/**"
8+
- "requirements.txt"
9+
- ".github/workflows/notebooks.yml"
10+
pull_request:
11+
paths:
12+
- "examples/**/*.ipynb"
13+
- "data/**"
14+
- "requirements.txt"
15+
- ".github/workflows/notebooks.yml"
16+
workflow_dispatch:
17+
18+
jobs:
19+
notebooks:
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 15
22+
23+
steps:
24+
- name: Check out repository
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: "3.11"
31+
cache: "pip"
32+
cache-dependency-path: requirements.txt
33+
34+
- name: Install dependencies
35+
run: |
36+
python -m pip install --upgrade pip
37+
pip install -r requirements.txt
38+
39+
- name: Execute notebooks
40+
run: |
41+
python - <<'PY'
42+
from pathlib import Path
43+
import nbformat
44+
from nbclient import NotebookClient
45+
46+
notebooks = sorted(Path("examples").rglob("*.ipynb"))
47+
if not notebooks:
48+
raise SystemExit("No notebooks found under examples/")
49+
50+
for notebook_path in notebooks:
51+
print(f"Executing {notebook_path}...")
52+
with notebook_path.open(encoding="utf-8") as f:
53+
notebook = nbformat.read(f, as_version=4)
54+
55+
client = NotebookClient(
56+
notebook,
57+
timeout=600,
58+
kernel_name="python3",
59+
resources={"metadata": {"path": str(notebook_path.parent)}},
60+
)
61+
client.execute()
62+
63+
print(f"Validated {len(notebooks)} notebook(s).")
64+
PY

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
numpy
2+
pandas
3+
scikit-learn
4+
jupyterlab
5+
nbclient
6+
nbformat
7+
ipykernel

0 commit comments

Comments
 (0)