Skip to content

Commit bd40e6c

Browse files
committed
gha: execute notebooks on github
1 parent 7ba0566 commit bd40e6c

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# .github/workflows/execute-notebooks.yml
2+
name: Execute Notebooks
3+
4+
on:
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- 'docs/Data Formatting/*ipynb'
9+
- 'docs/*ipynb'
10+
- '.github/workflows/execute_notebooks.yml'
11+
pull_request:
12+
branches: [ main ]
13+
paths:
14+
- 'docs/Data Formatting/*ipynb'
15+
- 'docs/*ipynb'
16+
workflow_dispatch: # Allow manual trigger
17+
18+
jobs:
19+
execute-notebooks:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
fetch-depth: 0
28+
29+
- name: Set up Python
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: '3.12'
33+
cache: 'pip'
34+
35+
- name: Install dependencies
36+
run: |
37+
# Install system dependencies
38+
sudo apt update
39+
sudo apt install pandoc
40+
41+
# Install Python dependencies
42+
python -m pip install --upgrade pip
43+
pip install jupyter nbconvert nbformat
44+
pip install -r requirements.txt
45+
pip install ipykernel rdkit cairosvg pymzml
46+
pip install .
47+
48+
- name: Configure git
49+
run: |
50+
git config --local user.email "action@github.com"
51+
git config --local user.name "GitHub Action"
52+
53+
- name: Find and execute notebooks
54+
run: |
55+
# Find all notebooks that need to execute (adjust paths as needed)
56+
find docs/Data Formatting/*ipynb -name "*.ipynb" > notebooks_to_execute.txt
57+
docs/Getting\ Started.ipynb > notebooks_to_execute.txt
58+
59+
echo "Found notebooks:"
60+
cat notebooks_to_execute.txt
61+
62+
# Execute each notebook
63+
while IFS= read -r notebook; do
64+
echo "Executing: $notebook"
65+
# Clear outputs first (optional)
66+
jupyter nbconvert --clear-output --inplace "$notebook"
67+
# Execute notebook
68+
jupyter nbconvert --execute --to notebook --inplace "$notebook" \
69+
--ExecutePreprocessor.timeout=300 \
70+
--ExecutePreprocessor.kernel_name=python3
71+
72+
# Check if execution was successful
73+
if [ $? -eq 0 ]; then
74+
echo "✓ Successfully executed: $notebook"
75+
else
76+
echo "✗ Failed to execute: $notebook"
77+
exit 1
78+
fi
79+
done < notebooks_to_execute.txt
80+
- name: Push changes
81+
if: steps.verify-changed-files.outputs.changed == 'true' && github.event_name != 'pull_request'
82+
run: |
83+
git push origin ${{ github.ref_name }}
84+
85+
- name: Summary
86+
run: |
87+
if [ "${{ steps.verify-changed-files.outputs.changed }}" == "true" ]; then
88+
echo "✅ Notebooks executed successfully and changes committed"
89+
else
90+
echo "✅ Notebooks executed successfully, no changes to commit"
91+
fi

0 commit comments

Comments
 (0)