Skip to content

Commit 37d4443

Browse files
authored
Merge pull request #9405 from bluetech/ci-backport
ci: add a workflow for backporting to other branches
2 parents 0bc77de + c85b143 commit 37d4443

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

.github/workflows/backport.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: backport
2+
3+
on:
4+
pull_request:
5+
types: [labeled]
6+
7+
# Set permissions at the job level.
8+
permissions: {}
9+
10+
jobs:
11+
backport:
12+
if: ${{ startsWith(github.event.label.name, 'backport ') }}
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
with:
21+
fetch-depth: 0
22+
persist-credentials: true
23+
24+
- name: Create backport PR
25+
run: |
26+
set -eux
27+
28+
git config --global user.name "pytest bot"
29+
git config --global user.email "[email protected]"
30+
31+
label='${{ github.event.label.name }}'
32+
target_branch="${label#backport }"
33+
backport_branch=backport-${{ github.event.number }}-to-"${target_branch}"
34+
subject="[$target_branch] $(gh pr view --json title -q .title ${{ github.event.number }})"
35+
36+
git checkout origin/"${target_branch}" -b "${backport_branch}"
37+
git cherry-pick -x --mainline 1 ${{ github.event.pull_request.merge_commit_sha }}
38+
git commit --amend --message "$subject"
39+
git push --set-upstream origin --force-with-lease "${backport_branch}"
40+
gh pr create \
41+
--base "${target_branch}" \
42+
--title "${subject}" \
43+
--body "Backport of PR #${{ github.event.number }} to $target_branch branch. PR created by backport workflow."
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CONTRIBUTING.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,13 @@ actual latest release). The procedure for this is:
391391
request, as described above. An exception to this is if the bug fix is not
392392
applicable to ``main`` anymore.
393393

394+
Automatic method:
395+
396+
Add a ``backport 1.2.x`` label to the PR you want to backport. This will create
397+
a backport PR against the ``1.2.x`` branch.
398+
399+
Manual method:
400+
394401
#. ``git checkout origin/1.2.x -b backport-XXXX`` # use the main PR number here
395402

396403
#. Locate the merge commit on the PR, in the *merged* message, for example:

0 commit comments

Comments
 (0)