From a25da3184ae852d2dcf7ea09dfee492027ebca68 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:23:40 +0800 Subject: [PATCH 01/17] update --- .github/workflows/backport.yml | 115 +++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 .github/workflows/backport.yml diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml new file mode 100644 index 0000000000..9992a09267 --- /dev/null +++ b/.github/workflows/backport.yml @@ -0,0 +1,115 @@ +name: Backport PR + +on: + pull_request_target: + types: [labeled] + +jobs: + backport: + if: | + !github.event.repository.fork && + startsWith(github.event.label.name, 'backport/3.') && + github.event.action == 'labeled' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Extract version from label + id: extract + run: | + LABEL="${{ github.event.label.name }}" + if [[ "$LABEL" =~ ^backport/3\.([0-9]+)$ ]]; then + VERSION="3.${BASH_REMATCH[1]}" + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "branch=release/$VERSION" >> $GITHUB_OUTPUT + else + echo "Invalid label format: $LABEL" + exit 1 + fi + + - name: Get PR info + id: pr_info + uses: actions/github-script@v8 + with: + script: | + const prNumber = context.payload.pull_request.number; + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber + }); + core.setOutput('title', pr.data.title); + core.setOutput('head_sha', pr.data.head.sha); + core.setOutput('head_repo', pr.data.head.repo.full_name); + + - name: Checkout target release branch + uses: actions/checkout@v5 + with: + ref: ${{ steps.extract.outputs.branch }} + fetch-depth: 0 + + - name: Fetch and merge PR changes (simulate squash) + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + # Fetch the PR's head commit from its source repo + git fetch https://github.com/${{ steps.pr_info.outputs.head_repo }} ${{ steps.pr_info.outputs.head_sha }} + + # Create a temporary merge to get the diff as if squashed + git merge --squash ${{ steps.pr_info.outputs.head_sha }} --no-edit + + # If there are no changes, skip backport + if ! git diff --cached --quiet; then + git commit -m "[Backport/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }} + + Backport of PR #${{ github.event.pull_request.number }}." + else + echo "No changes to backport." + exit 0 + fi + +- name: Push to backport branch + id: push + run: | + BRANCH="backport/pr-${{ github.event.pull_request.number }}-to-${{ steps.extract.outputs.version }}" + git push origin HEAD:$BRANCH + echo "backport_branch=$BRANCH" >> $GITHUB_OUTPUT + +- name: Create Backport Pull Request + if: success() && env.CHANGES_EXIST != 'false' # We'll handle no-change case below + uses: actions/github-script@v8 + with: + script: | + const { owner, repo } = context.repo; + const prNumber = ${{ github.event.pull_request.number }}; + const version = "${{ steps.extract.outputs.version }}"; + const title = "[Backport/${version}] ${{ steps.pr_info.outputs.title }}"; + const body = `Automated backport of #${prNumber} to \`${{ steps.extract.outputs.branch }}\`. + +Original PR: #${prNumber} +Commit: ${{ steps.pr_info.outputs.head_sha }}`; + + try { + await github.rest.pulls.create({ + owner, + repo, + title, + head: "${{ steps.push.outputs.backport_branch }}", + base: "${{ steps.extract.outputs.branch }}", + body +}); +} catch (error) { + if (error.status === 422 && error.message.includes('A pull request already exists')) { + console.log('Backport PR already exists, skipping.'); +} else { + throw error; +} +} + + - name: Handle no changes case + if: failure() + run: | + echo "No changes detected or error occurred. Skipping backport PR creation." \ No newline at end of file From 573fb6deacf1887d4b1c8a1f717090a1a7bacc60 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:26:24 +0800 Subject: [PATCH 02/17] update --- .github/workflows/backport.yml | 65 ++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 9992a09267..0d71457a4e 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -22,10 +22,10 @@ jobs: LABEL="${{ github.event.label.name }}" if [[ "$LABEL" =~ ^backport/3\.([0-9]+)$ ]]; then VERSION="3.${BASH_REMATCH[1]}" - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "branch=release/$VERSION" >> $GITHUB_OUTPUT + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "branch=release/$VERSION" >> "$GITHUB_OUTPUT" else - echo "Invalid label format: $LABEL" + echo "Error: Invalid label format '$LABEL'. Expected 'backport/3.X' where X is an integer." exit 1 fi @@ -34,11 +34,10 @@ jobs: uses: actions/github-script@v8 with: script: | - const prNumber = context.payload.pull_request.number; const pr = await github.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, - pull_number: prNumber + pull_number: ${{ github.event.pull_request.number }} }); core.setOutput('title', pr.data.title); core.setOutput('head_sha', pr.data.head.sha); @@ -50,46 +49,53 @@ jobs: ref: ${{ steps.extract.outputs.branch }} fetch-depth: 0 - - name: Fetch and merge PR changes (simulate squash) + - name: Fetch PR changes and simulate squash merge + id: apply_changes run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - # Fetch the PR's head commit from its source repo git fetch https://github.com/${{ steps.pr_info.outputs.head_repo }} ${{ steps.pr_info.outputs.head_sha }} - # Create a temporary merge to get the diff as if squashed - git merge --squash ${{ steps.pr_info.outputs.head_sha }} --no-edit + # Apply changes as a squash (staged but not committed yet) + if ! git merge --squash ${{ steps.pr_info.outputs.head_sha }} --no-edit; then + echo "Merge failed (likely due to conflicts). Skipping backport." + echo "has_changes=false" >> "$GITHUB_OUTPUT" + exit 0 + fi - # If there are no changes, skip backport - if ! git diff --cached --quiet; then + # Check if there are any staged changes + if git diff --cached --quiet; then + echo "No changes to backport." + echo "has_changes=false" >> "$GITHUB_OUTPUT" + exit 0 + else + echo "has_changes=true" >> "$GITHUB_OUTPUT" git commit -m "[Backport/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }} Backport of PR #${{ github.event.pull_request.number }}." - else - echo "No changes to backport." - exit 0 fi -- name: Push to backport branch +- name: Push backport branch + if: steps.apply_changes.outputs.has_changes == 'true' id: push run: | - BRANCH="backport/pr-${{ github.event.pull_request.number }}-to-${{ steps.extract.outputs.version }}" - git push origin HEAD:$BRANCH - echo "backport_branch=$BRANCH" >> $GITHUB_OUTPUT + BACKPORT_BRANCH="backport/pr-${{ github.event.pull_request.number }}-to-${{ steps.extract.outputs.version }}" + git push origin HEAD:"$BACKPORT_BRANCH" + echo "backport_branch=$BACKPORT_BRANCH" >> "$GITHUB_OUTPUT" - name: Create Backport Pull Request - if: success() && env.CHANGES_EXIST != 'false' # We'll handle no-change case below + if: steps.apply_changes.outputs.has_changes == 'true' uses: actions/github-script@v8 with: script: | const { owner, repo } = context.repo; - const prNumber = ${{ github.event.pull_request.number }}; + const originalPrNumber = ${{ github.event.pull_request.number }}; const version = "${{ steps.extract.outputs.version }}"; - const title = "[Backport/${version}] ${{ steps.pr_info.outputs.title }}"; - const body = `Automated backport of #${prNumber} to \`${{ steps.extract.outputs.branch }}\`. + const title = `[Backport/${version}] ${{ steps.pr_info.outputs.title }}`; + const body = `Automated backport of #${originalPrNumber} to \`${{ steps.extract.outputs.branch }}\`. -Original PR: #${prNumber} +Original PR: #${originalPrNumber} Commit: ${{ steps.pr_info.outputs.head_sha }}`; try { @@ -101,15 +107,12 @@ Commit: ${{ steps.pr_info.outputs.head_sha }}`; base: "${{ steps.extract.outputs.branch }}", body }); + console.log("Backport PR created successfully."); } catch (error) { - if (error.status === 422 && error.message.includes('A pull request already exists')) { - console.log('Backport PR already exists, skipping.'); + const msg = error.message || ''; + if (error.status === 422 && msg.includes('A pull request already exists')) { + console.log("Backport PR already exists. Skipping."); } else { throw error; } -} - - - name: Handle no changes case - if: failure() - run: | - echo "No changes detected or error occurred. Skipping backport PR creation." \ No newline at end of file +} \ No newline at end of file From b47118de596e04419914b7796a11b1ac55655fc6 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:29:04 +0800 Subject: [PATCH 03/17] update --- .github/workflows/backport.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 0d71457a4e..1943f0f918 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -54,17 +54,12 @@ jobs: run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - - git fetch https://github.com/${{ steps.pr_info.outputs.head_repo }} ${{ steps.pr_info.outputs.head_sha }} - - # Apply changes as a squash (staged but not committed yet) - if ! git merge --squash ${{ steps.pr_info.outputs.head_sha }} --no-edit; then + git fetch "https://github.com/${{ steps.pr_info.outputs.head_repo }}" "${{ steps.pr_info.outputs.head_sha }}" + if ! git merge --squash "${{ steps.pr_info.outputs.head_sha }}" --no-edit; then echo "Merge failed (likely due to conflicts). Skipping backport." echo "has_changes=false" >> "$GITHUB_OUTPUT" exit 0 fi - - # Check if there are any staged changes if git diff --cached --quiet; then echo "No changes to backport." echo "has_changes=false" >> "$GITHUB_OUTPUT" From 046e3fe0f835e32bf47277c19bf5313e7064af23 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:29:32 +0800 Subject: [PATCH 04/17] update --- .github/workflows/backport.yml | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 1943f0f918..7ce60840b1 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -89,25 +89,25 @@ jobs: const version = "${{ steps.extract.outputs.version }}"; const title = `[Backport/${version}] ${{ steps.pr_info.outputs.title }}`; const body = `Automated backport of #${originalPrNumber} to \`${{ steps.extract.outputs.branch }}\`. - -Original PR: #${originalPrNumber} -Commit: ${{ steps.pr_info.outputs.head_sha }}`; - - try { - await github.rest.pulls.create({ - owner, - repo, - title, - head: "${{ steps.push.outputs.backport_branch }}", - base: "${{ steps.extract.outputs.branch }}", - body -}); - console.log("Backport PR created successfully."); -} catch (error) { - const msg = error.message || ''; - if (error.status === 422 && msg.includes('A pull request already exists')) { - console.log("Backport PR already exists. Skipping."); -} else { - throw error; -} -} \ No newline at end of file + + Original PR: #${originalPrNumber} + Commit: ${{ steps.pr_info.outputs.head_sha }}`; + + try { + await github.rest.pulls.create({ + owner, + repo, + title, + head: "${{ steps.push.outputs.backport_branch }}", + base: "${{ steps.extract.outputs.branch }}", + body + }); + console.log("Backport PR created successfully."); + } catch (error) { + const msg = error.message || ''; + if (error.status === 422 && msg.includes('A pull request already exists')) { + console.log("Backport PR already exists. Skipping."); + } else { + throw error; + } + } \ No newline at end of file From 8083f841e8d4264f1fb47bcc636e0870badf516d Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:30:31 +0800 Subject: [PATCH 05/17] update --- .github/workflows/backport.yml | 82 +++++++++++++++++----------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 7ce60840b1..4e76b178ef 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -68,46 +68,46 @@ jobs: echo "has_changes=true" >> "$GITHUB_OUTPUT" git commit -m "[Backport/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }} - Backport of PR #${{ github.event.pull_request.number }}." - fi + Backport of PR #${{ github.event.pull_request.number }}." + fi -- name: Push backport branch - if: steps.apply_changes.outputs.has_changes == 'true' - id: push - run: | - BACKPORT_BRANCH="backport/pr-${{ github.event.pull_request.number }}-to-${{ steps.extract.outputs.version }}" - git push origin HEAD:"$BACKPORT_BRANCH" - echo "backport_branch=$BACKPORT_BRANCH" >> "$GITHUB_OUTPUT" + - name: Push backport branch + if: steps.apply_changes.outputs.has_changes == 'true' + id: push + run: | + BACKPORT_BRANCH="backport/pr-${{ github.event.pull_request.number }}-to-${{ steps.extract.outputs.version }}" + git push origin HEAD:"$BACKPORT_BRANCH" + echo "backport_branch=$BACKPORT_BRANCH" >> "$GITHUB_OUTPUT" -- name: Create Backport Pull Request - if: steps.apply_changes.outputs.has_changes == 'true' - uses: actions/github-script@v8 - with: - script: | - const { owner, repo } = context.repo; - const originalPrNumber = ${{ github.event.pull_request.number }}; - const version = "${{ steps.extract.outputs.version }}"; - const title = `[Backport/${version}] ${{ steps.pr_info.outputs.title }}`; - const body = `Automated backport of #${originalPrNumber} to \`${{ steps.extract.outputs.branch }}\`. - - Original PR: #${originalPrNumber} - Commit: ${{ steps.pr_info.outputs.head_sha }}`; - - try { - await github.rest.pulls.create({ - owner, - repo, - title, - head: "${{ steps.push.outputs.backport_branch }}", - base: "${{ steps.extract.outputs.branch }}", - body - }); - console.log("Backport PR created successfully."); - } catch (error) { - const msg = error.message || ''; - if (error.status === 422 && msg.includes('A pull request already exists')) { - console.log("Backport PR already exists. Skipping."); - } else { - throw error; - } - } \ No newline at end of file + - name: Create Backport Pull Request + if: steps.apply_changes.outputs.has_changes == 'true' + uses: actions/github-script@v8 + with: + script: | + const { owner, repo } = context.repo; + const originalPrNumber = ${{ github.event.pull_request.number }}; + const version = "${{ steps.extract.outputs.version }}"; + const title = `[Backport/${version}] ${{ steps.pr_info.outputs.title }}`; + const body = `Automated backport of #${originalPrNumber} to \`${{ steps.extract.outputs.branch }}\`. + + Original PR: #${originalPrNumber} + Commit: ${{ steps.pr_info.outputs.head_sha }}`; + + try { + await github.rest.pulls.create({ + owner, + repo, + title, + head: "${{ steps.push.outputs.backport_branch }}", + base: "${{ steps.extract.outputs.branch }}", + body + }); + console.log("Backport PR created successfully."); + } catch (error) { + const msg = error.message || ''; + if (error.status === 422 && msg.includes('A pull request already exists')) { + console.log("Backport PR already exists. Skipping."); + } else { + throw error; + } + } \ No newline at end of file From 407b29f725dae954bd96309da70d3eccc4941fb0 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:32:58 +0800 Subject: [PATCH 06/17] update --- .github/workflows/backport.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 4e76b178ef..9d86db9d26 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -7,7 +7,6 @@ on: jobs: backport: if: | - !github.event.repository.fork && startsWith(github.event.label.name, 'backport/3.') && github.event.action == 'labeled' runs-on: ubuntu-latest From e959428bd41f976a361a806ccf549ce520bce3f7 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:36:30 +0800 Subject: [PATCH 07/17] update --- .github/workflows/backport.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 9d86db9d26..2a6a281656 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -1,7 +1,7 @@ name: Backport PR on: - pull_request_target: + pull_request: types: [labeled] jobs: From 4e33a2c547a9409e7442a672962de3d856c03cd5 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:40:36 +0800 Subject: [PATCH 08/17] update --- .github/workflows/debug.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/debug.yml diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml new file mode 100644 index 0000000000..abe4e22676 --- /dev/null +++ b/.github/workflows/debug.yml @@ -0,0 +1,12 @@ +name: Debug Label Event +on: + pull_request: + types: [labeled] +jobs: + debug: + runs-on: ubuntu-latest + steps: + - run: | + echo "Label added: ${{ github.event.label.name }}" + echo "Action: ${{ github.event.action }}" + echo "PR number: ${{ github.event.pull_request.number }}" \ No newline at end of file From 3347a712c91046269a385b33fd19ca7afab0fa75 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:42:43 +0800 Subject: [PATCH 09/17] update --- .github/workflows/backport.yml | 2 ++ .github/workflows/debug.yml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 2a6a281656..d6fdc662f5 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -3,6 +3,8 @@ name: Backport PR on: pull_request: types: [labeled] + pull_request_target : + types: [ labeled ] jobs: backport: diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index abe4e22676..991d2ba099 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -2,6 +2,9 @@ name: Debug Label Event on: pull_request: types: [labeled] + pull_request_target : + types: [ labeled ] + jobs: debug: runs-on: ubuntu-latest From 6f9745808538e9d00894f178ce9078d6482cc8c2 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:47:46 +0800 Subject: [PATCH 10/17] update --- .github/workflows/backport.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index d6fdc662f5..8351b3305d 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -76,7 +76,7 @@ jobs: if: steps.apply_changes.outputs.has_changes == 'true' id: push run: | - BACKPORT_BRANCH="backport/pr-${{ github.event.pull_request.number }}-to-${{ steps.extract.outputs.version }}" + BACKPORT_BRANCH="backports/pr-${{ github.event.pull_request.number }}-to-${{ steps.extract.outputs.version }}" git push origin HEAD:"$BACKPORT_BRANCH" echo "backport_branch=$BACKPORT_BRANCH" >> "$GITHUB_OUTPUT" From a70f14b8c026967725280fd7653316b7785c31f0 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:56:21 +0800 Subject: [PATCH 11/17] update --- .github/workflows/backport.yml | 33 ++++++--------------------------- .github/workflows/debug.yml | 15 --------------- 2 files changed, 6 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/debug.yml diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 8351b3305d..8adea8720f 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -2,8 +2,8 @@ name: Backport PR on: pull_request: - types: [labeled] - pull_request_target : + types: [ labeled ] + pull_request_target: types: [ labeled ] jobs: @@ -58,22 +58,17 @@ jobs: git fetch "https://github.com/${{ steps.pr_info.outputs.head_repo }}" "${{ steps.pr_info.outputs.head_sha }}" if ! git merge --squash "${{ steps.pr_info.outputs.head_sha }}" --no-edit; then echo "Merge failed (likely due to conflicts). Skipping backport." - echo "has_changes=false" >> "$GITHUB_OUTPUT" exit 0 fi if git diff --cached --quiet; then echo "No changes to backport." - echo "has_changes=false" >> "$GITHUB_OUTPUT" exit 0 else - echo "has_changes=true" >> "$GITHUB_OUTPUT" - git commit -m "[Backport/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }} - + git commit -m "[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }} Backport of PR #${{ github.event.pull_request.number }}." fi - name: Push backport branch - if: steps.apply_changes.outputs.has_changes == 'true' id: push run: | BACKPORT_BRANCH="backports/pr-${{ github.event.pull_request.number }}-to-${{ steps.extract.outputs.version }}" @@ -81,21 +76,14 @@ jobs: echo "backport_branch=$BACKPORT_BRANCH" >> "$GITHUB_OUTPUT" - name: Create Backport Pull Request - if: steps.apply_changes.outputs.has_changes == 'true' uses: actions/github-script@v8 with: script: | const { owner, repo } = context.repo; - const originalPrNumber = ${{ github.event.pull_request.number }}; const version = "${{ steps.extract.outputs.version }}"; - const title = `[Backport/${version}] ${{ steps.pr_info.outputs.title }}`; - const body = `Automated backport of #${originalPrNumber} to \`${{ steps.extract.outputs.branch }}\`. - - Original PR: #${originalPrNumber} - Commit: ${{ steps.pr_info.outputs.head_sha }}`; - - try { - await github.rest.pulls.create({ + const title = `[release/${version}] ${{ steps.pr_info.outputs.title }}`; + const body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\`. + await github.rest.pulls.create({ owner, repo, title, @@ -103,12 +91,3 @@ jobs: base: "${{ steps.extract.outputs.branch }}", body }); - console.log("Backport PR created successfully."); - } catch (error) { - const msg = error.message || ''; - if (error.status === 422 && msg.includes('A pull request already exists')) { - console.log("Backport PR already exists. Skipping."); - } else { - throw error; - } - } \ No newline at end of file diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml deleted file mode 100644 index 991d2ba099..0000000000 --- a/.github/workflows/debug.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Debug Label Event -on: - pull_request: - types: [labeled] - pull_request_target : - types: [ labeled ] - -jobs: - debug: - runs-on: ubuntu-latest - steps: - - run: | - echo "Label added: ${{ github.event.label.name }}" - echo "Action: ${{ github.event.action }}" - echo "PR number: ${{ github.event.pull_request.number }}" \ No newline at end of file From 5d744ebffc090fdd94bdb3b63b9b94cabe25b7f5 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 18:59:15 +0800 Subject: [PATCH 12/17] update --- .github/workflows/backport.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 8adea8720f..10746a5ffc 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -71,7 +71,7 @@ jobs: - name: Push backport branch id: push run: | - BACKPORT_BRANCH="backports/pr-${{ github.event.pull_request.number }}-to-${{ steps.extract.outputs.version }}" + BACKPORT_BRANCH="release-${{ steps.extract.outputs.version }}/backport/pr-${{ github.event.pull_request.number }}" git push origin HEAD:"$BACKPORT_BRANCH" echo "backport_branch=$BACKPORT_BRANCH" >> "$GITHUB_OUTPUT" @@ -80,9 +80,10 @@ jobs: with: script: | const { owner, repo } = context.repo; + const originalPrNumber = ${{ github.event.pull_request.number }}; const version = "${{ steps.extract.outputs.version }}"; const title = `[release/${version}] ${{ steps.pr_info.outputs.title }}`; - const body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\`. + const body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\``; await github.rest.pulls.create({ owner, repo, @@ -90,4 +91,4 @@ jobs: head: "${{ steps.push.outputs.backport_branch }}", base: "${{ steps.extract.outputs.branch }}", body - }); + }); \ No newline at end of file From db294cf9b36e5d20d64cae13e0b43ff41310f9fe Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 19:04:53 +0800 Subject: [PATCH 13/17] update [skip ci] --- .github/workflows/backport.yml | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 10746a5ffc..c912570af4 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -26,7 +26,7 @@ jobs: echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "branch=release/$VERSION" >> "$GITHUB_OUTPUT" else - echo "Error: Invalid label format '$LABEL'. Expected 'backport/3.X' where X is an integer." + echo "Error: Invalid label format '$LABEL'." exit 1 fi @@ -56,22 +56,18 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git fetch "https://github.com/${{ steps.pr_info.outputs.head_repo }}" "${{ steps.pr_info.outputs.head_sha }}" - if ! git merge --squash "${{ steps.pr_info.outputs.head_sha }}" --no-edit; then - echo "Merge failed (likely due to conflicts). Skipping backport." + git merge --squash "${{ steps.pr_info.outputs.head_sha }}" --no-edit || true + git add -A + git commit -m "[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }} + Backport of PR #${{ github.event.pull_request.number }}." || { + echo "No changes to commit. Skipping backport PR creation." exit 0 - fi - if git diff --cached --quiet; then - echo "No changes to backport." - exit 0 - else - git commit -m "[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }} - Backport of PR #${{ github.event.pull_request.number }}." - fi + } - name: Push backport branch id: push run: | - BACKPORT_BRANCH="release-${{ steps.extract.outputs.version }}/backport/pr-${{ github.event.pull_request.number }}" + BACKPORT_BRANCH="pr-backport/${{ steps.extract.outputs.version }}/pr-${{ github.event.pull_request.number }}" git push origin HEAD:"$BACKPORT_BRANCH" echo "backport_branch=$BACKPORT_BRANCH" >> "$GITHUB_OUTPUT" @@ -83,7 +79,7 @@ jobs: const originalPrNumber = ${{ github.event.pull_request.number }}; const version = "${{ steps.extract.outputs.version }}"; const title = `[release/${version}] ${{ steps.pr_info.outputs.title }}`; - const body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\``; + const body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\`\n\n> ⚠️ This backport may contain merge conflicts. Please resolve them manually.`; await github.rest.pulls.create({ owner, repo, From f15468c0fb58789316421f77c9b41369a7b9f387 Mon Sep 17 00:00:00 2001 From: Ciilu <109708109+Ciilu@users.noreply.github.com> Date: Sat, 10 Jan 2026 19:06:48 +0800 Subject: [PATCH 14/17] update [skip ci] --- .github/workflows/backport.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index c912570af4..09819f3d8b 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -58,8 +58,7 @@ jobs: git fetch "https://github.com/${{ steps.pr_info.outputs.head_repo }}" "${{ steps.pr_info.outputs.head_sha }}" git merge --squash "${{ steps.pr_info.outputs.head_sha }}" --no-edit || true git add -A - git commit -m "[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }} - Backport of PR #${{ github.event.pull_request.number }}." || { + git commit -m "[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }}" || { echo "No changes to commit. Skipping backport PR creation." exit 0 } @@ -79,7 +78,7 @@ jobs: const originalPrNumber = ${{ github.event.pull_request.number }}; const version = "${{ steps.extract.outputs.version }}"; const title = `[release/${version}] ${{ steps.pr_info.outputs.title }}`; - const body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\`\n\n> ⚠️ This backport may contain merge conflicts. Please resolve them manually.`; + const body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\``; await github.rest.pulls.create({ owner, repo, From ab98d147a9623b1679053bee7316c1807f3dd7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=9E=E5=BA=90?= <109708109+CiiLu@users.noreply.github.com> Date: Sun, 11 Jan 2026 10:46:51 +0800 Subject: [PATCH 15/17] [skip ci] --- .github/workflows/backport.yml | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 09819f3d8b..cc77bd64cd 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -56,18 +56,26 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git fetch "https://github.com/${{ steps.pr_info.outputs.head_repo }}" "${{ steps.pr_info.outputs.head_sha }}" - git merge --squash "${{ steps.pr_info.outputs.head_sha }}" --no-edit || true + set +e + git merge --squash "${{ steps.pr_info.outputs.head_sha }}" --no-edit + + set -e + git add -A - git commit -m "[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }}" || { + + if git diff --cached --quiet; then echo "No changes to commit. Skipping backport PR creation." exit 0 - } + fi + + COMMIT_MSG="[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }}" + git commit -m "$COMMIT_MSG" - name: Push backport branch id: push run: | BACKPORT_BRANCH="pr-backport/${{ steps.extract.outputs.version }}/pr-${{ github.event.pull_request.number }}" - git push origin HEAD:"$BACKPORT_BRANCH" + git push origin HEAD:"$BACKPORT_BRANCH" --force echo "backport_branch=$BACKPORT_BRANCH" >> "$GITHUB_OUTPUT" - name: Create Backport Pull Request @@ -77,13 +85,16 @@ jobs: const { owner, repo } = context.repo; const originalPrNumber = ${{ github.event.pull_request.number }}; const version = "${{ steps.extract.outputs.version }}"; - const title = `[release/${version}] ${{ steps.pr_info.outputs.title }}`; - const body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\``; - await github.rest.pulls.create({ + + let title = `[release/${version}] ${{ steps.pr_info.outputs.title }}`; + let body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\``; + + const { data: pr } = await github.rest.pulls.create({ owner, repo, title, head: "${{ steps.push.outputs.backport_branch }}", base: "${{ steps.extract.outputs.branch }}", body - }); \ No newline at end of file + }); + From 9c958ae16d1717e7541992f072d9ff2813375ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=9E=E5=BA=90?= <109708109+CiiLu@users.noreply.github.com> Date: Sun, 11 Jan 2026 10:54:16 +0800 Subject: [PATCH 16/17] Update backport.yml --- .github/workflows/backport.yml | 37 ++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index cc77bd64cd..947d01f492 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -50,25 +50,38 @@ jobs: ref: ${{ steps.extract.outputs.branch }} fetch-depth: 0 - - name: Fetch PR changes and simulate squash merge + - name: Fetch PR changes and merge id: apply_changes run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + echo "Fetching changes from origin PR..." git fetch "https://github.com/${{ steps.pr_info.outputs.head_repo }}" "${{ steps.pr_info.outputs.head_sha }}" - set +e + + set +e + git merge --squash "${{ steps.pr_info.outputs.head_sha }}" --no-edit - - set -e + MERGE_EXIT_CODE=$? + set -e + + if [ $MERGE_EXIT_CODE -ne 0 ]; then + echo "has_conflicts=true" >> "$GITHUB_OUTPUT" + COMMIT_PREFIX="[Conflict] " + else + echo "has_conflicts=false" >> "$GITHUB_OUTPUT" + COMMIT_PREFIX="" + fi + git add -A if git diff --cached --quiet; then - echo "No changes to commit. Skipping backport PR creation." + echo "No changes to commit. Skipping." exit 0 fi - COMMIT_MSG="[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }}" + COMMIT_MSG="${COMMIT_PREFIX}[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }}" git commit -m "$COMMIT_MSG" - name: Push backport branch @@ -85,9 +98,18 @@ jobs: const { owner, repo } = context.repo; const originalPrNumber = ${{ github.event.pull_request.number }}; const version = "${{ steps.extract.outputs.version }}"; + const hasConflicts = "${{ steps.apply_changes.outputs.has_conflicts }}" === "true"; let title = `[release/${version}] ${{ steps.pr_info.outputs.title }}`; - let body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\``; + if (hasConflicts) { + title = `[Conflict] ${title}`; + } + + let body = `[Backport] #${originalPrNumber} -> \`${{ steps.extract.outputs.branch }}\`\n\n`; + + if (hasConflicts) { + body += `> Has Merge Conflicts\n\n`; + } const { data: pr } = await github.rest.pulls.create({ owner, @@ -97,4 +119,3 @@ jobs: base: "${{ steps.extract.outputs.branch }}", body }); - From c41524d70d74ef4641320fc331dbd6c17560f6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=9E=E5=BA=90?= <109708109+CiiLu@users.noreply.github.com> Date: Sun, 11 Jan 2026 11:18:24 +0800 Subject: [PATCH 17/17] [skip ci] --- .github/workflows/backport.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 947d01f492..82387ea81f 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -59,9 +59,19 @@ jobs: echo "Fetching changes from origin PR..." git fetch "https://github.com/${{ steps.pr_info.outputs.head_repo }}" "${{ steps.pr_info.outputs.head_sha }}" + HEAD_SHA="${{ steps.pr_info.outputs.head_sha }}" + + git log --pretty=format:"Co-authored-by: %an <%ae>" HEAD..$HEAD_SHA > coauthors.tmp + + git log --pretty=format:"%(trailers:key=Co-authored-by,valueonly=false,separator=%n)" HEAD..$HEAD_SHA >> coauthors.tmp + + COAUTHORS=$(cat coauthors.tmp | sort | uniq | grep -v "github-actions\[bot\]" | sed '/^$/d') + + rm coauthors.tmp + set +e - git merge --squash "${{ steps.pr_info.outputs.head_sha }}" --no-edit + git merge --squash "$HEAD_SHA" --no-edit MERGE_EXIT_CODE=$? set -e @@ -82,7 +92,14 @@ jobs: fi COMMIT_MSG="${COMMIT_PREFIX}[release/${{ steps.extract.outputs.version }}] ${{ steps.pr_info.outputs.title }}" - git commit -m "$COMMIT_MSG" + + if [ -n "$COAUTHORS" ]; then + printf "%s\n\n%s" "$COMMIT_MSG" "$COAUTHORS" > commit_msg.txt + else + printf "%s" "$COMMIT_MSG" > commit_msg.txt + fi + + git commit -F commit_msg.txt - name: Push backport branch id: push