9
9
workflow_dispatch :
10
10
inputs :
11
11
milestone_name :
12
- description : ' Milestone name to collect closed PRs from'
12
+ description : " Milestone name to collect closed PRs from"
13
13
required : true
14
- default : ' v3.8.2 '
14
+ default : " v3.8.3 "
15
15
target_branch :
16
- description : ' Target branch to merge the consolidated PR'
16
+ description : " Target branch to merge the consolidated PR"
17
17
required : true
18
- default : ' pre-release-v3.8.2 '
18
+ default : " pre-release-v3.8.3 "
19
19
20
20
env :
21
- MILESTONE_NAME : ${{ github.event.inputs.milestone_name || 'v3.8.2 ' }}
22
- TARGET_BRANCH : ${{ github.event.inputs.target_branch || 'pre-release-v3.8.2 ' }}
21
+ MILESTONE_NAME : ${{ github.event.inputs.milestone_name || 'v3.8.3 ' }}
22
+ TARGET_BRANCH : ${{ github.event.inputs.target_branch || 'pre-release-v3.8.3 ' }}
23
23
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
24
24
BOT_TOKEN : ${{ secrets.BOT_TOKEN }}
25
25
LABEL_NAME : cherry-picked
26
- TEMP_DIR : /tmp # Using /tmp as the temporary directory
26
+ TEMP_DIR : /tmp # Using /tmp as the temporary directory
27
27
28
28
jobs :
29
- cherry_pick_milestone_prs :
29
+ merge_milestone_prs :
30
30
runs-on : ubuntu-latest
31
31
steps :
32
32
- name : Setup temp directory
47
47
48
48
- name : Setup Git User for OpenIM-Robot
49
49
run : |
50
- # Set up Git credentials for the bot
51
50
git config --global user.email "[email protected] "
52
51
git config --global user.name "OpenIM-Robot"
53
52
@@ -83,136 +82,51 @@ jobs:
83
82
if ! echo "$labels" | grep -q "${LABEL_NAME}"; then
84
83
echo "PR #$pr_number does not have the 'cherry-picked' label. Adding to the list."
85
84
echo "$pr_number" >> ${{ env.TEMP_DIR }}/pr_numbers.txt
86
- else
87
- echo "PR #$pr_number already has the 'cherry-picked' label. Skipping."
88
85
fi
89
86
done
90
87
91
- # Sort the filtered PR numbers
92
88
sort -n ${{ env.TEMP_DIR }}/pr_numbers.txt -o ${{ env.TEMP_DIR }}/pr_numbers.txt
93
89
94
- echo "Filtered and sorted PR numbers:"
95
- cat ${{ env.TEMP_DIR }}/pr_numbers.txt || echo "No closed PR numbers found for milestone."
96
-
97
- - name : Fetch Merge Commits for PRs and Generate Title and Body
90
+ - name : Create Individual PRs
98
91
run : |
99
- # Ensure the files are initialized
100
- > ${{ env.TEMP_DIR }}/commit_hashes.txt
101
- > ${{ env.TEMP_DIR }}/pr_title.txt
102
- > ${{ env.TEMP_DIR }}/pr_body.txt
103
-
104
- # Write description to the PR body
105
- echo "### Description:" >> ${{ env.TEMP_DIR }}/pr_body.txt
106
- echo "Merging PRs from milestone \`$MILESTONE_NAME\` into target branch \`$TARGET_BRANCH\`." >> ${{ env.TEMP_DIR }}/pr_body.txt
107
- echo "" >> ${{ env.TEMP_DIR }}/pr_body.txt
108
- echo "### Need Merge PRs:" >> ${{ env.TEMP_DIR }}/pr_body.txt
109
-
110
- pr_numbers_in_title=""
111
-
112
- # Process sorted PR numbers and generate commit hashes
113
92
for pr_number in $(cat ${{ env.TEMP_DIR }}/pr_numbers.txt); do
114
- echo "Processing PR #$pr_number"
115
93
pr_details=$(curl -s -H "Authorization: token $BOT_TOKEN" \
116
94
-H "Accept: application/vnd.github+json" \
117
95
"https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number")
118
96
pr_title=$(echo "$pr_details" | jq -r '.title')
97
+ pr_body=$(echo "$pr_details" | jq -r '.body')
98
+ pr_creator=$(echo "$pr_details" | jq -r '.user.login')
119
99
merge_commit=$(echo "$pr_details" | jq -r '.merge_commit_sha')
120
100
short_commit_hash=$(echo "$merge_commit" | cut -c 1-7)
121
101
122
- # Append PR details to the body
123
- echo "- $pr_title: (#$pr_number) ($short_commit_hash)" >> ${{ env.TEMP_DIR }}/pr_body.txt
124
-
125
102
if [ "$merge_commit" != "null" ];then
126
- echo "$merge_commit" >> ${{ env.TEMP_DIR }}/commit_hashes.txt
127
- echo "#$pr_number" >> ${{ env.TEMP_DIR }}/pr_title.txt
128
- pr_numbers_in_title="$pr_numbers_in_title #$pr_number"
129
- fi
130
- done
103
+ git fetch origin
104
+ git checkout $TARGET_BRANCH
105
+ git pull origin $TARGET_BRANCH
106
+ cherry_pick_branch="cherry-pick-${short_commit_hash}"
107
+ git checkout -b $cherry_pick_branch
108
+ git cherry-pick "$merge_commit" --strategy=recursive -X theirs || git cherry-pick --continue
109
+ git remote set-url origin "https://${BOT_TOKEN}@github.com/${{ github.repository }}.git"
110
+ git push origin $cherry_pick_branch --force
111
+
112
+ new_pr_title="$pr_title [Created by @$pr_creator from #$pr_number]"
113
+ new_pr_body="$pr_body \\n >This PR cherry-picks commit from original PR #$pr_number."
114
+
115
+ response=$(curl -s -X POST -H "Authorization: token $BOT_TOKEN" \
116
+ -H "Accept: application/vnd.github+json" \
117
+ https://api.github.com/repos/${{ github.repository }}/pulls \
118
+ -d "$(jq -n --arg title "$new_pr_title" \
119
+ --arg head "$cherry_pick_branch" \
120
+ --arg base "$TARGET_BRANCH" \
121
+ --arg body "$new_pr_body" \
122
+ '{title: $title, head: $head, base: $base, body: $body}')")
131
123
132
- commit_hashes=$(cat ${{ env.TEMP_DIR }}/commit_hashes.txt | tr '\n' ' ')
133
- first_commit_hash=$(head -n 1 ${{ env.TEMP_DIR }}/commit_hashes.txt)
134
- cherry_pick_branch="cherry-pick-${first_commit_hash:0:7}"
135
- echo "COMMIT_HASHES=$commit_hashes" >> $GITHUB_ENV
136
- echo "CHERRY_PICK_BRANCH=$cherry_pick_branch" >> $GITHUB_ENV
137
- echo "pr_numbers_in_title=$pr_numbers_in_title" >> $GITHUB_ENV
124
+ new_pr_number=$(echo "$response" | jq -r '.number')
125
+ echo "Created PR #$new_pr_number"
138
126
139
- - name : Pull and Cherry-pick Commits, Then Push
140
- env :
141
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
142
- BOT_TOKEN : ${{ secrets.BOT_TOKEN }}
143
- run : |
144
- # Fetch and pull the latest changes from the target branch
145
- git fetch origin
146
- git checkout $TARGET_BRANCH
147
- git pull origin $TARGET_BRANCH
148
-
149
- # Create a new branch for cherry-picking
150
- git checkout -b $CHERRY_PICK_BRANCH
151
-
152
- # Cherry-pick the commits and handle conflicts
153
- for commit_hash in $COMMIT_HASHES; do
154
- echo "Attempting to cherry-pick commit $commit_hash"
155
- if ! git cherry-pick "$commit_hash" --strategy=recursive -X theirs; then
156
- echo "Conflict detected for $commit_hash. Resolving with incoming changes."
157
- conflict_files=$(git diff --name-only --diff-filter=U)
158
- echo "Conflicting files:"
159
- echo "$conflict_files"
160
-
161
- for file in $conflict_files; do
162
- if [ -f "$file" ]; then
163
- echo "Resolving conflict for $file"
164
- git add "$file"
165
- else
166
- echo "File $file has been deleted. Skipping."
167
- git rm "$file"
168
- fi
169
- done
170
-
171
- echo "Conflicts resolved. Continuing cherry-pick."
172
- git cherry-pick --continue
173
- else
174
- echo "Cherry-pick successful for commit $commit_hash."
127
+ curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
128
+ -H "Accept: application/vnd.github+json" \
129
+ -d '{"labels": ["milestone-merge"]}' \
130
+ "https://api.github.com/repos/${{ github.repository }}/issues/$new_pr_number/labels"
175
131
fi
176
- done
177
-
178
- # Push the cherry-pick branch to the repository
179
- git remote set-url origin "https://${BOT_TOKEN}@github.com/${{ github.repository }}.git"
180
- git push origin $CHERRY_PICK_BRANCH --force
181
-
182
- - name : Create Pull Request
183
- run : |
184
- # Prepare and create the PR
185
- pr_title="deps: Merge ${{ env.pr_numbers_in_title }} PRs into $TARGET_BRANCH"
186
- pr_body=$(cat ${{ env.TEMP_DIR }}/pr_body.txt)
187
-
188
- echo "Prepared PR title:"
189
- echo "$pr_title"
190
- echo "Prepared PR body:"
191
- echo "$pr_body"
192
-
193
- # Create the PR using the GitHub API
194
- response=$(curl -s -X POST -H "Authorization: token $BOT_TOKEN" \
195
- -H "Accept: application/vnd.github+json" \
196
- https://api.github.com/repos/${{ github.repository }}/pulls \
197
- -d "$(jq -n --arg title "$pr_title" \
198
- --arg head "$CHERRY_PICK_BRANCH" \
199
- --arg base "$TARGET_BRANCH" \
200
- --arg body "$pr_body" \
201
- '{title: $title, head: $head, base: $base, body: $body}')")
202
-
203
- pr_number=$(echo "$response" | jq -r '.number')
204
- echo "$pr_number" > ${{ env.TEMP_DIR }}/created_pr_number.txt
205
- echo "Created PR #$pr_number"
206
-
207
- - name : Add Label to Created Pull Request
208
- run : |
209
- # Add 'milestone-merge' label to the created PR
210
- pr_number=$(cat ${{ env.TEMP_DIR }}/created_pr_number.txt)
211
- echo "Adding label to PR #$pr_number"
212
-
213
- curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
214
- -H "Accept: application/vnd.github+json" \
215
- -d '{"labels": ["milestone-merge"]}' \
216
- "https://api.github.com/repos/${{ github.repository }}/issues/$pr_number/labels"
217
-
218
- echo "Added 'milestone-merge' label to PR #$pr_number."
132
+ done
0 commit comments