Skip to content

Commit 5620196

Browse files
authored
CI: Add backporting bot (#4795)
Adds a bot that automatically opens MRs into the `stable2407` branch when the `A4-needs-backport` label is applied to a merged MR. TODO: - [x] ~~Settle on label vs error message trade-off~~ (resolved) docs: # Backporting This document explains how to backport a merged PR from `master` to one of the `stable*` branches. Backports should only be used to fix bugs or security issues - never to introduce new features. ## Steps 1. Fix a bug through a PR that targets `master`. 2. Add label `A4-needs-backport` to the PR. 4. Merge the PR into `master`. 5. Wait for the bot to open the backport PR. 6. Ensure the change is audited or does not need audit. 7. Merge the backport PR. The label can also be added after the PR is merged. ## Example For example here where the dev triggered the process by adding the label after merging: ![backport-ex2](https://github.com/user-attachments/assets/c7b686db-a0fe-41f1-9d6f-959a5a7097b1) --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]>
1 parent 1c4141a commit 5620196

File tree

5 files changed

+91
-6
lines changed

5 files changed

+91
-6
lines changed

.github/workflows/check-semver.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
as to not impact downstream teams that rely on the stability of it. Some things to consider:
4646
- Backports are only for 'patch' or 'minor' changes. No 'major' or other breaking change.
4747
- Should be a legit *fix* for some bug, not adding tons of new features.
48-
- Must either be already audited or trivial (not sure audit).
48+
- Must either be already audited or not need an audit.
4949
5050
<details><summary><i>Emergency Bypass</i></summary>
5151
<p>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Backport into stable
2+
3+
on:
4+
# This trigger can be problematic, see: https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
5+
# In our case it is fine since we only run it on merged Pull Requests and do not execute any of the repo code itself.
6+
pull_request_target:
7+
types: [ closed, labeled ]
8+
9+
permissions:
10+
contents: write # so it can comment
11+
pull-requests: write # so it can create pull requests
12+
13+
jobs:
14+
backport:
15+
name: Backport pull request
16+
runs-on: ubuntu-latest
17+
18+
# The 'github.event.pull_request.merged' ensures that it got into master:
19+
if: >
20+
( !startsWith(github.event.pull_request.base.ref, 'stable') ) &&
21+
(
22+
github.event_name == 'pull_request_target' &&
23+
github.event.pull_request.merged &&
24+
github.event.pull_request.base.ref == 'master' &&
25+
contains(github.event.pull_request.labels.*.name, 'A4-needs-backport')
26+
)
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Create backport pull requests
31+
uses: korthout/backport-action@v3
32+
id: backport
33+
with:
34+
target_branches: stable2407
35+
merge_commits: skip
36+
github_token: ${{ secrets.GITHUB_TOKEN }}
37+
pull_description: |
38+
Backport #${pull_number} into `${target_branch}` (cc @${pull_author}).
39+
40+
<!--
41+
# To be used by other automation, do not modify:
42+
original-pr-number: #${pull_number}
43+
-->
44+
pull_title: |
45+
[${target_branch}] Backport #${pull_number}
46+
47+
- name: Label Backports
48+
if: ${{ steps.backport.outputs.created_pull_numbers != '' }}
49+
uses: actions/github-script@v7
50+
with:
51+
script: |
52+
const pullNumbers = '${{ steps.backport.outputs.created_pull_numbers }}'.split(' ');
53+
54+
for (const pullNumber of pullNumbers) {
55+
await github.rest.issues.addLabels({
56+
issue_number: parseInt(pullNumber),
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
labels: ['A3-backport']
60+
});
61+
console.log(`Added A3-backport label to PR #${pullNumber}`);
62+
}

docs/BACKPORT.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Backporting
2+
3+
This document explains how to backport a merged PR from `master` to one of the `stable*` branches.
4+
Backports should only be used to fix bugs or security issues - never to introduce new features.
5+
6+
## Steps
7+
8+
1. Fix a bug through a PR that targets `master`.
9+
2. Add label `A4-needs-backport` to the PR.
10+
3. Merge the PR into `master`.
11+
4. Wait for the bot to open the backport PR.
12+
5. Ensure the change is audited or does not need audit.
13+
6. Merge the backport PR.
14+
15+
The label can also be added after the PR is merged.
16+
17+
## Example
18+
19+
For example here where the dev triggered the process by adding the label after merging:
20+
21+
![backport](./images/backport-ex2.png)

docs/RELEASE.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ The Westend testnet will be updated to a new runtime every two weeks with the la
5555

5656
**From `master` to `stable`**
5757

58-
Backports in this direction can be anything that is audited and either a `minor` or a `patch` bump. [Security
59-
fixes](#bug-and-security-fix) should be prioritized over additions or improvements. Crates that are declared as internal
60-
API can also have `major` version bumps through backports.
58+
Backports in this direction can be anything that is audited and either a `minor` or a `patch` bump.
59+
See [BACKPORT.md](./BACKPORT.md) for more explanation. [Security fixes](#bug-and-security-fix)
60+
should be prioritized over additions or improvements. Crates that are declared as internal API can
61+
also have `major` version bumps through backports.
6162

6263
**From `stable` to `master`**
6364

@@ -164,5 +165,6 @@ Describes how developers should merge bug and security fixes.
164165
2. The Pull Request is marked as priority fix.
165166
3. Audit happens with priority.
166167
4. It is merged into `master`.
167-
5. It is automatically back-ported to `stable`.
168-
6. The fix will be released in the next *Stable* release. In urgent cases, a release can happen earlier.
168+
5. Dev adds the `A4-needs-backport` label.
169+
6. It is automatically back-ported to `stable`.
170+
7. The fix will be released in the next *Stable* release. In urgent cases, a release can happen earlier.

docs/images/backport-ex2.png

98.7 KB
Loading

0 commit comments

Comments
 (0)