Release v1.34.0 #5
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: Automatic Backport to Develop | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| create-backport-pr: | |
| # Only run if the PR was actually merged (not just closed) | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get merged branch name | |
| id: get-branch | |
| run: | | |
| # Get the head branch name from the merged PR | |
| BRANCH_NAME="${{ github.event.pull_request.head.ref }}" | |
| echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| echo "Merged branch: $BRANCH_NAME" | |
| - name: Check if branch exists | |
| id: check-branch | |
| run: | | |
| BRANCH_NAME="${{ steps.get-branch.outputs.branch-name }}" | |
| # Check if the branch still exists on the remote | |
| if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then | |
| echo "branch-exists=true" >> $GITHUB_OUTPUT | |
| echo "Branch $BRANCH_NAME exists and can be used for backport" | |
| else | |
| echo "branch-exists=false" >> $GITHUB_OUTPUT | |
| echo "Branch $BRANCH_NAME no longer exists, cannot create backport PR" | |
| fi | |
| - name: Create backport PR | |
| if: steps.check-branch.outputs.branch-exists == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const branchName = '${{ steps.get-branch.outputs.branch-name }}'; | |
| const originalPrNumber = context.payload.pull_request.number; | |
| const originalPrTitle = context.payload.pull_request.title; | |
| const originalPrBody = context.payload.pull_request.body || ''; | |
| const originalPrAuthor = context.payload.pull_request.user.login; | |
| // Create the backport PR | |
| try { | |
| const response = await github.rest.pulls.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `[Backport] ${originalPrTitle}`, | |
| head: branchName, | |
| base: 'develop', | |
| body: `## Automatic Backport\n\nThis is an automatic backport of PR #${originalPrNumber} by @${originalPrAuthor} to the \`develop\` branch.\n\n### Original PR Details:\n${originalPrBody}\n\n---\n*This PR was created automatically when #${originalPrNumber} was merged into \`main\`.*`, | |
| maintainer_can_modify: true | |
| }); | |
| console.log(`✅ Successfully created backport PR #${response.data.number}`); | |
| console.log(`🔗 PR URL: ${response.data.html_url}`); | |
| // Add labels to the backport PR | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: response.data.number, | |
| labels: ['backport', 'automated'] | |
| }); | |
| } catch (error) { | |
| console.error('❌ Failed to create backport PR:', error.message); | |
| // Check if it's a conflict or other specific error | |
| if (error.message.includes('No commits between')) { | |
| console.log('ℹ️ The branch is already up to date with develop - no backport needed'); | |
| } else if ( | |
| error.status === 422 && | |
| error.response && | |
| Array.isArray(error.response.data?.errors) && | |
| error.response.data.errors.some(e => | |
| e.message && e.message.includes('A pull request already exists') | |
| ) | |
| ) { | |
| console.log('ℹ️ A pull request already exists for this branch to develop'); | |
| } else { | |
| // Re-throw for other errors to fail the workflow | |
| throw error; | |
| } | |
| } | |
| - name: Handle missing branch | |
| if: steps.check-branch.outputs.branch-exists == 'false' | |
| run: | | |
| echo "⚠️ Cannot create backport PR because the source branch no longer exists." | |
| echo "This typically happens when the branch was deleted after merging." | |
| echo "If a backport to develop is needed, it should be done manually." |