diff --git a/.github/workflows/auto_merge.yaml b/.github/workflows/auto_merge.yaml new file mode 100644 index 00000000..d80d91ba --- /dev/null +++ b/.github/workflows/auto_merge.yaml @@ -0,0 +1,110 @@ +name: Auto Approve and Merge +permissions: + checks: write + contents: write + pull-requests: write +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + branches: [main] + workflow_dispatch: # Add manual trigger for testing + inputs: + pr_number: + description: 'PR number to test auto-merge on' + required: false + type: string + +jobs: + debug-context: + runs-on: ubuntu-latest + # Always run this job to see what's happening + steps: + - name: Debug PR Context + run: | + echo "=== WORKFLOW TRIGGER DEBUG ===" + echo "Event Name: ${{ github.event_name }}" + echo "Workflow Run ID: ${{ github.run_id }}" + echo "Workflow Run Number: ${{ github.run_number }}" + echo "Repository: ${{ github.repository }}" + echo "Ref: ${{ github.ref }}" + echo "Actor: ${{ github.actor }}" + echo "" + echo "=== PR DETAILS ===" + echo "PR Title: '${{ github.event.pull_request.title }}'" + echo "PR Number: ${{ github.event.pull_request.number }}" + echo "PR State: ${{ github.event.pull_request.state }}" + echo "Is Draft: ${{ github.event.pull_request.draft }}" + echo "Base Branch: ${{ github.event.pull_request.base.ref }}" + echo "Head Branch: ${{ github.event.pull_request.head.ref }}" + echo "PR Author: ${{ github.event.pull_request.user.login }}" + echo "PR Author Type: ${{ github.event.pull_request.user.type }}" + echo "" + echo "=== CONDITION CHECKS ===" + echo "Title contains 'Auto-merge workflow': ${{ contains(github.event.pull_request.title, 'Auto-merge workflow') }}" + echo "Author is github-actions: ${{ github.event.pull_request.user.login == 'app/github-actions' }}" + echo "Both conditions met: ${{ github.event.pull_request.user.login == 'app/github-actions' && contains(github.event.pull_request.title, 'Auto-merge workflow') }}" + echo "" + echo "=== TOKEN DEBUG ===" + echo "AUTO_MERGE_TOKEN exists: ${{ secrets.AUTO_MERGE_TOKEN != '' }}" + echo "GITHUB_TOKEN exists: ${{ secrets.GITHUB_TOKEN != '' }}" + + auto-approve-merge: + runs-on: ubuntu-latest + # Only auto-merge PRs created by github-actions[bot] with the test title + if: | + github.event.pull_request.user.login == 'app/github-actions' && + contains(github.event.pull_request.title, 'Auto-merge workflow') + + steps: + - name: Check conditions + run: | + echo "🔍 Checking if should auto-merge..." + echo "PR Title: '${{ github.event.pull_request.title }}'" + echo "PR Author: '${{ github.event.pull_request.user.login }}'" + echo "Title condition: ${{ contains(github.event.pull_request.title, 'Auto-merge workflow') }}" + echo "Author condition: ${{ github.event.pull_request.user.login == 'app/github-actions' }}" + echo "Both conditions: ${{ github.event.pull_request.user.login == 'app/github-actions' && contains(github.event.pull_request.title, 'Auto-merge workflow') }}" + + if [[ "${{ github.event.pull_request.user.login }}" == "app/github-actions" && "${{ github.event.pull_request.title }}" == *"Auto-merge workflow"* ]]; then + echo "✅ Both conditions met - proceeding with auto-merge" + else + echo "❌ Conditions not met - would skip" + echo " - Author is github-actions: ${{ github.event.pull_request.user.login == 'app/github-actions' }}" + echo " - Title contains 'Auto-merge workflow': ${{ contains(github.event.pull_request.title, 'Auto-merge workflow') }}" + exit 0 # Don't fail, just skip + fi + + - name: Check PR status + run: | + echo "=== PR STATUS CHECK ===" + gh pr view ${{ github.event.pull_request.number }} --json state,mergeable,mergeStateStatus,reviewDecision + echo "" + echo "=== PR REVIEWS ===" + gh pr view ${{ github.event.pull_request.number }} --json reviews + echo "" + echo "=== PR CHECKS ===" + gh pr checks ${{ github.event.pull_request.number }} + env: + GH_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} + + - name: Auto approve and merge + if: | + github.event.pull_request.user.login == 'app/github-actions' && + contains(github.event.pull_request.title, 'Auto-merge workflow') + run: | + echo "=== STARTING AUTO-MERGE PROCESS ===" + echo "PR Number: ${{ github.event.pull_request.number }}" + echo "Token available: ${{ secrets.AUTO_MERGE_TOKEN != '' }}" + + echo "Step 1: Approving PR..." + gh pr review ${{ github.event.pull_request.number }} --approve --body "Auto-approved by workflow" + echo "✅ Approval completed" + + echo "Step 2: Enabling auto-merge..." + gh pr merge ${{ github.event.pull_request.number }} --auto --merge --delete-branch + echo "✅ Auto-merge enabled" + + echo "Step 3: Final PR status..." + gh pr view ${{ github.event.pull_request.number }} --json state,mergeable,mergeStateStatus + env: + GH_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test_auto_merge.yaml b/.github/workflows/test_auto_merge.yaml new file mode 100644 index 00000000..fe1f3eba --- /dev/null +++ b/.github/workflows/test_auto_merge.yaml @@ -0,0 +1,33 @@ +name: Create Test PR +on: + workflow_dispatch: + push: + branches: [auto-approve-merge] + +jobs: + create-test-pr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Create test PR + run: | + # Configure git identity + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # Create branch with test file + BRANCH_NAME="test-auto-merge-${{ github.run_number }}" + git checkout -b $BRANCH_NAME + echo "Test $(date)" > test.txt + git add test.txt + git commit -m "test: auto-merge" + git push origin $BRANCH_NAME + + # Create PR + gh pr create \ + --base main \ + --title "Test: Auto-merge workflow" \ + --body "Testing auto-merge functionality" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file