diff --git a/.github/workflows/check-colab-notebooks.yml b/.github/workflows/check-colab-notebooks.yml index 70a6eaade..dbf28f8a8 100644 --- a/.github/workflows/check-colab-notebooks.yml +++ b/.github/workflows/check-colab-notebooks.yml @@ -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 @@ -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) - 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." diff --git a/Makefile b/Makefile index 842d8452e..cf8075a08 100644 --- a/Makefile +++ b/Makefile @@ -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: