Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 35 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,46 @@ 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
echo "full=true" >> "$GITHUB_OUTPUT"
exit 0
fi

while IFS= read -r -d '' source_path; do
printf '%s\0' "${source_path##*/}"
done < <(git diff --no-renames --name-only -z --diff-filter=ACDMT "$BASE_SHA" "$GITHUB_SHA" -- 'docs/notebook_source/*.py') > "$RUNNER_TEMP/changed-notebook-sources"

while IFS= read -r -d '' source_path; do
printf '%s\0' "${source_path##*/}"
done < <(git diff --no-renames --name-only -z --diff-filter=D "$BASE_SHA" "$GITHUB_SHA" -- 'docs/notebook_source/*.py') > "$RUNNER_TEMP/deleted-notebook-sources"

- name: Generate Colab notebooks
env:
FULL_REGENERATION: ${{ steps.changed.outputs.full }}
run: |
make generate-colab-notebooks
if [ "$FULL_REGENERATION" = "true" ]; then
make generate-colab-notebooks
exit 0
fi

while IFS= read -r -d '' file; do
rm -f "docs/colab_notebooks/${file%.py}.ipynb"
done < "$RUNNER_TEMP/deleted-notebook-sources"

make generate-colab-notebooks FILES_FILE="$RUNNER_TEMP/changed-notebook-sources"

- 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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,13 @@ endif

generate-colab-notebooks:
@echo "πŸ““ Generating Colab-compatible notebooks ($(DOCS_PYTHON))..."
ifdef FILES_FILE
@if [ -s "$(FILES_FILE)" ]; then \
xargs -0 -n 1 $(DOCS_PYTHON) docs/scripts/generate_colab_notebooks.py --files < "$(FILES_FILE)"; \
fi
else
$(DOCS_PYTHON) docs/scripts/generate_colab_notebooks.py
endif
@echo "βœ… Colab notebooks created in docs/colab_notebooks/"

generate-fern-notebooks:
Expand Down
Loading