Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions .github/workflows/check-colab-notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
Expand All @@ -32,19 +34,45 @@ jobs:
- name: Install dependencies
run: uv sync --all-packages --group notebooks --group docs

- name: Get changed notebook sources
id: changed
env:
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
run: |
if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
exit 0
fi

files=()
while IFS= read -r source_path; do
files+=("${source_path##*/}")
done < <(git diff --no-renames --name-only --diff-filter=ACDMT "$BASE_SHA" "$GITHUB_SHA" -- 'docs/notebook_source/*.py')

deleted=()
while IFS= read -r source_path; do
deleted+=("${source_path##*/}")
done < <(git diff --no-renames --name-only --diff-filter=D "$BASE_SHA" "$GITHUB_SHA" -- 'docs/notebook_source/*.py')

echo "files=${files[*]}" >> "$GITHUB_OUTPUT"
echo "deleted=${deleted[*]}" >> "$GITHUB_OUTPUT"
Comment thread
andreatnvidia marked this conversation as resolved.
Outdated

- name: Generate Colab notebooks
env:
DELETED_FILES: ${{ steps.changed.outputs.deleted }}
FILES: ${{ steps.changed.outputs.files }}
run: |
make generate-colab-notebooks
for file in $DELETED_FILES; do
rm -f "docs/colab_notebooks/${file%.py}.ipynb"
done
make generate-colab-notebooks FILES="$FILES"

- name: Check for differences
run: |
# Get the diff, filtering out cell ID changes (which are randomly generated)
# Filter out: file markers (--- and +++), and "id" lines
# Jupytext assigns random cell IDs, so ignore ID-only changes.
git add -N docs/colab_notebooks/
MEANINGFUL_DIFF=$(git diff docs/colab_notebooks/ | grep -E '^[+-]' | grep -v '^---' | grep -v '^+++' | grep -vE '^[+-]\s*"id": "[0-9a-fA-F]+",?$' || true)
Comment thread
andreatnvidia marked this conversation as resolved.

if [ -z "$MEANINGFUL_DIFF" ]; then
echo "βœ… Colab notebooks are up-to-date (ignoring cell ID changes)"
else
if [ -n "$MEANINGFUL_DIFF" ]; then
echo "❌ Colab notebooks are out of sync with source files"
echo ""
echo "The generated notebooks differ from the committed ones."
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,11 @@ endif

generate-colab-notebooks:
@echo "πŸ““ Generating Colab-compatible notebooks ($(DOCS_PYTHON))..."
ifdef FILES
$(DOCS_PYTHON) docs/scripts/generate_colab_notebooks.py --files $(FILES)
else
$(DOCS_PYTHON) docs/scripts/generate_colab_notebooks.py
endif
@echo "βœ… Colab notebooks created in docs/colab_notebooks/"

generate-fern-notebooks:
Expand Down
Loading