|
| 1 | +name: Create Clean Generation PR to Main |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + |
| 7 | +jobs: |
| 8 | + create-pr: |
| 9 | + # Only run if PR was actually merged (not just closed) |
| 10 | + if: github.event.pull_request.merged == true |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Check if this is a conflict resolution merge |
| 15 | + id: check-branches |
| 16 | + run: | |
| 17 | + BASE_BRANCH="${{ github.event.pull_request.base.ref }}" |
| 18 | + HEAD_BRANCH="${{ github.event.pull_request.head.ref }}" |
| 19 | +
|
| 20 | + echo "Base branch: $BASE_BRANCH" |
| 21 | + echo "Head branch: $HEAD_BRANCH" |
| 22 | +
|
| 23 | + # Check if base branch starts with speakeasy/clean-generation- |
| 24 | + if [[ "$BASE_BRANCH" == speakeasy/clean-generation-* ]] && [[ "$HEAD_BRANCH" == speakeasy/resolve-* ]]; then |
| 25 | + echo "This is a conflict resolution merge" |
| 26 | + echo "is_conflict_resolution=true" >> $GITHUB_OUTPUT |
| 27 | + echo "clean_gen_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT |
| 28 | + else |
| 29 | + echo "This is not a conflict resolution merge" |
| 30 | + echo "is_conflict_resolution=false" >> $GITHUB_OUTPUT |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Check if PR already exists |
| 34 | + if: steps.check-branches.outputs.is_conflict_resolution == 'true' |
| 35 | + id: check-pr |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + run: | |
| 39 | + CLEAN_GEN_BRANCH="${{ steps.check-branches.outputs.clean_gen_branch }}" |
| 40 | +
|
| 41 | + # Search for existing open PR from clean-generation branch to main |
| 42 | + EXISTING_PR=$(gh pr list \ |
| 43 | + --repo ${{ github.repository }} \ |
| 44 | + --head "$CLEAN_GEN_BRANCH" \ |
| 45 | + --base main \ |
| 46 | + --state open \ |
| 47 | + --json number \ |
| 48 | + --jq '.[0].number') |
| 49 | +
|
| 50 | + if [ -n "$EXISTING_PR" ]; then |
| 51 | + echo "PR already exists: #$EXISTING_PR" |
| 52 | + echo "pr_exists=true" >> $GITHUB_OUTPUT |
| 53 | + echo "pr_number=$EXISTING_PR" >> $GITHUB_OUTPUT |
| 54 | + else |
| 55 | + echo "No existing PR found" |
| 56 | + echo "pr_exists=false" >> $GITHUB_OUTPUT |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Create PR to main |
| 60 | + if: steps.check-branches.outputs.is_conflict_resolution == 'true' && steps.check-pr.outputs.pr_exists == 'false' |
| 61 | + env: |
| 62 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + run: | |
| 64 | + CLEAN_GEN_BRANCH="${{ steps.check-branches.outputs.clean_gen_branch }}" |
| 65 | +
|
| 66 | + # Create PR body |
| 67 | + PR_BODY="# SDK Generation with Resolved Conflicts |
| 68 | +
|
| 69 | +This PR contains the successfully generated SDK with custom code conflicts resolved. |
| 70 | + |
| 71 | +**Source Branch:** \`$CLEAN_GEN_BRANCH\` |
| 72 | +**Target Branch:** \`main\` |
| 73 | + |
| 74 | +## What Happened |
| 75 | + |
| 76 | +1. SDK generation detected custom code conflicts |
| 77 | +2. Conflict resolution PR was created and merged |
| 78 | +3. This PR now contains the complete, working SDK |
| 79 | + |
| 80 | +## Next Steps |
| 81 | + |
| 82 | +1. Review the changes in this PR |
| 83 | +2. Verify all conflicts were properly resolved |
| 84 | +3. Merge to \`main\` to complete the SDK update |
| 85 | + |
| 86 | +--- |
| 87 | +🤖 This PR was created automatically after conflict resolution" |
| 88 | + |
| 89 | + # Create the PR |
| 90 | + gh pr create \ |
| 91 | + --repo ${{ github.repository }} \ |
| 92 | + --head "$CLEAN_GEN_BRANCH" \ |
| 93 | + --base main \ |
| 94 | + --title "✅ SDK Update with Resolved Conflicts" \ |
| 95 | + --body "$PR_BODY" |
| 96 | + |
| 97 | + echo "✅ Created PR from $CLEAN_GEN_BRANCH to main" |
| 98 | + |
| 99 | + - name: Log result |
| 100 | + if: steps.check-branches.outputs.is_conflict_resolution == 'true' |
| 101 | + run: | |
| 102 | + if [[ "${{ steps.check-pr.outputs.pr_exists }}" == "true" ]]; then |
| 103 | + echo "✅ PR already exists (#${{ steps.check-pr.outputs.pr_number }}), no action needed" |
| 104 | + else |
| 105 | + echo "✅ Successfully created PR to main" |
| 106 | + fi |
0 commit comments