Skip to content

Commit a3453ef

Browse files
FBumannclaude
andcommitted
ci: Speedup notebook execution (#551)
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f76ea9e commit a3453ef

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/docs.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,33 @@ jobs:
5757
- name: Install dependencies
5858
run: uv pip install --system ".[docs,full]"
5959

60+
- name: Get notebook cache key
61+
id: notebook-cache-key
62+
run: |
63+
set -eo pipefail
64+
# Hash notebooks + flixopt source code using null-delimited find for safety
65+
HASH=$({ find docs/notebooks -name '*.ipynb' -print0; find flixopt -name '*.py' -print0; } | sort -z | xargs -0 tar -cf - 2>/dev/null | sha256sum | cut -d' ' -f1)
66+
echo "hash=$HASH" >> $GITHUB_OUTPUT
67+
68+
- name: Cache executed notebooks
69+
uses: actions/cache@v4
70+
id: notebook-cache
71+
with:
72+
path: docs/notebooks/**/*.ipynb
73+
key: notebooks-${{ steps.notebook-cache-key.outputs.hash }}
74+
75+
- name: Execute notebooks in parallel
76+
if: steps.notebook-cache.outputs.cache-hit != 'true'
77+
run: |
78+
set -eo pipefail
79+
# Execute all notebooks in parallel (4 at a time)
80+
# Run from notebooks directory so relative imports work
81+
cd docs/notebooks && find . -name '*.ipynb' -print0 | \
82+
xargs -0 -P 4 -I {} sh -c 'jupyter execute --inplace "$1" || exit 255' _ {}
83+
6084
- name: Build docs
85+
env:
86+
MKDOCS_JUPYTER_EXECUTE: "false"
6187
run: mkdocs build --strict
6288

6389
- uses: actions/upload-artifact@v4
@@ -95,12 +121,36 @@ jobs:
95121
- name: Install dependencies
96122
run: uv pip install --system ".[docs,full]"
97123

124+
- name: Get notebook cache key
125+
id: notebook-cache-key
126+
run: |
127+
set -eo pipefail
128+
# Hash notebooks + flixopt source code using null-delimited find for safety
129+
HASH=$({ find docs/notebooks -name '*.ipynb' -print0; find flixopt -name '*.py' -print0; } | sort -z | xargs -0 tar -cf - 2>/dev/null | sha256sum | cut -d' ' -f1)
130+
echo "hash=$HASH" >> $GITHUB_OUTPUT
131+
132+
- name: Cache executed notebooks
133+
uses: actions/cache@v4
134+
id: notebook-cache
135+
with:
136+
path: docs/notebooks/**/*.ipynb
137+
key: notebooks-${{ steps.notebook-cache-key.outputs.hash }}
138+
139+
- name: Execute notebooks in parallel
140+
if: steps.notebook-cache.outputs.cache-hit != 'true'
141+
run: |
142+
set -eo pipefail
143+
cd docs/notebooks && find . -name '*.ipynb' -print0 | \
144+
xargs -0 -P 4 -I {} sh -c 'jupyter execute --inplace "$1" || exit 255' _ {}
145+
98146
- name: Configure Git
99147
run: |
100148
git config user.name "github-actions[bot]"
101149
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
102150
103151
- name: Deploy docs
152+
env:
153+
MKDOCS_JUPYTER_EXECUTE: "false"
104154
run: |
105155
VERSION=${{ inputs.version }}
106156
VERSION=${VERSION#v}

0 commit comments

Comments
 (0)