Skip to content

Commit ab4b70a

Browse files
authored
Merge pull request #11 from sendbird/sagan/docs-sync-test
[Docs, ReadMe] Update yml file
2 parents f19cf86 + d32d8be commit ab4b70a

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

.github/workflows/sync-sdk-docs.yml

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,53 @@ jobs:
9191
f.write("\n".join(updated_targets))
9292
9393
if not updated_targets:
94-
print("No updates detected.")
94+
print("No updates detected (no mapped files copied).")
9595
EOF
9696
97-
- name: Commit changes
97+
- name: Commit changes (one commit per changed file)
9898
id: commit-changes
9999
run: |
100-
if [ ! -s updated_files.txt ]; then
101-
echo "No updated files. Skipping commit and PR."
100+
# If the file doesn't exist or is empty, nothing to do
101+
if [ ! -f updated_files.txt ] || [ ! -s updated_files.txt ]; then
102+
echo "No updated files recorded. Skipping commit and PR."
102103
echo "skip_pr=true" >> "$GITHUB_OUTPUT"
103104
exit 0
104105
fi
105106
106107
git config user.name "docs-sync-bot"
107108
git config user.email "docs-sync-bot@users.noreply.github.com"
108109
110+
# We'll track which files we *actually* committed (have a diff)
111+
> committed_files.txt
112+
109113
echo "Creating commits..."
110114
while IFS= read -r file; do
111115
if [ -z "$file" ]; then
112116
continue
113117
fi
118+
119+
# If there is no diff for this file, skip committing it
120+
if git diff --quiet -- "$file"; then
121+
echo "No changes in $file, skipping commit."
122+
continue
123+
fi
124+
114125
echo "Committing $file"
115126
git add "$file"
116127
git commit -m "[Sync] update $file"
128+
echo "$file" >> committed_files.txt
117129
done < updated_files.txt
118130
119-
echo "skip_pr=false" >> "$GITHUB_OUTPUT"
131+
# Clean up helper file so it doesn't accidentally get committed
132+
rm -f updated_files.txt
133+
134+
# If we didn't commit anything, skip PR creation
135+
if [ ! -s committed_files.txt ]; then
136+
echo "No commits were created. Skipping PR."
137+
echo "skip_pr=true" >> "$GITHUB_OUTPUT"
138+
# Leave committed_files.txt for debugging if needed
139+
exit 0
140+
fi
120141
121142
echo "Building PR body..."
122143
{
@@ -127,9 +148,11 @@ jobs:
127148
if [ -n "$file" ]; then
128149
echo "- \`$file\`"
129150
fi
130-
done < updated_files.txt
151+
done < committed_files.txt
131152
} > PR_BODY.md
132153
154+
echo "skip_pr=false" >> "$GITHUB_OUTPUT"
155+
133156
- name: Push branch and create PR via API
134157
id: push-and-pr
135158
if: steps.commit-changes.outputs.skip_pr == 'false'
@@ -142,7 +165,8 @@ jobs:
142165
set -e
143166
144167
echo "Pushing branch $SYNC_BRANCH"
145-
git push origin HEAD:$SYNC_BRANCH
168+
# --force just in case a branch with the same name exists from a previous run
169+
git push --force origin HEAD:$SYNC_BRANCH
146170
147171
echo "Creating PR..."
148172
PR_DATA=$(python - << 'EOF'
@@ -159,15 +183,22 @@ jobs:
159183
EOF
160184
)
161185
162-
RESPONSE=$(curl -sS -X POST \
186+
RESPONSE=$(curl -sS -w "%{http_code}" -o pr_response.json \
187+
-X POST \
163188
-H "Authorization: Bearer $GITHUB_TOKEN" \
164189
-H "Accept: application/vnd.github+json" \
165190
"https://api.github.com/repos/$REPO/pulls" \
166191
-d "$PR_DATA")
167192
168-
echo "$RESPONSE" > pr_response.json
193+
echo "GitHub API status: $RESPONSE"
194+
echo "PR API response:"
169195
cat pr_response.json
170196
197+
if [ "$RESPONSE" -lt 200 ] || [ "$RESPONSE" -ge 300 ]; then
198+
echo "Failed to create PR (status $RESPONSE)."
199+
exit 1
200+
fi
201+
171202
PR_NUMBER=$(python - << 'EOF'
172203
import json
173204
with open("pr_response.json", "r", encoding="utf-8") as f:
@@ -177,7 +208,7 @@ jobs:
177208
)
178209
179210
if [ -z "$PR_NUMBER" ]; then
180-
echo "Failed to create PR."
211+
echo "PR number missing in API response."
181212
exit 1
182213
fi
183214
@@ -192,8 +223,13 @@ jobs:
192223
PR_NUMBER: ${{ steps.push-and-pr.outputs.pr_number }}
193224
run: |
194225
echo "Approving PR #$PR_NUMBER"
195-
curl -sS -X POST \
226+
RESP=$(curl -sS -w "%{http_code}" -o approve_response.json \
227+
-X POST \
196228
-H "Authorization: Bearer $APPROVE_TOKEN" \
197229
-H "Accept: application/vnd.github+json" \
198230
"https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/reviews" \
199-
-d '{"event":"APPROVE"}'
231+
-d '{"event":"APPROVE"}')
232+
233+
echo "Approve API status: $RESP"
234+
echo "Approve API response:"
235+
cat approve_response.json

0 commit comments

Comments
 (0)