Skip to content

Commit a859cb5

Browse files
authored
Merge pull request #431 from predictive-clinical-neuroscience/maint/run_notebooks_action_and_skill
enh - create github action to run all notebooks
2 parents 78cf982 + 84e7b67 commit a859cb5

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Manually execute all tutorial notebooks and commit the results.
2+
#
3+
# Trigger: manual only.
4+
# - Open the Actions tab, select "Run Notebooks", click "Run workflow".
5+
# - Pick the branch you want to run against (e.g. your PR branch).
6+
# - Tick "Dry run" to execute notebooks without committing anything.
7+
#
8+
# The workflow stops immediately if any notebook fails.
9+
# The failing notebook name and cell error are printed in the log.
10+
# Nothing is committed unless every notebook succeeds.
11+
#
12+
# Notebook 08_cluster.ipynb is always skipped — it requires SLURM.
13+
14+
name: Run Notebooks
15+
16+
on:
17+
workflow_dispatch:
18+
inputs:
19+
dry_run:
20+
description: >
21+
Dry run — execute notebooks but do NOT commit results back.
22+
required: false
23+
type: boolean
24+
default: false
25+
26+
permissions:
27+
contents: write # required to push committed outputs back
28+
29+
jobs:
30+
run-notebooks:
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
# ── 1. Checkout ────────────────────────────────────────────
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
with:
38+
# persist-credentials lets the final push step use the
39+
# built-in GITHUB_TOKEN — no personal access token needed.
40+
persist-credentials: true
41+
42+
# ── 2. Python ──────────────────────────────────────────────
43+
- name: Set up Python 3.12
44+
uses: actions/setup-python@v5
45+
with:
46+
python-version: "3.12"
47+
48+
# ── 3. System dependencies ─────────────────────────────────
49+
- name: Install pandoc
50+
# pandoc is required by nbconvert --to rst, which is called
51+
# by doc/convert_notebooks.py in step 6.
52+
run: sudo apt-get install -y pandoc
53+
54+
# ── 4. Python dependencies ─────────────────────────────────
55+
- name: Install Python dependencies
56+
run: |
57+
# Install the package plus its dev extras, then add
58+
# papermill for notebook execution.
59+
pip install -e ".[dev]"
60+
pip install papermill
61+
62+
# ── 5. Execute all notebooks ───────────────────────────────
63+
- name: Execute notebooks
64+
run: |
65+
# Loop over every notebook in examples/, skipping the
66+
# cluster notebook which requires SLURM and cannot run
67+
# in a GitHub Actions environment.
68+
FAILED=0
69+
for nb in examples/*.ipynb; do
70+
if [[ "$nb" == *"08_cluster"* ]]; then
71+
echo "Skipping (SLURM-only): $nb"
72+
continue
73+
fi
74+
75+
echo "Running: $nb"
76+
77+
# papermill executes the notebook in-place and prints
78+
# the failing cell + Python traceback on error.
79+
papermill "$nb" "$nb" \
80+
--execution-timeout 3600 \
81+
--request-save-on-cell-execute \
82+
|| { echo "FAILED: $nb"; FAILED=1; break; }
83+
84+
echo "Done: $nb"
85+
done
86+
87+
# Exit with failure so GitHub Actions marks the job red
88+
# and shows the error prominently.
89+
exit $FAILED
90+
91+
# ── 6. Convert notebooks to RST ───────────────────────────
92+
- name: Convert notebooks to RST
93+
# Regenerate all RST files from the freshly executed .ipynb
94+
# files so the website outputs are up to date.
95+
run: python doc/convert_notebooks.py
96+
97+
# ── 7. Commit and push ─────────────────────────────────────
98+
- name: Commit generated outputs
99+
if: ${{ github.event.inputs.dry_run == 'false' }}
100+
run: |
101+
git config --global user.name "github-actions[bot]"
102+
git config --global user.email \
103+
"github-actions[bot]@users.noreply.github.com"
104+
105+
# Stage the executed notebooks and the generated RST files.
106+
git add examples/ doc/pages/tutorials/
107+
108+
# Commit only if there are staged changes; exit cleanly
109+
# if nothing changed (idempotent re-runs are safe).
110+
if git diff --staged --quiet; then
111+
echo "Nothing changed — no commit needed."
112+
else
113+
git commit -m \
114+
"chore: update executed notebook outputs [skip ci]"
115+
git push
116+
fi

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ pcntoolkit.egg-info
7272
# Overrule for github folder
7373
!.github
7474

75+
# ignore agent skills for copilot
76+
.github/skills/
77+
7578
# Dist folder
7679
dist/pcntoolkit-0.30.post2-py3.12.egg
7780
dist/*

0 commit comments

Comments
 (0)