Skip to content

Commit 0523d46

Browse files
committed
Merge branch 'main' of github.com:strapi/documentation
2 parents 9d8b914 + 36ccc24 commit 0523d46

File tree

1 file changed

+137
-19
lines changed

1 file changed

+137
-19
lines changed

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

+137-19
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,39 @@ on:
55
branches:
66
- main
77
paths:
8-
- 'docs/cms/**'
9-
- 'docs/cloud/**'
10-
- 'static/img/assets/**'
8+
- 'docusaurus/docs/cms/**'
9+
- 'docusaurus/docs/cloud/**'
10+
- 'docusaurus/static/img/assets/**'
1111
pull_request:
1212
types: [labeled, closed]
1313

1414
jobs:
15+
# Debug Job: Print event info
16+
debug-event:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Print GitHub context
20+
env:
21+
GITHUB_CONTEXT: ${{ toJSON(github) }}
22+
run: echo "$GITHUB_CONTEXT"
23+
24+
- name: Print event name and type
25+
run: |
26+
echo "Event name: ${{ github.event_name }}"
27+
echo "Event action: ${{ github.event.action }}"
28+
if [ "${{ github.event_name }}" = "pull_request" ]; then
29+
echo "PR number: ${{ github.event.pull_request.number }}"
30+
echo "PR labels: ${{ toJSON(github.event.pull_request.labels) }}"
31+
fi
32+
if [ "${{ github.event_name }}" = "push" ]; then
33+
echo "Pushed ref: ${{ github.ref }}"
34+
echo "Base ref: ${{ github.base_ref }}"
35+
fi
36+
1537
# Job 1: Automatic replication of commits pushed to main
1638
cherry-pick-from-push:
1739
if: github.event_name == 'push'
40+
needs: debug-event
1841
runs-on: ubuntu-latest
1942
steps:
2043
- name: Checkout repository
@@ -28,59 +51,92 @@ jobs:
2851
git config user.name "GitHub Actions Bot"
2952
git config user.email "[email protected]"
3053
54+
- name: Debug - List recent commits
55+
run: |
56+
echo "Recent commits on main:"
57+
git log -n 5 --oneline
58+
3159
- name: Get latest commit that modified content
3260
id: get-commit
3361
run: |
34-
COMMIT_HASH=$(git log -1 --format="%H" -- docs/cms docs/cloud static/img/assets)
62+
echo "Looking for latest commit that modified content folders..."
63+
COMMIT_HASH=$(git log -1 --format="%H" -- docusaurus/docs/cms docusaurus/docs/cloud docusaurus/static/img/assets)
3564
COMMIT_MSG=$(git log -1 --format="%s" $COMMIT_HASH)
65+
echo "Found commit: $COMMIT_HASH"
66+
echo "Commit message: $COMMIT_MSG"
3667
echo "commit_hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
3768
echo "commit_msg=$COMMIT_MSG" >> $GITHUB_OUTPUT
3869
3970
- name: Check if commit modifies only content files
4071
id: check-content-only
4172
run: |
73+
echo "Checking if commit modifies only content files..."
4274
# Check if the commit touches only allowed folders
4375
MODIFIED_FILES=$(git diff-tree --no-commit-id --name-only -r ${{ steps.get-commit.outputs.commit_hash }})
44-
INVALID_FILES=$(echo "$MODIFIED_FILES" | grep -v -E '^(docs/cms/|docs/cloud/|static/img/assets/)')
76+
echo "Modified files:"
77+
echo "$MODIFIED_FILES"
78+
79+
INVALID_FILES=$(echo "$MODIFIED_FILES" | grep -v -E '^(docusaurus/docs/cms/|docusaurus/docs/cloud/|docusaurus/static/img/assets/)')
4580
4681
if [ -z "$INVALID_FILES" ]; then
82+
echo "All files are in content folders. Proceeding."
4783
echo "content_only=true" >> $GITHUB_OUTPUT
4884
else
85+
echo "Found files outside content folders:"
86+
echo "$INVALID_FILES"
4987
echo "content_only=false" >> $GITHUB_OUTPUT
5088
fi
5189
90+
- name: Debug - Check next branch
91+
if: steps.check-content-only.outputs.content_only == 'true'
92+
run: |
93+
git fetch origin next
94+
echo "Latest commits on next branch:"
95+
git log origin/next -n 3 --oneline
96+
5297
- name: Create PR to next branch
5398
if: steps.check-content-only.outputs.content_only == 'true'
5499
run: |
100+
echo "Creating PR to next branch..."
55101
BRANCH_NAME="sync-content-$(date +%Y%m%d-%H%M%S)"
102+
echo "New branch name: $BRANCH_NAME"
103+
56104
git fetch origin next
57105
git checkout -b $BRANCH_NAME origin/next
58106
107+
echo "Attempting cherry-pick of commit ${{ steps.get-commit.outputs.commit_hash }}..."
59108
git cherry-pick ${{ steps.get-commit.outputs.commit_hash }} || {
60-
if git diff --name-only --diff-filter=U | grep -q -E '^(docs/cms/|docs/cloud/|static/img/assets/)'; then
61-
# Try to resolve simple conflicts in content files
62-
git add $(git diff --name-only --diff-filter=U | grep -E '^(docs/cms/|docs/cloud/|static/img/assets/)')
109+
if git diff --name-only --diff-filter=U | grep -q -E '^(docusaurus/docs/cms/|docusaurus/docs/cloud/|docusaurus/static/img/assets/)'; then
110+
echo "Conflicts detected in content files, attempting to resolve..."
111+
CONFLICTED_FILES=$(git diff --name-only --diff-filter=U | grep -E '^(docusaurus/docs/cms/|docusaurus/docs/cloud/|docusaurus/static/img/assets/)')
112+
echo "Conflicted files:"
113+
echo "$CONFLICTED_FILES"
114+
git add $(echo "$CONFLICTED_FILES")
63115
git cherry-pick --continue
64116
else
65-
# If conflict involves other files, abort
117+
echo "Conflicts detected in non-content files, aborting cherry-pick"
66118
git cherry-pick --abort
67119
echo "Conflict detected in non-content files, cherry-pick aborted"
68120
exit 1
69121
fi
70122
}
71123
124+
echo "Cherry-pick successful, pushing branch..."
72125
git push origin $BRANCH_NAME
73126
74127
# Create a PR with a title that includes reference to the original commit
128+
echo "Creating PR from $BRANCH_NAME to next..."
75129
gh pr create --base next --head $BRANCH_NAME \
76130
--title "[Auto-sync] ${{ steps.get-commit.outputs.commit_msg }}" \
77131
--body "Automatic synchronization of commit from main: ${{ steps.get-commit.outputs.commit_hash }}\n\nChanges applied automatically by GitHub Actions."
132+
echo "PR creation completed"
78133
env:
79134
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}
80135

81136
# Job 2: Create PR to next when a PR is labeled
82137
create-pr-for-labeled:
83-
if: github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == "temp - port to docs-next"
138+
if: github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'port-to-docs-next'
139+
needs: debug-event
84140
runs-on: ubuntu-latest
85141
steps:
86142
- name: Checkout repository
@@ -94,63 +150,97 @@ jobs:
94150
git config user.name "GitHub Actions Bot"
95151
git config user.email "[email protected]"
96152
153+
- name: Debug - PR info
154+
run: |
155+
echo "PR Number: ${{ github.event.pull_request.number }}"
156+
echo "PR Title: ${{ github.event.pull_request.title }}"
157+
echo "PR Labels: ${{ toJSON(github.event.pull_request.labels) }}"
158+
echo "Added Label: ${{ github.event.label.name }}"
159+
97160
- name: Check if PR contains only content changes
98161
id: check-pr-files
99162
run: |
163+
echo "Checking if PR contains only content changes..."
100164
# Get list of modified files in the PR
101165
PR_FILES=$(gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files[].path')
166+
echo "Files in PR:"
167+
echo "$PR_FILES"
102168
103169
# Check if all files are in allowed directories
104-
INVALID_FILES=$(echo "$PR_FILES" | grep -v -E '^(docs/cms/|docs/cloud/|static/img/assets/)')
170+
INVALID_FILES=$(echo "$PR_FILES" | grep -v -E '^(docusaurus/docs/cms/|docusaurus/docs/cloud/|docusaurus/static/img/assets/)')
105171
106172
if [ -z "$INVALID_FILES" ]; then
173+
echo "All files are in content folders. Proceeding."
107174
echo "content_only=true" >> $GITHUB_OUTPUT
108175
else
176+
echo "Found files outside content folders:"
177+
echo "$INVALID_FILES"
109178
echo "content_only=false" >> $GITHUB_OUTPUT
110-
echo "Non-content files found: $INVALID_FILES"
111179
fi
112180
env:
113181
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}
114182

115183
- name: Create PR to next branch
116184
if: steps.check-pr-files.outputs.content_only == 'true'
117185
run: |
186+
echo "Creating PR to next branch..."
118187
# Get source branch of the original PR
119188
SOURCE_BRANCH="${{ github.event.pull_request.head.ref }}"
120189
SOURCE_REPO="${{ github.event.pull_request.head.repo.full_name }}"
121190
PR_TITLE="${{ github.event.pull_request.title }}"
122191
192+
echo "Source Branch: $SOURCE_BRANCH"
193+
echo "Source Repo: $SOURCE_REPO"
194+
123195
# Create a new branch based on next
124196
TARGET_BRANCH="next-port-pr${{ github.event.pull_request.number }}"
197+
echo "Target Branch: $TARGET_BRANCH"
198+
125199
git fetch origin next
126200
git checkout -b $TARGET_BRANCH origin/next
127201
128202
# If PR comes from a fork, fetch its changes
129203
if [ "$SOURCE_REPO" != "${{ github.repository }}" ]; then
204+
echo "PR comes from a fork, fetching changes from $SOURCE_REPO"
130205
git fetch "https://github.com/$SOURCE_REPO.git" $SOURCE_BRANCH
206+
else
207+
echo "PR is from the same repo"
208+
git fetch origin $SOURCE_BRANCH
131209
fi
132210
133211
# Get each modified file that matches our criteria
134-
for FILE in $(echo "$PR_FILES" | grep -E '^(docs/cms/|docs/cloud/|static/img/assets/)'); do
212+
echo "Getting content files from PR..."
213+
CONTENT_FILES=$(echo "$PR_FILES" | grep -E '^(docusaurus/docs/cms/|docusaurus/docs/cloud/|docusaurus/static/img/assets/)')
214+
echo "Content files to port:"
215+
echo "$CONTENT_FILES"
216+
217+
for FILE in $CONTENT_FILES; do
218+
echo "Processing file: $FILE"
135219
mkdir -p $(dirname "$FILE")
136220
git checkout FETCH_HEAD -- "$FILE"
137221
done
138222
139223
# Commit and push
224+
echo "Committing changes..."
140225
git add .
141226
git commit -m "Port PR #${{ github.event.pull_request.number }}: $PR_TITLE to next branch"
227+
228+
echo "Pushing branch..."
142229
git push origin $TARGET_BRANCH
143230
144231
# Create PR to next
232+
echo "Creating PR from $TARGET_BRANCH to next..."
145233
gh pr create --base next --head $TARGET_BRANCH \
146234
--title "[Port to next] $PR_TITLE" \
147-
--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."
235+
--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 'port-to-docs-next' label."
236+
echo "PR creation completed"
148237
env:
149238
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}
150239

151240
# Job 3: Sync changes when a labeled PR is merged to main
152241
sync-merged-pr:
153-
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'temp - port to docs-next')
242+
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'port-to-docs-next')
243+
needs: debug-event
154244
runs-on: ubuntu-latest
155245
steps:
156246
- name: Checkout repository
@@ -164,45 +254,73 @@ jobs:
164254
git config user.name "GitHub Actions Bot"
165255
git config user.email "[email protected]"
166256
257+
- name: Debug - Merged PR info
258+
run: |
259+
echo "Merged PR Number: ${{ github.event.pull_request.number }}"
260+
echo "PR Title: ${{ github.event.pull_request.title }}"
261+
echo "Merge commit: ${{ github.event.pull_request.merge_commit_sha }}"
262+
echo "PR Labels: ${{ toJSON(github.event.pull_request.labels) }}"
263+
167264
- name: Get merge commit
168265
id: get-merge-commit
169266
run: |
267+
echo "Getting merge commit..."
170268
MERGE_COMMIT=$(git log -1 --format="%H" ${{ github.event.pull_request.merge_commit_sha }})
269+
echo "Merge commit: $MERGE_COMMIT"
171270
echo "merge_commit=$MERGE_COMMIT" >> $GITHUB_OUTPUT
172271
272+
- name: Debug - Examine merge commit
273+
run: |
274+
echo "Examining merge commit details:"
275+
git show ${{ steps.get-merge-commit.outputs.merge_commit }} --name-only
276+
173277
- name: Cherry-pick merge commit to next
174278
run: |
279+
echo "Creating PR to next branch..."
175280
BRANCH_NAME="sync-merged-pr${{ github.event.pull_request.number }}"
281+
echo "New branch name: $BRANCH_NAME"
282+
176283
git fetch origin next
177284
git checkout -b $BRANCH_NAME origin/next
178285
286+
echo "Attempting cherry-pick of merge commit ${{ steps.get-merge-commit.outputs.merge_commit }}..."
179287
# For a merge commit, we need to use -m 1 to cherry-pick the parent changes
180288
git cherry-pick -m 1 ${{ steps.get-merge-commit.outputs.merge_commit }} || {
181-
if git diff --name-only --diff-filter=U | grep -q -E '^(docs/cms/|docs/cloud/|static/img/assets/)'; then
182-
# Try to resolve simple conflicts in content files
183-
git add $(git diff --name-only --diff-filter=U | grep -E '^(docs/cms/|docs/cloud/|static/img/assets/)')
289+
if git diff --name-only --diff-filter=U | grep -q -E '^(docusaurus/docs/cms/|docusaurus/docs/cloud/|docusaurus/static/img/assets/)'; then
290+
echo "Conflicts detected in content files, attempting to resolve..."
291+
CONFLICTED_FILES=$(git diff --name-only --diff-filter=U | grep -E '^(docusaurus/docs/cms/|docusaurus/docs/cloud/|docusaurus/static/img/assets/)')
292+
echo "Conflicted files:"
293+
echo "$CONFLICTED_FILES"
294+
git add $(echo "$CONFLICTED_FILES")
184295
git cherry-pick --continue
185296
else
186-
# If conflict involves other files, abort
297+
echo "Conflicts detected in non-content files, aborting cherry-pick"
187298
git cherry-pick --abort
188299
echo "Conflict detected in non-content files, cherry-pick aborted"
189300
exit 1
190301
fi
191302
}
192303
304+
echo "Cherry-pick successful, pushing branch..."
193305
git push origin $BRANCH_NAME
194306
195307
# Find if there's an existing PR for this original PR
308+
echo "Checking for existing port PRs..."
196309
EXISTING_PORT_PR=$(gh pr list --base next --head "next-port-pr${{ github.event.pull_request.number }}" --json number --jq '.[0].number')
197310
198311
if [ -n "$EXISTING_PORT_PR" ]; then
199312
# If a PR already exists, close it and add a comment
313+
echo "Found existing PR #$EXISTING_PORT_PR, closing it..."
200314
gh pr close $EXISTING_PORT_PR --comment "This PR is replaced by the direct synchronization of the merge commit: #INSERT_NEW_PR_NUMBER_HERE"
315+
else
316+
echo "No existing port PR found"
201317
fi
202318
203319
# Create PR to next
320+
echo "Creating PR from $BRANCH_NAME to next..."
204321
gh pr create --base next --head $BRANCH_NAME \
205322
--title "[Merged-sync] ${{ github.event.pull_request.title }}" \
206323
--body "Synchronization of the merge commit from PR #${{ github.event.pull_request.number }} to next.\n\nThis PR replaces any previous port PR created for #${{ github.event.pull_request.number }}."
324+
echo "PR creation completed"
207325
env:
208326
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}

0 commit comments

Comments
 (0)