Skip to content

Commit 2102181

Browse files
committed
[CI] Different approach to automating backports #501
Automates cherry-picking fixes to stable branches via [baackport X.Y] in commit messages or /backport X.Y comments, with conflict notification Fixes #501
1 parent 8c51bdf commit 2102181

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

.github/workflows/backport.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Backport fixes to stable branch
22

33
on:
4-
pull_request_target:
5-
types: [closed]
4+
push:
5+
branches:
6+
- master
67
issue_comment:
78
types: [created]
89

@@ -11,18 +12,20 @@ permissions:
1112
pull-requests: write
1213

1314
jobs:
14-
backport:
15+
backport-on-push:
16+
if: github.event_name == 'push'
17+
uses: ./.github/workflows/reusable-backport.yml
18+
with:
19+
commit_sha: ${{ github.sha }}
20+
21+
backport-on-comment:
1522
if: >
16-
(
17-
github.event_name == 'pull_request_target' &&
18-
github.event.pull_request.merged
19-
) || (
20-
github.event_name == 'issue_comment' &&
21-
github.event.issue.pull_request &&
22-
github.event.issue.state == 'closed' &&
23-
contains(fromJSON('["MEMBER", "OWNER"]'), github.event.comment.author_association) &&
24-
github.event.comment.body == '/backport'
25-
)
23+
github.event_name == 'issue_comment' &&
24+
github.event.issue.pull_request &&
25+
github.event.issue.state == 'closed' &&
26+
contains(fromJSON('["MEMBER", "OWNER"]'), github.event.comment.author_association) &&
27+
startsWith(github.event.comment.body, '/backport')
2628
uses: ./.github/workflows/reusable-backport.yml
2729
with:
28-
source_pr_number: ${{ github.event.pull_request.number || github.event.issue.number }}
30+
pr_number: ${{ github.event.issue.number }}
31+
comment_body: ${{ github.event.comment.body }}

.github/workflows/reusable-backport.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,20 @@ jobs:
8888
--title "[backport] $PR_TITLE (to $BRANCH)" \
8989
--body "Backport of #$PR_NUMBER to \`$BRANCH\`."
9090
else
91-
git cherry-pick --abort
92-
gh pr comment "$PR_NUMBER" \
93-
--body "❌ Cherry-pick to \`$BRANCH\` failed due to conflicts. Please backport manually:
94-
95-
\`\`\`bash
96-
git fetch origin $BRANCH
97-
git checkout -b backport/${PR_NUMBER}-to-${BRANCH} origin/$BRANCH
98-
git cherry-pick -x $SHA
99-
# resolve conflicts
100-
git cherry-pick --continue
101-
git push origin backport/${PR_NUMBER}-to-${BRANCH}
102-
\`\`\`
103-
104-
Then open a PR targeting \`$BRANCH\`."
91+
git cherry-pick --abort || true
92+
{
93+
echo "❌ Cherry-pick to \`$BRANCH\` failed due to conflicts. Please backport manually:"
94+
echo ""
95+
echo "\`\`\`bash"
96+
echo "git fetch origin $BRANCH master"
97+
echo "git checkout -b backport/${PR_NUMBER}-to-${BRANCH} origin/$BRANCH"
98+
echo "git cherry-pick -x $SHA"
99+
echo "# resolve conflicts"
100+
echo "git cherry-pick --continue"
101+
echo "git push origin backport/${PR_NUMBER}-to-${BRANCH}"
102+
echo "\`\`\`"
103+
echo ""
104+
echo "Then open a PR targeting \`$BRANCH\`."
105+
} > /tmp/backport-comment.md
106+
gh pr comment "$PR_NUMBER" --body-file /tmp/backport-comment.md
105107
fi

0 commit comments

Comments
 (0)