11name : Backport
22# Creates backport PRs when someone comments "/backport <branch>" on a PR.
3- # Also auto-updates existing backport PRs when the source PR is updated .
3+ # Updates existing backport PRs when someone comments "/update-backports" on a PR .
44
55on :
66 issue_comment :
77 types : [created]
8- pull_request :
9- branches : [main]
10- types : [synchronize]
118
129permissions :
1310 contents : read
@@ -191,10 +188,13 @@ jobs:
191188 echo " 5. gh pr create --base <target-branch>"
192189 fi
193190
194- # ─── Job 2: Auto-update backport PRs when source PR is updated ───
191+ # ─── Job 2: Update backport PRs via /update-backports comment ───
195192 update-backport :
196193 name : Update backport PRs
197- if : github.event_name == 'pull_request' && github.event.action == 'synchronize'
194+ if : >
195+ github.event_name == 'issue_comment' &&
196+ github.event.issue.pull_request != '' &&
197+ github.event.comment.body == '/update-backports'
198198 runs-on : ubuntu-latest
199199 permissions :
200200 contents : write
@@ -207,12 +207,31 @@ jobs:
207207 app-id : ${{ vars.APP_ID }}
208208 private-key : ${{ secrets.GH_APP_PRIVATE_KEY }}
209209
210+ - name : React to comment
211+ env :
212+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
213+ run : |
214+ gh api \
215+ --method POST \
216+ repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \
217+ -f content='+1'
218+
219+ - name : Get PR details
220+ id : pr
221+ env :
222+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
223+ PR_URL : ${{ github.event.issue.pull_request.url }}
224+ run : |
225+ PR_DATA=$(gh api "$PR_URL")
226+ echo "number=$(echo "$PR_DATA" | jq -r '.number')" >> "$GITHUB_OUTPUT"
227+ echo "head_branch=$(echo "$PR_DATA" | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
228+
210229 - name : Find linked backport PRs
211230 id : find-backports
212231 env :
213232 GH_TOKEN : ${{ steps.app-token.outputs.token }}
214- HEAD_BRANCH : ${{ github.event.pull_request.head.ref }}
215- PR_NUMBER : ${{ github.event.pull_request .number }}
233+ HEAD_BRANCH : ${{ steps.pr.outputs.head_branch }}
234+ PR_NUMBER : ${{ steps.pr.outputs .number }}
216235 REPO : ${{ github.repository }}
217236 run : |
218237 # Search for open PRs whose branch matches the pattern <version>/<head-branch>
@@ -226,6 +245,8 @@ jobs:
226245 if [ -z "$BACKPORT_PRS" ]; then
227246 echo "No backport PRs found for branch $HEAD_BRANCH"
228247 echo "found=false" >> "$GITHUB_OUTPUT"
248+ gh pr comment "$PR_NUMBER" --repo "$REPO" \
249+ --body ":information_source: No open backport PRs found for branch \`$HEAD_BRANCH\`."
229250 else
230251 echo "Found backport PRs:"
231252 echo "$BACKPORT_PRS"
@@ -251,12 +272,13 @@ jobs:
251272 if : steps.find-backports.outputs.found == 'true'
252273 env :
253274 GH_TOKEN : ${{ steps.app-token.outputs.token }}
254- PR_NUMBER : ${{ github.event.pull_request .number }}
275+ PR_NUMBER : ${{ steps.pr.outputs .number }}
255276 REPO : ${{ github.repository }}
256277 run : |
257278 # Get current commits from the source PR
258279 COMMITS=$(gh api "repos/$REPO/pulls/$PR_NUMBER/commits" --jq '.[].sha')
259280
281+ RESULTS=""
260282 while IFS= read -r LINE; do
261283 BP_NUMBER=$(echo "$LINE" | awk '{print $1}')
262284 BP_BRANCH=$(echo "$LINE" | awk '{print $2}')
@@ -280,14 +302,16 @@ jobs:
280302
281303 if [ "$CHERRY_PICK_FAILED" = true ]; then
282304 echo "::warning::Cherry-pick failed while updating backport PR #$BP_NUMBER"
283- gh pr comment "$PR_NUMBER" --repo "$REPO" \
284- --body ":warning: Failed to auto-update backport PR #$BP_NUMBER to \`$BP_BASE\` due to conflicts. Manual update needed."
285- gh pr comment "$BP_NUMBER" --repo "$REPO" \
286- --body ":warning: Auto-update from source PR #$PR_NUMBER failed due to cherry-pick conflicts. Manual update needed."
305+ RESULTS="$RESULTS\n- :x: #$BP_NUMBER (\`$BP_BASE\`): cherry-pick conflicts (manual update needed)"
287306 else
288307 git push -f origin "$BP_BRANCH"
289308 echo "Successfully updated backport PR #$BP_NUMBER"
309+ RESULTS="$RESULTS\n- :white_check_mark: #$BP_NUMBER (\`$BP_BASE\`): updated"
290310 fi
291311
292312 echo "::endgroup::"
293313 done < /tmp/backport-prs.txt
314+
315+ # Post summary comment
316+ COMMENT_BODY="## Backport update results\n$RESULTS"
317+ gh pr comment "$PR_NUMBER" --repo "$REPO" --body "$(echo -e "$COMMENT_BODY")"
0 commit comments