2222 uses : actions/checkout@v4
2323 with :
2424 ref : ${{ env.BASE_BRANCH }}
25- token : ${{ secrets.BOT_TOKEN }}
25+ token : ${{ github.token }}
2626
2727 - name : Checkout delight-ai-agent
2828 uses : actions/checkout@v4
3131 ref : sagan/docs-sync-test # or main in production
3232 path : delight-ai-agent
3333 token : ${{ secrets.BOT_TOKEN }}
34+ fetch-depth : 2 # need previous commit for diff
35+
36+ # NEW: detect which files changed in the latest commit on delight-ai-agent
37+ - name : Detect updated source files in delight-ai-agent
38+ id : detect-updates
39+ run : |
40+ cd delight-ai-agent
41+
42+ # If there is no previous commit (very first commit / shallow history),
43+ # fall back to treating all tracked files as "changed".
44+ if git rev-parse HEAD~1 >/dev/null 2>&1; then
45+ echo "Diffing HEAD~1..HEAD to find changed files..."
46+ git diff --name-only HEAD~1 HEAD > ../changed_source_files.txt
47+ else
48+ echo "No HEAD~1, using all tracked files as changed (initial sync case)..."
49+ git ls-files > ../changed_source_files.txt
50+ fi
51+
52+ cd ..
53+ echo "Changed source files (from delight-ai-agent):"
54+ cat changed_source_files.txt || echo "(none)"
3455
3556 - name : Sync mapped files from delight-ai-agent to sdk-docs
3657 id : sync-files
4263 agent_root = Path("delight-ai-agent")
4364 docs_root = Path(".")
4465
66+ changed_file_list = Path("changed_source_files.txt")
67+ if changed_file_list.is_file():
68+ changed_sources = {
69+ line.strip()
70+ for line in changed_file_list.read_text(encoding="utf-8").splitlines()
71+ if line.strip()
72+ }
73+ print("Changed sources from delight-ai-agent:")
74+ for s in sorted(changed_sources):
75+ print(f" - {s}")
76+ else:
77+ changed_sources = set()
78+ print("[WARN] changed_source_files.txt not found; assuming no changed sources.")
79+
80+ # Mapping: source in delight-ai-agent -> target in delight-ai-docs
4581 MAPPING = {
4682 # ANDROID
4783 "android/docs/conversations.md": "sdk-docs/android/features/conversations.md",
@@ -71,75 +107,119 @@ jobs:
71107 "js/react/TEMPLATE-LAYOUT-CUSTOMIZATION-GUIDE.md": "sdk-docs/react-npm/template-based-layout-component-customization-guide.md",
72108 }
73109
110+ mapping_sources = set(MAPPING.keys())
111+
112+ # Only sync files that are BOTH:
113+ # - changed in delight-ai-agent (changed_sources)
114+ # - present in our mapping table (mapping_sources)
115+ to_sync_sources = sorted(mapping_sources & changed_sources)
116+
117+ print("Sources selected for sync (intersection of mapping & changed files):")
118+ if to_sync_sources:
119+ for src in to_sync_sources:
120+ print(f" - {src}")
121+ else:
122+ print(" (none)")
123+
74124 updated_targets = []
75125
76- for src, dst in MAPPING.items():
126+ for src in to_sync_sources:
127+ dst = MAPPING[src]
77128 src_path = agent_root / src
78129 dst_path = docs_root / dst
79130
80131 if not src_path.is_file():
81- print(f"[WARN] Missing source: {src}")
132+ print(f"[WARN] Missing source (skipping) : {src}")
82133 continue
83134
84135 dst_path.parent.mkdir(parents=True, exist_ok=True)
85136 shutil.copy2(src_path, dst_path)
86- updated_targets.append(str(dst_path))
137+ updated_targets.append(dst) # store repo-relative path
87138 print(f"Copied {src} -> {dst}")
88139
89- # Write updated targets for later steps
90- with open("updated_files.txt", "w", encoding="utf-8") as f:
91- f.write("\n".join(updated_targets))
92-
93- if not updated_targets:
94- print("No updates detected (no mapped files copied).")
140+ # Write updated targets for later steps (commits & PR body)
141+ updated_list_path = Path("updated_files.txt")
142+ if updated_targets:
143+ updated_list_path.write_text("\n".join(updated_targets) + "\n", encoding="utf-8")
144+ print(f"{len(updated_targets)} file(s) copied for sync.")
145+ print("updated_files.txt will contain:")
146+ for t in updated_targets:
147+ print(f" - {t}")
148+ else:
149+ # still create the file so the next step can safely check it
150+ updated_list_path.write_text("", encoding="utf-8")
151+ print("No mapped files updated from latest commit.")
95152 EOF
96153
97154 - name : Commit changes (one commit per changed file)
98155 id : commit-changes
99156 run : |
100- # If the file doesn't exist or is empty, nothing to do
157+ echo "===== 📝 Commit Changes Step Started ====="
158+
159+ # 1) Safety check
101160 if [ ! -f updated_files.txt ] || [ ! -s updated_files.txt ]; then
102- echo "No updated files recorded. Skipping commit and PR."
161+ echo "⚠️ No updated files recorded. Skipping commit and PR."
103162 echo "skip_pr=true" >> "$GITHUB_OUTPUT"
104163 exit 0
105164 fi
106165
166+ echo "📄 updated_files.txt exists and is non-empty"
167+ echo "----- Contents of updated_files.txt (truncated per line to 100 chars) -----"
168+ while IFS= read -r line; do
169+ if [ -z "$line" ]; then
170+ continue
171+ fi
172+ truncated=$(echo "$line" | cut -c1-100)
173+ echo " • $truncated"
174+ done < updated_files.txt
175+ echo "--------------------------------------------------------------------------"
176+
177+ # 2) Configure git
178+ echo "🔧 Configuring git user"
107179 git config user.name "docs-sync-bot"
108180 git config user.email "docs-sync-bot@users.noreply.github.com"
109181
110- # We'll track which files we *actually* committed (have a diff)
182+ # 3) Prepare commit tracking file
111183 > committed_files.txt
112184
113- echo "Creating commits..."
185+ echo "===== 🚀 Creating commits ====="
186+ COUNT=0
114187 while IFS= read -r file; do
115188 if [ -z "$file" ]; then
116189 continue
117190 fi
118191
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."
192+ if [ ! -f "$file" ]; then
193+ echo "⚠️ [WARN] Target file missing at commit time, skipping: $file"
122194 continue
123195 fi
124196
125- echo "Committing $file"
197+ echo "➡️ Committing: $file"
126198 git add "$file"
127- git commit -m "[Sync] update $file"
199+ git commit --allow-empty - m "[Sync] update $file"
128200 echo "$file" >> committed_files.txt
201+ COUNT=$((COUNT+1))
129202 done < updated_files.txt
130203
131- # Clean up helper file so it doesn't accidentally get committed
204+ echo "===== 🧹 Cleanup: removing updated_files.txt ====="
132205 rm -f updated_files.txt
133206
134- # If we didn't commit anything, skip PR creation
207+ # 4) Post- commit checks
135208 if [ ! -s committed_files.txt ]; then
136- echo "No commits were created. Skipping PR."
209+ echo "⚠️ No commits were created (all files missing?) . Skipping PR."
137210 echo "skip_pr=true" >> "$GITHUB_OUTPUT"
138- # Leave committed_files.txt for debugging if needed
139211 exit 0
140212 fi
141213
142- echo "Building PR body..."
214+ echo "===== 📌 Summary ====="
215+ echo "Total commits created: $COUNT"
216+ echo "Committed files (truncated to 100 chars):"
217+ while IFS= read -r line; do
218+ truncated=$(echo "$line" | cut -c1-100)
219+ echo " • $truncated"
220+ done < committed_files.txt
221+
222+ echo "===== 🏗️ Building PR body ====="
143223 {
144224 echo "Automated sync from **delight-ai-agent → delight-ai-docs**."
145225 echo ""
@@ -151,13 +231,15 @@ jobs:
151231 done < committed_files.txt
152232 } > PR_BODY.md
153233
234+ echo "PR body written to PR_BODY.md"
235+ echo "===== ✅ Commit Step Finished Successfully ====="
154236 echo "skip_pr=false" >> "$GITHUB_OUTPUT"
155237
156238 - name : Push branch and create PR via API
157239 id : push-and-pr
158240 if : steps.commit-changes.outputs.skip_pr == 'false'
159241 env :
160- GITHUB_TOKEN : ${{ secrets.BOT_TOKEN }}
242+ GITHUB_TOKEN : ${{ github.token }}
161243 REPO : sendbird/delight-ai-docs
162244 BASE_BRANCH : ${{ env.BASE_BRANCH }}
163245 SYNC_BRANCH : ${{ env.SYNC_BRANCH_PREFIX }}-${{ github.run_id }}
0 commit comments