11cb0ef41Sopenharmony_ci# How to backport a pull request to a release line
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci## Staging branches
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciEach release line has a staging branch that the releaser will use as a scratch
61cb0ef41Sopenharmony_cipad while preparing a release. The branch name is formatted as follows:
71cb0ef41Sopenharmony_ci`vN.x-staging` where `N` is the major release number.
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciFor the active staging branches see the [Release Schedule][].
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci## What needs to be backported?
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciIf a cherry-pick from `main` does not land cleanly on a staging branch, the
141cb0ef41Sopenharmony_cireleaser will mark the pull request with a particular label for that release
151cb0ef41Sopenharmony_ciline (e.g. `backport-requested-vN.x`), specifying to our tooling that this
161cb0ef41Sopenharmony_cipull request should not be included. The releaser will then add a comment
171cb0ef41Sopenharmony_cirequesting that a backport pull request be made.
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci## What can be backported?
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciThe "Current" release line is much more lenient than the LTS release lines in
221cb0ef41Sopenharmony_ciwhat can be landed. Our LTS release lines (see the [Release Plan][])
231cb0ef41Sopenharmony_cirequire that commits mature in the Current release for at least 2 weeks before
241cb0ef41Sopenharmony_cithey can be landed in an LTS staging branch. Only after "maturation" will those
251cb0ef41Sopenharmony_cicommits be cherry-picked or backported.
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci## How to label backport issues and PRs?
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciFor the following labels, the `N` in `vN.x` refers to the major release number.
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci| Label                   | Description                                                                                       |
321cb0ef41Sopenharmony_ci| ----------------------- | ------------------------------------------------------------------------------------------------- |
331cb0ef41Sopenharmony_ci| backport-blocked-vN.x   | PRs that should land on the vN.x-staging branch but are blocked by another PR's pending backport. |
341cb0ef41Sopenharmony_ci| backport-open-vN.x      | Indicate that the PR has an open backport.                                                        |
351cb0ef41Sopenharmony_ci| backport-requested-vN.x | PRs awaiting manual backport to the vN.x-staging branch.                                          |
361cb0ef41Sopenharmony_ci| backported-to-vN.x      | PRs backported to the vN.x-staging branch.                                                        |
371cb0ef41Sopenharmony_ci| baking-for-lts          | PRs that need to wait before landing in a LTS release.                                            |
381cb0ef41Sopenharmony_ci| lts-watch-vN.x          | PRs that may need to be released in vN.x.                                                         |
391cb0ef41Sopenharmony_ci| vN.x                    | Issues that can be reproduced on vN.x or PRs targeting the vN.x-staging branch.                   |
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci## How to submit a backport pull request
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciFor the following steps, let's assume that a backport is needed for the v10.x
441cb0ef41Sopenharmony_cirelease line. All commands will use the `v10.x-staging` branch as the target
451cb0ef41Sopenharmony_cibranch. In order to submit a backport pull request to another branch, simply
461cb0ef41Sopenharmony_cireplace that with the staging branch for the targeted release line.
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci1. Checkout the staging branch for the targeted release line.
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci2. Make sure that the local staging branch is up to date with the remote.
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci3. Create a new branch off of the staging branch, as shown below.
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci   ```bash
551cb0ef41Sopenharmony_ci   # Assuming your fork of Node.js is checked out in $NODE_DIR,
561cb0ef41Sopenharmony_ci   # the origin remote points to your fork, and the upstream remote points
571cb0ef41Sopenharmony_ci   # to git@github.com:nodejs/node.git
581cb0ef41Sopenharmony_ci   cd $NODE_DIR
591cb0ef41Sopenharmony_ci   # If v10.x-staging is checked out `pull` should be used instead of `fetch`
601cb0ef41Sopenharmony_ci   git fetch upstream v10.x-staging:v10.x-staging -f
611cb0ef41Sopenharmony_ci   # Assume we want to backport PR #10157
621cb0ef41Sopenharmony_ci   git checkout -b backport-10157-to-v10.x v10.x-staging
631cb0ef41Sopenharmony_ci   # Ensure there are no test artifacts from previous builds
641cb0ef41Sopenharmony_ci   # Note that this command deletes all files and directories
651cb0ef41Sopenharmony_ci   # not under revision control below the ./test directory.
661cb0ef41Sopenharmony_ci   # It is optional and should be used with caution.
671cb0ef41Sopenharmony_ci   git clean -xfd ./test/
681cb0ef41Sopenharmony_ci   ```
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci4. After creating the branch, apply the changes to the branch. The cherry-pick
711cb0ef41Sopenharmony_ci   will likely fail due to conflicts. In that case, you will see something
721cb0ef41Sopenharmony_ci   like this:
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci   ```console
751cb0ef41Sopenharmony_ci   # Say the $SHA is 773cdc31ef
761cb0ef41Sopenharmony_ci   $ git cherry-pick $SHA # Use your commit hash
771cb0ef41Sopenharmony_ci   error: could not apply 773cdc3... <commit title>
781cb0ef41Sopenharmony_ci   hint: after resolving the conflicts, mark the corrected paths
791cb0ef41Sopenharmony_ci   hint: with 'git add <paths>' or 'git rm <paths>'
801cb0ef41Sopenharmony_ci   hint: and commit the result with 'git commit'
811cb0ef41Sopenharmony_ci   ```
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci5. Make the required changes to remove the conflicts, add the files to the index
841cb0ef41Sopenharmony_ci   using `git add`, and then commit the changes. That can be done with
851cb0ef41Sopenharmony_ci   `git cherry-pick --continue`.
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ci6. Leave the commit message as is. If you think it should be modified, comment
881cb0ef41Sopenharmony_ci   in the pull request. The `Backport-PR-URL` metadata does need to be added to
891cb0ef41Sopenharmony_ci   the commit, but this will be done later.
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci7. Make sure `make -j4 test` passes.
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ci8. Push the changes to your fork.
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_ci9. Open a pull request:
961cb0ef41Sopenharmony_ci   1. Be sure to target the `v10.x-staging` branch in the pull request.
971cb0ef41Sopenharmony_ci   2. Include the backport target in the pull request title in the following
981cb0ef41Sopenharmony_ci      format: `[v10.x backport] <commit title>`.
991cb0ef41Sopenharmony_ci      Example: `[v10.x backport] process: improve performance of nextTick`
1001cb0ef41Sopenharmony_ci   3. Check the checkbox labeled "Allow edits and access to secrets by
1011cb0ef41Sopenharmony_ci      maintainers".
1021cb0ef41Sopenharmony_ci   4. In the description add a reference to the original pull request.
1031cb0ef41Sopenharmony_ci   5. Amend the commit message and include a `Backport-PR-URL:` metadata and
1041cb0ef41Sopenharmony_ci      re-push the change to your fork.
1051cb0ef41Sopenharmony_ci   6. Run a [`node-test-pull-request`][] CI job (with `REBASE_ONTO` set to the
1061cb0ef41Sopenharmony_ci      default `<pr base branch>`)
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ci10. Replace the `backport-requested-v10.x` label on the original pull request
1091cb0ef41Sopenharmony_ci    with `backport-open-v10.x`.
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_ci11. If during the review process conflicts arise, use the following to rebase:
1121cb0ef41Sopenharmony_ci    `git pull --rebase upstream v10.x-staging`
1131cb0ef41Sopenharmony_ci
1141cb0ef41Sopenharmony_ciAfter the pull request lands, replace the `backport-open-v10.x` label on the
1151cb0ef41Sopenharmony_cioriginal pull request with `backported-to-v10.x`.
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci[Release Plan]: https://github.com/nodejs/Release#release-plan
1181cb0ef41Sopenharmony_ci[Release Schedule]: https://github.com/nodejs/Release#release-schedule
1191cb0ef41Sopenharmony_ci[`node-test-pull-request`]: https://ci.nodejs.org/job/node-test-pull-request/build
120