Skip to content

Commit 3c04008

Browse files
committed
push PR only on merge
1 parent b7b1408 commit 3c04008

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

.github/workflows/add-notebook-examples-to-docs.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Checkout repository
2424
uses: actions/checkout@v3
2525
with:
26-
fetch-depth: 2
26+
fetch-depth: 0
2727

2828
- name: Set up Python
2929
uses: actions/setup-python@v4
@@ -38,11 +38,31 @@ jobs:
3838
run: |
3939
set -x # Enable debug mode
4040
41-
# Smart change detection - only process changed files
42-
FILES=$(git diff --name-only HEAD^ HEAD 2>/dev/null | grep -E "(examples/.*\.ipynb|docs/v2/examples/.*\.mdx)" | \
41+
# Smart change detection - handle both regular commits and merge commits
42+
echo "Detecting changed files..."
43+
44+
# Check if this is a merge commit
45+
if git rev-parse HEAD^2 >/dev/null 2>&1; then
46+
echo "Detected merge commit - finding all PR changes"
47+
# Get the merge base between the two parent commits
48+
BASE_SHA=$(git merge-base HEAD^1 HEAD^2)
49+
echo "Merge base: $BASE_SHA"
50+
# Get all files changed in the PR
51+
CHANGED_FILES=$(git diff --name-only $BASE_SHA HEAD)
52+
else
53+
echo "Regular commit - checking against previous commit"
54+
# For regular commits, just check against the parent
55+
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD 2>/dev/null)
56+
fi
57+
58+
# Filter for relevant files and find related MDX files
59+
FILES=$(echo "$CHANGED_FILES" | grep -E "(examples/.*\.ipynb|docs/v2/examples/.*\.mdx)" | \
4360
xargs -I{} sh -c 'echo {} | grep -q "\.ipynb$" && grep -l "SOURCE_FILE: {}" docs/v2/examples/*.mdx 2>/dev/null || echo {}' | \
4461
sort -u)
4562
63+
echo "Total changed files: $(echo "$CHANGED_FILES" | wc -l)"
64+
echo "Relevant files to process: $(echo "$FILES" | wc -l)"
65+
4666
if [[ -z "$FILES" ]]; then
4767
echo "No relevant changes detected - skipping processing"
4868
exit 0

0 commit comments

Comments
 (0)