This repository was archived by the owner on Jul 6, 2025. It is now read-only.
chore(actions)(deps): bump actions/github-script from 6 to 7 #37
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Automated Backport | |
| on: | |
| pull_request_target: | |
| types: [closed, labeled] | |
| issue_comment: | |
| types: [created] | |
| jobs: | |
| backport: | |
| name: Backport PR | |
| if: > | |
| (github.event_name == 'pull_request_target' && | |
| github.event.pull_request.merged == true) || | |
| (github.event_name == 'issue_comment' && | |
| github.event.issue.pull_request && | |
| contains(github.event.comment.body, '/backport')) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Extract backport branches | |
| id: extract-branches | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const labels = context.payload.pull_request ? | |
| context.payload.pull_request.labels : | |
| (await github.rest.issues.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.issue.number | |
| })).data.labels; | |
| const backportLabels = labels | |
| .filter(label => label.name.startsWith('backport-to-')) | |
| .map(label => label.name.replace('backport-to-', '')); | |
| console.log(`Backport branches: ${backportLabels.join(', ')}`); | |
| return backportLabels; | |
| - name: Create backport PRs | |
| if: steps.extract-branches.outputs.result != '[]' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const branches = ${{ steps.extract-branches.outputs.result }}; | |
| const prNumber = context.payload.pull_request ? | |
| context.payload.pull_request.number : | |
| context.payload.issue.number; | |
| for (const branch of branches) { | |
| try { | |
| // Create new branch for backport | |
| const backportBranch = `backport-${prNumber}-to-${branch}`; | |
| await exec.exec('git', ['checkout', branch]); | |
| await exec.exec('git', ['checkout', '-b', backportBranch]); | |
| // Cherry-pick the original PR's commits | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| const commits = await github.rest.pulls.listCommits({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| for (const commit of commits.data) { | |
| await exec.exec('git', ['cherry-pick', '-x', commit.sha]); | |
| } | |
| // Push the branch | |
| await exec.exec('git', ['push', 'origin', backportBranch]); | |
| // Create PR | |
| const { data: backportPr } = await github.rest.pulls.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `[Backport ${branch}] ${pr.title}`, | |
| body: `Backport of #${prNumber} to ${branch}\n\nOriginal PR: #${prNumber}`, | |
| head: backportBranch, | |
| base: branch | |
| }); | |
| // Add labels | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: backportPr.number, | |
| labels: ['backport'] | |
| }); | |
| console.log(`Created backport PR #${backportPr.number} for ${branch}`); | |
| } catch (error) { | |
| console.error(`Failed to create backport PR for ${branch}: ${error}`); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: `⚠️ Failed to create backport PR for ${branch}: ${error.message}` | |
| }); | |
| } | |
| } | |
| - name: Notify success | |
| if: success() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prNumber = context.payload.pull_request ? | |
| context.payload.pull_request.number : | |
| context.payload.issue.number; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: '✅ Backport PRs created successfully!' | |
| }); |