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