|
| 1 | +name: Create Upstream PR Branch |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + issue_number: |
| 7 | + description: 'Issue number (used for branch name: upstream-pr/issue-{number})' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + source_branch: |
| 11 | + description: 'Source branch containing the commits to cherry-pick' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + commit_shas: |
| 15 | + description: 'Comma-separated list of commit SHAs to cherry-pick onto upstream/master' |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + pr_title: |
| 19 | + description: 'Title for the upstream PR (informational only)' |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + |
| 23 | +jobs: |
| 24 | + create-upstream-pr-branch: |
| 25 | + name: Create Clean Upstream PR Branch |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: write |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Configure Git |
| 37 | + run: | |
| 38 | + git config user.name "github-actions[bot]" |
| 39 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 40 | +
|
| 41 | + - name: Fetch upstream master |
| 42 | + run: | |
| 43 | + git remote add upstream https://github.com/eclipse-jdt/eclipse.jdt.ui.git |
| 44 | + git fetch upstream master |
| 45 | +
|
| 46 | + - name: Create branch based on upstream/master |
| 47 | + run: | |
| 48 | + BRANCH_NAME="upstream-pr/issue-${{ inputs.issue_number }}" |
| 49 | + git checkout -b "$BRANCH_NAME" upstream/master |
| 50 | + echo "Created branch: $BRANCH_NAME" |
| 51 | +
|
| 52 | + - name: Cherry-pick specified commits |
| 53 | + id: cherry_pick |
| 54 | + run: | |
| 55 | + BRANCH_NAME="upstream-pr/issue-${{ inputs.issue_number }}" |
| 56 | + COMMIT_SHAS="${{ inputs.commit_shas }}" |
| 57 | + |
| 58 | + # Convert comma-separated list to space-separated |
| 59 | + SHAS=$(echo "$COMMIT_SHAS" | tr ',' ' ' | tr -s ' ') |
| 60 | + |
| 61 | + echo "Cherry-picking commits: $SHAS" |
| 62 | + |
| 63 | + SUCCESS=true |
| 64 | + for SHA in $SHAS; do |
| 65 | + SHA=$(echo "$SHA" | xargs) # trim whitespace |
| 66 | + if [ -z "$SHA" ]; then |
| 67 | + continue |
| 68 | + fi |
| 69 | + echo "Cherry-picking $SHA..." |
| 70 | + if ! git cherry-pick "$SHA"; then |
| 71 | + echo "Cherry-pick failed for $SHA" |
| 72 | + git cherry-pick --abort 2>/dev/null || true |
| 73 | + SUCCESS=false |
| 74 | + break |
| 75 | + fi |
| 76 | + done |
| 77 | + |
| 78 | + if [ "$SUCCESS" = "true" ]; then |
| 79 | + echo "success=true" >> $GITHUB_OUTPUT |
| 80 | + else |
| 81 | + echo "success=false" >> $GITHUB_OUTPUT |
| 82 | + fi |
| 83 | +
|
| 84 | + - name: Verify branch contents |
| 85 | + if: steps.cherry_pick.outputs.success == 'true' |
| 86 | + run: | |
| 87 | + echo "=== Commits on this branch (not in upstream/master) ===" |
| 88 | + git log upstream/master..HEAD --oneline |
| 89 | + echo "" |
| 90 | + echo "=== Files changed vs upstream/master ===" |
| 91 | + git diff upstream/master..HEAD --stat |
| 92 | +
|
| 93 | + - name: Force-push branch to fork |
| 94 | + if: steps.cherry_pick.outputs.success == 'true' |
| 95 | + run: | |
| 96 | + BRANCH_NAME="upstream-pr/issue-${{ inputs.issue_number }}" |
| 97 | + git push --force origin "$BRANCH_NAME" |
| 98 | + echo "✅ Branch '$BRANCH_NAME' pushed to fork" |
| 99 | +
|
| 100 | + - name: Output PR creation link |
| 101 | + if: steps.cherry_pick.outputs.success == 'true' |
| 102 | + run: | |
| 103 | + BRANCH_NAME="upstream-pr/issue-${{ inputs.issue_number }}" |
| 104 | + REPO_OWNER="${{ github.repository_owner }}" |
| 105 | + REPO_NAME="${{ github.event.repository.name }}" |
| 106 | + PR_LINK="https://github.com/eclipse-jdt/eclipse.jdt.ui/compare/master...${REPO_OWNER}:${REPO_NAME}:${BRANCH_NAME}" |
| 107 | + |
| 108 | + echo "" |
| 109 | + echo "==========================================" |
| 110 | + echo "✅ Branch ready for upstream PR!" |
| 111 | + echo "==========================================" |
| 112 | + echo "" |
| 113 | + echo "Branch: $BRANCH_NAME" |
| 114 | + if [ -n "${{ inputs.pr_title }}" ]; then |
| 115 | + echo "PR Title: ${{ inputs.pr_title }}" |
| 116 | + fi |
| 117 | + echo "" |
| 118 | + echo "Create PR at:" |
| 119 | + echo "$PR_LINK" |
| 120 | + echo "" |
| 121 | +
|
| 122 | + - name: Fail if cherry-pick failed |
| 123 | + if: steps.cherry_pick.outputs.success == 'false' |
| 124 | + run: | |
| 125 | + echo "❌ Cherry-pick failed. Check the logs above for details." |
| 126 | + exit 1 |
0 commit comments