Skip to content

Commit 5bfbbda

Browse files
committed
feat: refactor auto_examples generation to remove download step and enforce full rebuild
1 parent 7ff6853 commit 5bfbbda

File tree

1 file changed

+21
-123
lines changed

1 file changed

+21
-123
lines changed

.github/workflows/generate-examples.yml

Lines changed: 21 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,6 @@ jobs:
187187
pip install -r requirements-dev.txt
188188
pip install -e .
189189
190-
- name: Download latest auto_examples from releases
191-
run: |
192-
echo "🔽 Downloading latest auto_examples from GitHub releases..."
193-
python scripts/download_auto_examples.py
194-
if [ -d "docs/auto_examples" ]; then
195-
echo "✅ Downloaded existing auto_examples from releases"
196-
echo "Files: $(find docs/auto_examples -name "*.py" | wc -l) Python files"
197-
echo "Images: $(find docs/auto_examples -name "*.png" -o -name "*.jpg" -o -name "*.svg" | wc -l) image files"
198-
echo "Size: $(du -sh docs/auto_examples | cut -f1)"
199-
else
200-
echo "ℹ️ No existing auto_examples found in releases, will build from scratch"
201-
fi
202-
env:
203-
GITHUB_TOKEN: ${{ github.token }}
204-
205190
- name: Get last successful workflow commit
206191
id: last-success
207192
run: |
@@ -249,7 +234,7 @@ jobs:
249234
- name: Detect changed example files
250235
id: changed-examples
251236
run: |
252-
echo "🔍 Detecting changed example files..."
237+
echo "🔍 Detecting if any example files changed..."
253238
254239
LAST_SUCCESS_SHA="${{ steps.last-success.outputs.last_success_sha }}"
255240
CURRENT_SHA="${{ github.sha }}"
@@ -264,102 +249,38 @@ jobs:
264249
else
265250
echo "⚠️ Last successful commit $LAST_SUCCESS_SHA not accessible in current checkout"
266251
echo "This might happen with shallow clones - treating all examples as changed"
267-
changed_files=$(find examples -name "*.py" -type f)
252+
changed_files="examples_changed"
268253
fi
269254
else
270255
if [ "$LAST_SUCCESS_SHA" = "$CURRENT_SHA" ]; then
271256
echo "ℹ️ Current commit is the same as last successful run - no changes"
272257
changed_files=""
273258
else
274259
echo "⚠️ No reference commit available - treating all examples as changed"
275-
changed_files=$(find examples -name "*.py" -type f)
260+
changed_files="examples_changed"
276261
fi
277262
fi
278263
279264
if [ -z "$changed_files" ]; then
280-
echo "No example files changed since last successful build"
281-
echo "changed_count=0" >> $GITHUB_OUTPUT
282-
echo "changed_files=" >> $GITHUB_OUTPUT
265+
echo "No example files changed since last successful build - skipping generation"
266+
echo "examples_changed=false" >> $GITHUB_OUTPUT
283267
else
284-
echo "Changed example files since last successful build:"
285-
echo "$changed_files"
286-
echo "changed_count=$(echo "$changed_files" | wc -l)" >> $GITHUB_OUTPUT
287-
# Store changed files (newlines replaced with spaces for GitHub Actions)
288-
echo "changed_files=$(echo "$changed_files" | tr '\n' ' ')" >> $GITHUB_OUTPUT
268+
echo "Example files have changed since last successful build - will rebuild all examples"
269+
echo "examples_changed=true" >> $GITHUB_OUTPUT
289270
fi
290271
291-
- name: Remove generated files for changed examples
292-
if: steps.changed-examples.outputs.changed_count > 0
272+
- name: Generate auto_examples (full build)
273+
if: steps.changed-examples.outputs.examples_changed == 'true'
293274
run: |
294-
echo "🗑️ Removing generated files for changed examples..."
295-
changed_files="${{ steps.changed-examples.outputs.changed_files }}"
296-
297-
for example_file in $changed_files; do
298-
if [ -f "$example_file" ]; then
299-
# Convert examples/category/plot_example.py to auto_examples/category/plot_example.py
300-
auto_example_file=$(echo "$example_file" | sed 's|^examples/|docs/auto_examples/|')
301-
auto_example_dir=$(dirname "$auto_example_file")
302-
auto_example_base=$(basename "$auto_example_file" .py)
303-
304-
echo " Processing: $example_file"
305-
echo " -> Auto example: $auto_example_file"
306-
307-
if [ -d "$auto_example_dir" ]; then
308-
# Remove the main Python file
309-
if [ -f "$auto_example_file" ]; then
310-
rm -f "$auto_example_file"
311-
echo " ✅ Removed: $auto_example_file"
312-
fi
313-
314-
# Remove associated files (images, notebooks, etc.)
315-
rm -f "${auto_example_dir}/${auto_example_base}"*.png
316-
rm -f "${auto_example_dir}/${auto_example_base}"*.jpg
317-
rm -f "${auto_example_dir}/${auto_example_base}"*.svg
318-
rm -f "${auto_example_dir}/${auto_example_base}"*.ipynb
319-
rm -f "${auto_example_dir}/${auto_example_base}"*.zip
320-
321-
echo " ✅ Removed associated files for: $auto_example_base"
322-
else
323-
echo " ℹ️ Auto examples directory doesn't exist yet: $auto_example_dir"
324-
fi
325-
fi
326-
done
275+
echo "🔄 Generating auto_examples (full build)"
276+
echo "Reason: Example files have changed"
327277
328-
echo "🎯 Removed generated files for ${{ steps.changed-examples.outputs.changed_count }} changed examples"
329-
330-
- name: Generate auto_examples (incremental)
331-
run: |
332278
cd docs
333-
changed_count="${{ steps.changed-examples.outputs.changed_count }}"
334-
total_examples=$(find ../examples -name "*.py" | wc -l)
335-
336-
if [ "$changed_count" -gt 0 ] && [ -d "auto_examples" ]; then
337-
echo "🔄 Generating auto_examples (incremental build)"
338-
echo "Changed files: $changed_count out of $total_examples total"
339-
340-
# Use the incremental build script
341-
changed_files="${{ steps.changed-examples.outputs.changed_files }}"
342-
echo "Running incremental build for: $changed_files"
343-
344-
python ../scripts/build_incremental_examples.py \
345-
--changed-files "$changed_files" \
346-
--docs-dir . \
347-
--fallback-full-build
348-
349-
else
350-
echo "🔄 Generating auto_examples (full build)"
351-
if [ "$changed_count" -eq 0 ]; then
352-
echo "Reason: No changed files detected"
353-
else
354-
echo "Reason: No existing auto_examples base found"
355-
fi
356-
357-
# Use sphinx-build to generate the complete gallery
358-
sphinx-build -b html \
359-
-D sphinx_gallery_conf.plot_gallery=True \
360-
-D sphinx_gallery_conf.download_all_examples=True \
361-
. _build/html -v
362-
fi
279+
# Use sphinx-build to generate the complete gallery
280+
sphinx-build -b html \
281+
-D sphinx_gallery_conf.plot_gallery=True \
282+
-D sphinx_gallery_conf.download_all_examples=True \
283+
. _build/html -v
363284
364285
- name: Verify auto_examples generation
365286
run: |
@@ -382,21 +303,8 @@ jobs:
382303
echo " - Notebook files: $notebook_files"
383304
echo " - Total size: $total_size"
384305
385-
# Show what was actually built vs reused
386-
changed_count="${{ steps.changed-examples.outputs.changed_count }}"
387306
total_examples=$(find examples -name "*.py" | wc -l)
388-
389-
if [ "$changed_count" -gt 0 ] && [ "$changed_count" -lt "$total_examples" ]; then
390-
reused_count=$((total_examples - changed_count))
391-
echo "🎯 Incremental Build Summary:"
392-
echo " - Rebuilt: $changed_count examples"
393-
echo " - Reused: $reused_count examples"
394-
# Calculate percentage without bc dependency
395-
efficiency_percent=$((reused_count * 100 / total_examples))
396-
echo " - Efficiency: ${efficiency_percent}% reused"
397-
else
398-
echo "🔄 Full Build: Generated all examples"
399-
fi
307+
echo "🔄 Full Build: Generated all $total_examples examples"
400308
else
401309
echo "❌ ERROR: auto_examples directory was not created"
402310
exit 1
@@ -410,28 +318,20 @@ jobs:
410318
archive_size=$(ls -lh auto_examples.zip | awk '{print $5}')
411319
412320
# Add build metadata to the archive
413-
changed_count="${{ steps.changed-examples.outputs.changed_count }}"
414321
total_examples=$(find ../examples -name "*.py" | wc -l)
415322
416323
echo "📦 Archive Information:"
417324
echo " - File: auto_examples.zip"
418325
echo " - Size: $archive_size"
419326
echo " - Total examples: $total_examples"
420-
421-
if [ "$changed_count" -gt 0 ] && [ "$changed_count" -lt "$total_examples" ]; then
422-
reused_count=$((total_examples - changed_count))
423-
echo " - Build type: Incremental ($changed_count rebuilt, $reused_count reused)"
424-
else
425-
echo " - Build type: Full build"
426-
fi
427-
327+
echo " - Build type: Full build"
428328
echo " - Commit: ${{ github.sha }}"
429329
echo " - Event: ${{ github.event_name }}"
430330
431331
- name: Upload auto_examples as artifact (backup)
432332
uses: actions/upload-artifact@v4
433333
with:
434-
name: auto_examples-${{ github.sha }}-incremental
334+
name: auto_examples-${{ github.sha }}
435335
path: docs/auto_examples.zip
436336
retention-days: 30
437337

@@ -488,9 +388,7 @@ jobs:
488388
echo " - .github/workflows/generate-examples.yml"
489389
echo ""
490390
echo "💡 When changes are detected, the workflow will:"
491-
echo " 1. Download latest auto_examples as base"
492-
echo " 2. Remove generated files for changed examples only"
493-
echo " 3. Rebuild only the changed examples (incremental build)"
494-
echo " 4. Upload the updated auto_examples archive"
391+
echo " 1. Generate all auto_examples from scratch (full build)"
392+
echo " 2. Upload the auto_examples archive"
495393
echo ""
496394
echo "🚀 To force rebuild, include '[rebuild-examples]' in commit message"

0 commit comments

Comments
 (0)