Skip to content

Commit bcfd3de

Browse files
authored
New smarter approach for sync-content-to-next.yml
1 parent e9a50c4 commit bcfd3de

File tree

1 file changed

+72
-7
lines changed

1 file changed

+72
-7
lines changed

.github/workflows/sync-content-to-next.yml

+72-7
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,24 @@ jobs:
138138
# Push branch
139139
git push origin next-port-pr${{ github.event.pull_request.number }}
140140
141-
# Create PR with a special tag in the body to identify it later
141+
# Create PR body in a temp file to preserve newlines
142+
PR_BODY_FILE=$(mktemp)
143+
cat > $PR_BODY_FILE << EOF
144+
Automatic port of PR #${{ github.event.pull_request.number }} to next branch.
145+
146+
Original PR: #${{ github.event.pull_request.number }}
147+
Created automatically after adding the 'temp - port to docs-next' label.
148+
149+
<!-- SYNC_PR_MARKER -->
150+
EOF
151+
152+
# Create PR using the file for body content
142153
gh pr create --base next --head next-port-pr${{ github.event.pull_request.number }} \
143154
--title "[Port to next] ${{ github.event.pull_request.title }}" \
144-
--body "Automatic port of PR #${{ github.event.pull_request.number }} to next branch.\n\nOriginal PR: #${{ github.event.pull_request.number }}\nCreated automatically after adding the 'temp - port to docs-next' label.\n\n<!-- SYNC_PR_MARKER -->"
155+
--body-file $PR_BODY_FILE
156+
157+
# Clean up
158+
rm $PR_BODY_FILE
145159
env:
146160
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}
147161

@@ -251,7 +265,18 @@ jobs:
251265
echo "Updating existing PR #$EXISTING_PR with latest merged changes"
252266
253267
# Add comment explaining the update
254-
gh pr comment $EXISTING_PR --body "This PR has been updated with the latest changes from the merged PR #${{ github.event.pull_request.number }}. The merge commit was cherry-picked to include all approved changes."
268+
COMMENT_FILE=$(mktemp)
269+
cat > $COMMENT_FILE << EOF
270+
This PR has been updated with the latest changes from the merged PR #${{ github.event.pull_request.number }}.
271+
272+
The merge commit was cherry-picked to include all approved changes.
273+
EOF
274+
275+
# Add comment using the file
276+
gh pr comment $EXISTING_PR --body-file $COMMENT_FILE
277+
278+
# Clean up
279+
rm $COMMENT_FILE
255280
env:
256281
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}
257282

@@ -262,14 +287,32 @@ jobs:
262287
BRANCH_NAME="${{ steps.create-branch.outputs.branch_name }}"
263288
PR_TITLE="${{ github.event.pull_request.title }}"
264289
290+
# Create PR body file
291+
PR_BODY_FILE=$(mktemp)
292+
cat > $PR_BODY_FILE << EOF
293+
Synchronization of merged PR #${{ github.event.pull_request.number }} to next branch.
294+
295+
This PR contains the final state of the changes as they were merged to main.
296+
EOF
297+
265298
# Create the new PR first
266299
NEW_PR=$(gh pr create --base next --head $BRANCH_NAME \
267300
--title "[Merged-sync] $PR_TITLE" \
268-
--body "Synchronization of merged PR #${{ github.event.pull_request.number }} to next branch. This PR contains the final state of the changes as they were merged to main." \
301+
--body-file $PR_BODY_FILE \
269302
--json number --jq '.number')
270303

304+
# Create comment body file
305+
COMMENT_FILE=$(mktemp)
306+
cat > $COMMENT_FILE << EOF
307+
This PR is replaced by the direct synchronization of the merge commit in #$NEW_PR
308+
EOF
309+
271310
# Now close the existing PR with a reference to the new one
272-
gh pr close $EXISTING_PR --comment "This PR is replaced by the direct synchronization of the merge commit in #$NEW_PR"
311+
gh pr close $EXISTING_PR --comment-file $COMMENT_FILE
312+
313+
# Clean up
314+
rm $PR_BODY_FILE
315+
rm $COMMENT_FILE
273316
env:
274317
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}
275318

@@ -279,10 +322,21 @@ jobs:
279322
BRANCH_NAME="${{ steps.create-branch.outputs.branch_name }}"
280323
PR_TITLE="${{ github.event.pull_request.title }}"
281324
325+
# Create PR body file
326+
PR_BODY_FILE=$(mktemp)
327+
cat > $PR_BODY_FILE << EOF
328+
Synchronization of merged PR #${{ github.event.pull_request.number }} to next branch.
329+
330+
This PR contains the final state of the changes as they were merged to main.
331+
EOF
332+
282333
# Create new PR
283334
gh pr create --base next --head $BRANCH_NAME \
284335
--title "[Merged-sync] $PR_TITLE" \
285-
--body "Synchronization of merged PR #${{ github.event.pull_request.number }} to next branch. This PR contains the final state of the changes as they were merged to main."
336+
--body-file $PR_BODY_FILE
337+
338+
# Clean up
339+
rm $PR_BODY_FILE
286340
env:
287341
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}
288342

@@ -330,10 +384,21 @@ jobs:
330384
if git cherry-pick $COMMIT_HASH; then
331385
git push origin $BRANCH_NAME
332386
387+
# Create PR body file
388+
PR_BODY_FILE=$(mktemp)
389+
cat > $PR_BODY_FILE << EOF
390+
Automatic sync of commit from main.
391+
392+
This PR contains changes pushed directly to the main branch.
393+
EOF
394+
333395
# Create PR
334396
gh pr create --base next --head $BRANCH_NAME \
335397
--title "[Auto-sync] $COMMIT_MSG" \
336-
--body "Automatic sync of commit from main"
398+
--body-file $PR_BODY_FILE
399+
400+
# Clean up
401+
rm $PR_BODY_FILE
337402
else
338403
echo "Cherry-pick failed, manual intervention needed"
339404
git cherry-pick --abort

0 commit comments

Comments
 (0)