forked from netty/netty
-
Notifications
You must be signed in to change notification settings - Fork 5
130 lines (119 loc) · 4.91 KB
/
autoport-41.yml
File metadata and controls
130 lines (119 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Auto-port to 4.1
on:
pull_request_target:
types:
- closed
- labeled
branches:
- '4.2'
- '5.0'
jobs:
autoport:
name: "Auto-porting to 4.1"
concurrency:
group: port-41-${{ github.event.pull_request.number }}
cancel-in-progress: true
if: github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'needs-cherry-pick-4.1')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY_PEM }}
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
fetch-depth: '0' # Cherry-pick needs full history
- name: Setup git configuration
run: |
git config --global user.email "netty-project-bot@users.noreply.github.com"
git config --global user.name "Netty Project Bot"
- name: Create auto-port PR branch and cherry-pick
id: cherry-pick
run: |
MERGE_COMMIT="${{ github.event.pull_request.merge_commit_sha }}"
echo "Auto-porting commit: $MERGE_COMMIT"
PORT_BRANCH="auto-port-pr-${{ github.event.pull_request.number }}-to-4.1"
if [[ $(git branch --show-current) != '4.1' ]]; then
git fetch origin 4.1:4.1
fi
git checkout -b "$PORT_BRANCH" 4.1
if git cherry-pick -x "$MERGE_COMMIT"; then
echo "Cherry-pick successful"
else
echo "Cherry-pick failed - conflicts detected"
git cherry-pick --abort
exit 1
fi
echo "branch=$PORT_BRANCH" >> "$GITHUB_OUTPUT"
- name: Push auto-port branch
id: push
if: steps.cherry-pick.outcome == 'success'
run: |
if ! git push origin "${{ steps.cherry-pick.outputs.branch }}"; then
echo "Auto-port branch push failed"
exit 1
fi
- name: Create pull request
id: create-pr
if: steps.cherry-pick.outcome == 'success'
uses: actions/github-script@v8
with:
github-token: '${{ secrets.PAT_TOKEN_READ_WRITE_PR }}'
script: |
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Auto-port 4.1: ${context.payload.pull_request.title}`,
head: '${{ steps.cherry-pick.outputs.branch }}',
base: '4.1',
body: `Auto-port of #${context.payload.pull_request.number} to 4.1\n` +
`Cherry-picked commit: ${context.payload.pull_request.merge_commit_sha}\n\n---\n` +
`${context.payload.pull_request.body || ''}`
});
console.log(`Created auto-port PR: ${pr.html_url}`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `Auto-port PR for 4.1: #${pr.number}`
});
# Important: This script MUST run with the default GITHUB_TOKEN to avoid triggering other actions.
- name: Remove triggering label
if: steps.create-pr.outcome == 'success'
uses: actions/github-script@v8
with:
script: |
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
name: 'needs-cherry-pick-4.1'
});
- name: Report cherry-pick conflicts
if: failure() && steps.cherry-pick.outcome == 'failure'
uses: actions/github-script@v8
with:
github-token: '${{ secrets.PAT_TOKEN_READ_WRITE_PR }}'
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `Could not create auto-port PR.\nGot conflicts when cherry-picking onto 4.1.`
});
- name: Report auto-port branch push failure
if: failure() && steps.push.outcome == 'failure'
uses: actions/github-script@v8
with:
github-token: '${{ secrets.PAT_TOKEN_READ_WRITE_PR }}'
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `Could not create auto-port PR.\n`+
`I could cherry-pick onto 4.1 just fine, but pushing the new branch failed.`
});
- name: Remove branch on PR create failure
if: failure() && steps.cherry-pick.outputs.branch
run: |
git push -d origin "${{ steps.cherry-pick.outputs.branch }}"