@@ -13,22 +13,27 @@ jobs:
1313 contents : write
1414 pull-requests : write
1515
16+ env :
17+ BASE_BRANCH : sagan/docs-sync-test # change to develop later if needed
18+ SYNC_BRANCH_PREFIX : chore/sync-sdk-docs
19+
1620 steps :
1721 - name : Checkout delight-ai-docs
1822 uses : actions/checkout@v4
1923 with :
20- ref : sagan/docs-sync-test
24+ ref : ${{ env.BASE_BRANCH }}
2125 token : ${{ secrets.BOT_TOKEN }}
2226
2327 - name : Checkout delight-ai-agent
2428 uses : actions/checkout@v4
2529 with :
2630 repository : sendbird/delight-ai-agent
27- ref : sagan/docs-sync-test
31+ ref : sagan/docs-sync-test # or main in production
2832 path : delight-ai-agent
2933 token : ${{ secrets.BOT_TOKEN }}
3034
3135 - name : Sync mapped files from delight-ai-agent to sdk-docs
36+ id : sync-files
3237 run : |
3338 python << 'EOF'
3439 import shutil
@@ -66,51 +71,129 @@ jobs:
6671 "js/react/TEMPLATE-LAYOUT-CUSTOMIZATION-GUIDE.md": "sdk-docs/react-npm/template-based-layout-component-customization-guide.md",
6772 }
6873
69- updated_files = []
74+ updated_targets = []
7075
7176 for src, dst in MAPPING.items():
7277 src_path = agent_root / src
7378 dst_path = docs_root / dst
7479
75- if src_path.is_file():
76- dst_path.parent.mkdir(parents=True, exist_ok=True)
77- shutil.copy2(src_path, dst_path)
78- updated_files.append(dst)
79- print(f"Copied {src} -> {dst}")
80- else:
80+ if not src_path.is_file():
8181 print(f"[WARN] Missing source: {src}")
82+ continue
83+
84+ dst_path.parent.mkdir(parents=True, exist_ok=True)
85+ shutil.copy2(src_path, dst_path)
86+ updated_targets.append(str(dst_path))
87+ print(f"Copied {src} -> {dst}")
88+
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))
8292
83- if not updated_files :
93+ if not updated_targets :
8494 print("No updates detected.")
8595 EOF
8696
87- - name : Create pull request
88- id : cpr
89- uses : peter-evans/create-pull-request@v6
90- with :
91- token : ${{ secrets.BOT_TOKEN }}
92- commit-message : " chore: sync SDK docs from delight-ai-agent"
93- title : " chore: sync SDK docs from delight-ai-agent"
94- body : |
95- Automated sync from **delight-ai-agent → delight-ai-docs**.
96- base : sagan/docs-sync-test
97- branch : chore/sync-sdk-docs
98- branch-suffix : timestamp
99- labels : |
100- docs
101- automated-pr
102-
103- - name : Approve pull request
104- if : steps.cpr.outputs.pull-request-number != ''
105- uses : juliangruber/approve-pull-request-action@v1
106- with :
107- github-token : ${{ secrets.APPROVE_BOT_TOKEN }}
108- number : ${{ steps.cpr.outputs.pull-request-number }}
109-
110- # Optional auto-merge (enable if desired)
111- # - name: Merge PR
112- # if: steps.cpr.outputs.pull-request-number != ''
113- # uses: peter-evans/enable-pull-request-automerge@v3
114- # with:
115- # token: ${{ secrets.APPROVE_BOT_TOKEN }}
116- # pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
97+ - name : Commit changes
98+ id : commit-changes
99+ run : |
100+ if [ ! -s updated_files.txt ]; then
101+ echo "No updated files. Skipping commit and PR."
102+ echo "skip_pr=true" >> "$GITHUB_OUTPUT"
103+ exit 0
104+ fi
105+
106+ git config user.name "docs-sync-bot"
107+ git config user.email "docs-sync-bot@users.noreply.github.com"
108+
109+ echo "Creating commits..."
110+ while IFS= read -r file; do
111+ if [ -z "$file" ]; then
112+ continue
113+ fi
114+ echo "Committing $file"
115+ git add "$file"
116+ git commit -m "[Sync] update $file"
117+ done < updated_files.txt
118+
119+ echo "skip_pr=false" >> "$GITHUB_OUTPUT"
120+
121+ echo "Building PR body..."
122+ {
123+ echo "Automated sync from **delight-ai-agent → delight-ai-docs**."
124+ echo ""
125+ echo "Updated files:"
126+ while IFS= read -r file; do
127+ if [ -n "$file" ]; then
128+ echo "- \`$file\`"
129+ fi
130+ done < updated_files.txt
131+ } > PR_BODY.md
132+
133+ - name : Push branch and create PR via API
134+ id : push-and-pr
135+ if : steps.commit-changes.outputs.skip_pr == 'false'
136+ env :
137+ GITHUB_TOKEN : ${{ secrets.BOT_TOKEN }}
138+ REPO : sendbird/delight-ai-docs
139+ BASE_BRANCH : ${{ env.BASE_BRANCH }}
140+ SYNC_BRANCH : ${{ env.SYNC_BRANCH_PREFIX }}-${{ github.run_id }}
141+ run : |
142+ set -e
143+
144+ echo "Pushing branch $SYNC_BRANCH"
145+ git push origin HEAD:$SYNC_BRANCH
146+
147+ echo "Creating PR..."
148+ PR_DATA=$(python - << 'EOF'
149+ import json, os
150+ with open("PR_BODY.md", "r", encoding="utf-8") as f:
151+ body = f.read()
152+ data = {
153+ "title": "[SDK] updated from delight-ai-agent",
154+ "body": body,
155+ "head": os.environ["SYNC_BRANCH"],
156+ "base": os.environ["BASE_BRANCH"],
157+ }
158+ print(json.dumps(data))
159+ EOF
160+ )
161+
162+ RESPONSE=$(curl -sS -X POST \
163+ -H "Authorization: Bearer $GITHUB_TOKEN" \
164+ -H "Accept: application/vnd.github+json" \
165+ "https://api.github.com/repos/$REPO/pulls" \
166+ -d "$PR_DATA")
167+
168+ echo "$RESPONSE" > pr_response.json
169+ cat pr_response.json
170+
171+ PR_NUMBER=$(python - << 'EOF'
172+ import json
173+ with open("pr_response.json", "r", encoding="utf-8") as f:
174+ data = json.load(f)
175+ print(data.get("number", ""))
176+ EOF
177+ )
178+
179+ if [ -z "$PR_NUMBER" ]; then
180+ echo "Failed to create PR."
181+ exit 1
182+ fi
183+
184+ echo "Created PR #$PR_NUMBER"
185+ echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
186+
187+ - name : Approve pull request via API
188+ if : steps.push-and-pr.outputs.pr_number != '' && steps.commit-changes.outputs.skip_pr == 'false'
189+ env :
190+ APPROVE_TOKEN : ${{ secrets.APPROVE_BOT_TOKEN }}
191+ REPO : sendbird/delight-ai-docs
192+ PR_NUMBER : ${{ steps.push-and-pr.outputs.pr_number }}
193+ run : |
194+ echo "Approving PR #$PR_NUMBER"
195+ curl -sS -X POST \
196+ -H "Authorization: Bearer $APPROVE_TOKEN" \
197+ -H "Accept: application/vnd.github+json" \
198+ "https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/reviews" \
199+ -d '{"event":"APPROVE"}'
0 commit comments