-
Notifications
You must be signed in to change notification settings - Fork 23
152 lines (130 loc) · 4.25 KB
/
notebooks.yml
File metadata and controls
152 lines (130 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# GitHub Actions workflow for executing Jupyter notebooks
# Runs on pull requests and nightly to ensure notebooks work correctly
name: Notebooks
on:
push:
branches: [main, master]
paths:
- 'notebooks/**'
- 'boxcrete/**'
- 'pyproject.toml'
- '.github/workflows/notebooks.yml'
pull_request:
branches: [main, master]
paths:
- 'notebooks/**'
- 'boxcrete/**'
- 'pyproject.toml'
- '.github/workflows/notebooks.yml'
schedule:
# Run nightly at 3:00 AM UTC
- cron: '0 3 * * *'
workflow_dispatch:
jobs:
execute-notebooks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.10']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[notebooks]"
- name: Install Jupyter kernel
run: |
python -m ipykernel install --user --name python3
- name: Execute notebooks
run: |
python - << 'PYEOF'
import subprocess, sys
from pathlib import Path
notebooks = sorted(Path("notebooks").glob("*.ipynb"))
failed = []
for nb in notebooks:
print(f"{'=' * 40}")
print(f"Executing: {nb}")
print(f"{'=' * 40}")
result = subprocess.run(
[
sys.executable, "-m", "jupyter", "nbconvert",
"--to", "notebook",
"--execute",
"--inplace",
"--ExecutePreprocessor.timeout=600",
"--ExecutePreprocessor.kernel_name=python3",
str(nb),
],
capture_output=False,
)
if result.returncode != 0:
failed.append(str(nb))
print(f"❌ Failed: {nb}")
else:
print(f"✅ Successfully executed: {nb}")
print()
if failed:
print(f"\n{len(failed)} notebook(s) failed:")
for f in failed:
print(f" - {f}")
sys.exit(1)
else:
print(f"\nAll {len(notebooks)} notebook(s) executed successfully.")
PYEOF
- name: Upload executed notebooks as artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: executed-notebooks
path: notebooks/*.ipynb
retention-days: 7
notebook-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nbformat
- name: Validate notebook format
run: |
python - << 'EOF'
import nbformat
import sys
from pathlib import Path
notebooks = list(Path('notebooks').glob('*.ipynb'))
errors = []
for nb_path in notebooks:
try:
with open(nb_path, 'r', encoding='utf-8') as f:
nb = nbformat.read(f, as_version=4)
print(f"✅ Valid notebook: {nb_path}")
except Exception as e:
errors.append(f"❌ Invalid notebook {nb_path}: {e}")
print(errors[-1])
if errors:
print(f"\n{len(errors)} notebook(s) failed validation.")
sys.exit(1)
else:
print(f"\nAll {len(notebooks)} notebook(s) are valid.")
EOF