|
1 | | -Automate backport PR |
| 1 | +# `backport` - Tool to semi-automate backport pull requests |
2 | 2 |
|
3 | | -## Prerequisites |
| 3 | +This tool is used to backport pull requests labeled `to-be-backported`. |
4 | 4 |
|
5 | | -Requires installation of PyGithub |
6 | | -```shell |
7 | | -pip install pygithub |
8 | | -``` |
| 5 | +Generally backport PRs are [automatically created by GitHub Actions workflow](https://github.com/cupy/cupy/blob/main/.github/workflows/backport.yml). |
| 6 | +However, in case there is a conflict during the backport process, you need to run this tool in your local environment to manually resolve the conflict. |
9 | 7 |
|
10 | | -Token is [provided from Github](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/). Scope with `repo/public_repo` is required. |
| 8 | +## Prerequisites |
11 | 9 |
|
12 | | -Script requires authentication to github.com via SSH. [Directions here](https://help.github.com/articles/connecting-to-github-with-ssh/). |
| 10 | +1. Create a [classic GitHub token with `public_repo` scope](https://github.com/settings/tokens/new?scopes=public_repo). |
| 11 | +2. Install PyGitHub (`pip install pygithub`). |
13 | 12 |
|
14 | 13 | ## Usage |
15 | 14 |
|
16 | | -``` |
17 | | -usage: backport.py [-h] --repo {chainer,cupy} --token TOKEN --pr PR |
18 | | - [--branch BRANCH] [--debug] [--continue] |
19 | | - [--abort-before-push] |
| 15 | +For example, to backport PR #9876: |
20 | 16 |
|
21 | | -optional arguments: |
22 | | - -h, --help show this help message and exit |
23 | | - --repo {chainer,cupy} |
24 | | - chainer or cupy |
25 | | - --token TOKEN GitHub access token. |
26 | | - --pr PR The original PR number to be backported. |
27 | | - --branch BRANCH Target branch to make a backport |
28 | | - --debug |
29 | | - --continue Continues the process suspended by conflict situation. |
30 | | - Run from the working tree directory. |
31 | | - --abort-before-push Abort the procedure before making an push. Useful if |
32 | | - you want to make some modification to the backport |
33 | | - branch. Use --continue to make an actual push after |
34 | | - making modification. |
| 17 | +```shell |
| 18 | +$ export BACKPORT_GITHUB_TOKEN=ghp_XXXXXXXXXXXXXXXXXXXXX |
| 19 | +$ python backport.py --repo cupy --pr 9876 |
35 | 20 | ``` |
36 | 21 |
|
37 | | -## Example |
| 22 | +If there are conflicts during backport, the tool will stop and ask you to resolve the conflict manually. |
| 23 | +Follow the instructions shown. |
38 | 24 |
|
39 | | -```shell |
40 | | -$ python backport.py --repo chainer --token abcdefghijklmn --pr 1234 |
41 | | -``` |
| 25 | +Run `python backport.py --help` for additional options. |
42 | 26 |
|
43 | 27 | ## How it works |
44 | 28 |
|
45 | 29 | Basically it follows this procedure: |
46 | 30 |
|
47 | | -1. Clone the target branch (e.g. `v5`) of the target repository (e.g. `chainer/chainer`) to a temporary directory. |
| 31 | +1. Clone the target branch (e.g. `v13`) of the target repository (e.g. `cupy/cupy`) to a temporary directory. |
48 | 32 | 2. Create a local temporary branch and cherry-pick the merge commit of the original PR. |
49 | 33 | 3. Push it to the user repository. |
50 | 34 | 4. Make a backport PR. |
51 | | - |
52 | | - |
53 | | -## In the case of conflict |
54 | | - |
55 | | -If conflict has occurred during backporting, you have to resolve conflict yourself, |
56 | | -and rerun the command with additional `--continue` option. |
57 | | - |
58 | | -```shell |
59 | | -$ python backport.py --repo chainer --token abcdefghijklmn --pr 1234 |
60 | | -... |
61 | | -Cherry-pick failed. |
62 | | -Working tree is saved at: /tmp/bp-FktJXG5R |
63 | | -Go to the working tree, resolve the conflict and type `git cherry-pick --continue`, |
64 | | -then run this script with --continue option. |
65 | | - |
66 | | -$ cd /tmp/bp-FktJXG5R |
67 | | - |
68 | | -$ <resolve conflict> |
69 | | - |
70 | | -$ git cherry-pick --continue |
71 | | - |
72 | | -$ python backport.py --repo chainer --token abcdefghijklmn --pr 1234 --continue |
73 | | -``` |
0 commit comments