5
5
branches :
6
6
- main
7
7
paths :
8
- - ' docs/cms/**'
9
- - ' docs/cloud/**'
10
- - ' static/img/assets/**'
8
+ - ' docusaurus/ docs/cms/**'
9
+ - ' docusaurus/ docs/cloud/**'
10
+ - ' docusaurus/ static/img/assets/**'
11
11
pull_request :
12
12
types : [labeled, closed]
13
13
14
14
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
+
15
37
# Job 1: Automatic replication of commits pushed to main
16
38
cherry-pick-from-push :
17
39
if : github.event_name == 'push'
40
+ needs : debug-event
18
41
runs-on : ubuntu-latest
19
42
steps :
20
43
- name : Checkout repository
@@ -28,59 +51,92 @@ jobs:
28
51
git config user.name "GitHub Actions Bot"
29
52
git config user.email "[email protected] "
30
53
54
+ - name : Debug - List recent commits
55
+ run : |
56
+ echo "Recent commits on main:"
57
+ git log -n 5 --oneline
58
+
31
59
- name : Get latest commit that modified content
32
60
id : get-commit
33
61
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)
35
64
COMMIT_MSG=$(git log -1 --format="%s" $COMMIT_HASH)
65
+ echo "Found commit: $COMMIT_HASH"
66
+ echo "Commit message: $COMMIT_MSG"
36
67
echo "commit_hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
37
68
echo "commit_msg=$COMMIT_MSG" >> $GITHUB_OUTPUT
38
69
39
70
- name : Check if commit modifies only content files
40
71
id : check-content-only
41
72
run : |
73
+ echo "Checking if commit modifies only content files..."
42
74
# Check if the commit touches only allowed folders
43
75
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/)')
45
80
46
81
if [ -z "$INVALID_FILES" ]; then
82
+ echo "All files are in content folders. Proceeding."
47
83
echo "content_only=true" >> $GITHUB_OUTPUT
48
84
else
85
+ echo "Found files outside content folders:"
86
+ echo "$INVALID_FILES"
49
87
echo "content_only=false" >> $GITHUB_OUTPUT
50
88
fi
51
89
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
+
52
97
- name : Create PR to next branch
53
98
if : steps.check-content-only.outputs.content_only == 'true'
54
99
run : |
100
+ echo "Creating PR to next branch..."
55
101
BRANCH_NAME="sync-content-$(date +%Y%m%d-%H%M%S)"
102
+ echo "New branch name: $BRANCH_NAME"
103
+
56
104
git fetch origin next
57
105
git checkout -b $BRANCH_NAME origin/next
58
106
107
+ echo "Attempting cherry-pick of commit ${{ steps.get-commit.outputs.commit_hash }}..."
59
108
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")
63
115
git cherry-pick --continue
64
116
else
65
- # If conflict involves other files, abort
117
+ echo "Conflicts detected in non-content files, aborting cherry-pick"
66
118
git cherry-pick --abort
67
119
echo "Conflict detected in non-content files, cherry-pick aborted"
68
120
exit 1
69
121
fi
70
122
}
71
123
124
+ echo "Cherry-pick successful, pushing branch..."
72
125
git push origin $BRANCH_NAME
73
126
74
127
# Create a PR with a title that includes reference to the original commit
128
+ echo "Creating PR from $BRANCH_NAME to next..."
75
129
gh pr create --base next --head $BRANCH_NAME \
76
130
--title "[Auto-sync] ${{ steps.get-commit.outputs.commit_msg }}" \
77
131
--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"
78
133
env :
79
134
GITHUB_TOKEN : ${{ secrets.SYNC_MAIN_TO_NEXT }}
80
135
81
136
# Job 2: Create PR to next when a PR is labeled
82
137
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
84
140
runs-on : ubuntu-latest
85
141
steps :
86
142
- name : Checkout repository
@@ -94,63 +150,97 @@ jobs:
94
150
git config user.name "GitHub Actions Bot"
95
151
git config user.email "[email protected] "
96
152
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
+
97
160
- name : Check if PR contains only content changes
98
161
id : check-pr-files
99
162
run : |
163
+ echo "Checking if PR contains only content changes..."
100
164
# Get list of modified files in the PR
101
165
PR_FILES=$(gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files[].path')
166
+ echo "Files in PR:"
167
+ echo "$PR_FILES"
102
168
103
169
# 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/)')
105
171
106
172
if [ -z "$INVALID_FILES" ]; then
173
+ echo "All files are in content folders. Proceeding."
107
174
echo "content_only=true" >> $GITHUB_OUTPUT
108
175
else
176
+ echo "Found files outside content folders:"
177
+ echo "$INVALID_FILES"
109
178
echo "content_only=false" >> $GITHUB_OUTPUT
110
- echo "Non-content files found: $INVALID_FILES"
111
179
fi
112
180
env :
113
181
GITHUB_TOKEN : ${{ secrets.SYNC_MAIN_TO_NEXT }}
114
182
115
183
- name : Create PR to next branch
116
184
if : steps.check-pr-files.outputs.content_only == 'true'
117
185
run : |
186
+ echo "Creating PR to next branch..."
118
187
# Get source branch of the original PR
119
188
SOURCE_BRANCH="${{ github.event.pull_request.head.ref }}"
120
189
SOURCE_REPO="${{ github.event.pull_request.head.repo.full_name }}"
121
190
PR_TITLE="${{ github.event.pull_request.title }}"
122
191
192
+ echo "Source Branch: $SOURCE_BRANCH"
193
+ echo "Source Repo: $SOURCE_REPO"
194
+
123
195
# Create a new branch based on next
124
196
TARGET_BRANCH="next-port-pr${{ github.event.pull_request.number }}"
197
+ echo "Target Branch: $TARGET_BRANCH"
198
+
125
199
git fetch origin next
126
200
git checkout -b $TARGET_BRANCH origin/next
127
201
128
202
# If PR comes from a fork, fetch its changes
129
203
if [ "$SOURCE_REPO" != "${{ github.repository }}" ]; then
204
+ echo "PR comes from a fork, fetching changes from $SOURCE_REPO"
130
205
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
131
209
fi
132
210
133
211
# 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"
135
219
mkdir -p $(dirname "$FILE")
136
220
git checkout FETCH_HEAD -- "$FILE"
137
221
done
138
222
139
223
# Commit and push
224
+ echo "Committing changes..."
140
225
git add .
141
226
git commit -m "Port PR #${{ github.event.pull_request.number }}: $PR_TITLE to next branch"
227
+
228
+ echo "Pushing branch..."
142
229
git push origin $TARGET_BRANCH
143
230
144
231
# Create PR to next
232
+ echo "Creating PR from $TARGET_BRANCH to next..."
145
233
gh pr create --base next --head $TARGET_BRANCH \
146
234
--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"
148
237
env :
149
238
GITHUB_TOKEN : ${{ secrets.SYNC_MAIN_TO_NEXT }}
150
239
151
240
# Job 3: Sync changes when a labeled PR is merged to main
152
241
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
154
244
runs-on : ubuntu-latest
155
245
steps :
156
246
- name : Checkout repository
@@ -164,45 +254,73 @@ jobs:
164
254
git config user.name "GitHub Actions Bot"
165
255
git config user.email "[email protected] "
166
256
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
+
167
264
- name : Get merge commit
168
265
id : get-merge-commit
169
266
run : |
267
+ echo "Getting merge commit..."
170
268
MERGE_COMMIT=$(git log -1 --format="%H" ${{ github.event.pull_request.merge_commit_sha }})
269
+ echo "Merge commit: $MERGE_COMMIT"
171
270
echo "merge_commit=$MERGE_COMMIT" >> $GITHUB_OUTPUT
172
271
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
+
173
277
- name : Cherry-pick merge commit to next
174
278
run : |
279
+ echo "Creating PR to next branch..."
175
280
BRANCH_NAME="sync-merged-pr${{ github.event.pull_request.number }}"
281
+ echo "New branch name: $BRANCH_NAME"
282
+
176
283
git fetch origin next
177
284
git checkout -b $BRANCH_NAME origin/next
178
285
286
+ echo "Attempting cherry-pick of merge commit ${{ steps.get-merge-commit.outputs.merge_commit }}..."
179
287
# For a merge commit, we need to use -m 1 to cherry-pick the parent changes
180
288
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")
184
295
git cherry-pick --continue
185
296
else
186
- # If conflict involves other files, abort
297
+ echo "Conflicts detected in non-content files, aborting cherry-pick"
187
298
git cherry-pick --abort
188
299
echo "Conflict detected in non-content files, cherry-pick aborted"
189
300
exit 1
190
301
fi
191
302
}
192
303
304
+ echo "Cherry-pick successful, pushing branch..."
193
305
git push origin $BRANCH_NAME
194
306
195
307
# Find if there's an existing PR for this original PR
308
+ echo "Checking for existing port PRs..."
196
309
EXISTING_PORT_PR=$(gh pr list --base next --head "next-port-pr${{ github.event.pull_request.number }}" --json number --jq '.[0].number')
197
310
198
311
if [ -n "$EXISTING_PORT_PR" ]; then
199
312
# If a PR already exists, close it and add a comment
313
+ echo "Found existing PR #$EXISTING_PORT_PR, closing it..."
200
314
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"
201
317
fi
202
318
203
319
# Create PR to next
320
+ echo "Creating PR from $BRANCH_NAME to next..."
204
321
gh pr create --base next --head $BRANCH_NAME \
205
322
--title "[Merged-sync] ${{ github.event.pull_request.title }}" \
206
323
--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"
207
325
env :
208
326
GITHUB_TOKEN : ${{ secrets.SYNC_MAIN_TO_NEXT }}
0 commit comments