Skip to content
Merged
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
60 changes: 48 additions & 12 deletions .github/workflows/sync-sdk-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,53 @@ jobs:
f.write("\n".join(updated_targets))

if not updated_targets:
print("No updates detected.")
print("No updates detected (no mapped files copied).")
EOF

- name: Commit changes
- name: Commit changes (one commit per changed file)
id: commit-changes
run: |
if [ ! -s updated_files.txt ]; then
echo "No updated files. Skipping commit and PR."
# If the file doesn't exist or is empty, nothing to do
if [ ! -f updated_files.txt ] || [ ! -s updated_files.txt ]; then
echo "No updated files recorded. Skipping commit and PR."
echo "skip_pr=true" >> "$GITHUB_OUTPUT"
exit 0
fi

git config user.name "docs-sync-bot"
git config user.email "docs-sync-bot@users.noreply.github.com"

# We'll track which files we *actually* committed (have a diff)
> committed_files.txt

echo "Creating commits..."
while IFS= read -r file; do
if [ -z "$file" ]; then
continue
fi

# If there is no diff for this file, skip committing it
if git diff --quiet -- "$file"; then
echo "No changes in $file, skipping commit."
continue
fi

echo "Committing $file"
git add "$file"
git commit -m "[Sync] update $file"
echo "$file" >> committed_files.txt
done < updated_files.txt

echo "skip_pr=false" >> "$GITHUB_OUTPUT"
# Clean up helper file so it doesn't accidentally get committed
rm -f updated_files.txt

# If we didn't commit anything, skip PR creation
if [ ! -s committed_files.txt ]; then
echo "No commits were created. Skipping PR."
echo "skip_pr=true" >> "$GITHUB_OUTPUT"
# Leave committed_files.txt for debugging if needed
exit 0
fi

echo "Building PR body..."
{
Expand All @@ -127,9 +148,11 @@ jobs:
if [ -n "$file" ]; then
echo "- \`$file\`"
fi
done < updated_files.txt
done < committed_files.txt
} > PR_BODY.md

echo "skip_pr=false" >> "$GITHUB_OUTPUT"

- name: Push branch and create PR via API
id: push-and-pr
if: steps.commit-changes.outputs.skip_pr == 'false'
Expand All @@ -142,7 +165,8 @@ jobs:
set -e

echo "Pushing branch $SYNC_BRANCH"
git push origin HEAD:$SYNC_BRANCH
# --force just in case a branch with the same name exists from a previous run
git push --force origin HEAD:$SYNC_BRANCH

echo "Creating PR..."
PR_DATA=$(python - << 'EOF'
Expand All @@ -159,15 +183,22 @@ jobs:
EOF
)

RESPONSE=$(curl -sS -X POST \
RESPONSE=$(curl -sS -w "%{http_code}" -o pr_response.json \
-X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/pulls" \
-d "$PR_DATA")

echo "$RESPONSE" > pr_response.json
echo "GitHub API status: $RESPONSE"
echo "PR API response:"
cat pr_response.json

if [ "$RESPONSE" -lt 200 ] || [ "$RESPONSE" -ge 300 ]; then
echo "Failed to create PR (status $RESPONSE)."
exit 1
fi

PR_NUMBER=$(python - << 'EOF'
import json
with open("pr_response.json", "r", encoding="utf-8") as f:
Expand All @@ -177,7 +208,7 @@ jobs:
)

if [ -z "$PR_NUMBER" ]; then
echo "Failed to create PR."
echo "PR number missing in API response."
exit 1
fi

Expand All @@ -192,8 +223,13 @@ jobs:
PR_NUMBER: ${{ steps.push-and-pr.outputs.pr_number }}
run: |
echo "Approving PR #$PR_NUMBER"
curl -sS -X POST \
RESP=$(curl -sS -w "%{http_code}" -o approve_response.json \
-X POST \
-H "Authorization: Bearer $APPROVE_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/reviews" \
-d '{"event":"APPROVE"}'
-d '{"event":"APPROVE"}')

echo "Approve API status: $RESP"
echo "Approve API response:"
cat approve_response.json