diff --git a/.github/workflows/auto_merge.yaml b/.github/workflows/auto_merge.yaml new file mode 100644 index 00000000..d4a9bb56 --- /dev/null +++ b/.github/workflows/auto_merge.yaml @@ -0,0 +1,53 @@ +name: Auto Approve and Merge + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + workflow_dispatch: # Add manual trigger for testing + +jobs: + debug-context: + runs-on: ubuntu-latest + # Always run this job to see what's happening + steps: + - name: Debug PR Context + run: | + echo "Event Name: ${{ github.event_name }}" + 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 "Contains check: ${{ contains(github.event.pull_request.title, 'Auto-merge workflow') }}" + + auto-approve-merge: + runs-on: ubuntu-latest + # TODO: restore condition + if: 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 }}'" + + if [[ "${{ github.event.pull_request.title }}" == *"Auto-merge workflow"* ]]; then + echo "✅ Title contains 'Auto-merge workflow' - proceeding" + else + echo "❌ Title does not contain 'Auto-merge workflow' - would skip" + exit 0 # Don't fail, just skip + fi + + - name: Auto approve and merge + if: contains(github.event.pull_request.title, 'Auto-merge workflow') + run: | + echo "Auto-merging PR #${{ github.event.pull_request.number }}" + + # Approve + gh pr review ${{ github.event.pull_request.number }} --approve + + # Enable auto-merge + gh pr merge ${{ github.event.pull_request.number }} --auto --merge --delete-branch + 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..a45f703c --- /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 auto-approve-merge \ + --title "Test: Auto-merge workflow" \ + --body "Testing auto-merge functionality" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file