1+ name : Auto Approve and Merge
2+ permissions :
3+ checks : write
4+ contents : write
5+ pull-requests : write
6+ on :
7+ pull_request :
8+ types : [opened, synchronize, reopened, ready_for_review]
9+ branches : [main]
10+ workflow_dispatch :
11+ inputs :
12+ pr_number :
13+ description : ' PR number to test auto-merge on'
14+ required : false
15+ type : string
16+
17+ jobs :
18+ auto-approve-merge :
19+ runs-on : ubuntu-latest
20+ if : |
21+ github.event.pull_request.user.login == 'app/github-actions' &&
22+ contains(github.event.pull_request.title, 'Update SDK - Generate')
23+
24+ steps :
25+ - name : Check conditions
26+ run : |
27+ echo "🔍 Checking if should auto-merge..."
28+ echo "PR Title: '${{ github.event.pull_request.title }}'"
29+ echo "PR Author: '${{ github.event.pull_request.user.login }}'"
30+ echo "Title condition: ${{ contains(github.event.pull_request.title, 'Update SDK - Generate') }}"
31+ echo "Author condition: ${{ github.event.pull_request.user.login == 'app/github-actions' }}"
32+ echo "Both conditions: ${{ github.event.pull_request.user.login == 'app/github-actions' && contains(github.event.pull_request.title, 'Update SDK - Generate') }}"
33+
34+ if [[ "${{ github.event.pull_request.user.login }}" == "app/github-actions" && "${{ github.event.pull_request.title }}" == *"Update SDK - Generate"* ]]; then
35+ echo "✅ Both conditions met - proceeding with auto-merge"
36+ else
37+ echo "❌ Conditions not met"
38+ echo " - Author is github-actions: ${{ github.event.pull_request.user.login == 'app/github-actions' }}"
39+ echo " - Title contains 'Update SDK - Generate': ${{ contains(github.event.pull_request.title, 'Update SDK - Generate') }}"
40+ exit 0 # Don't fail, just skip
41+ fi
42+
43+ - name : Auto approve and merge
44+ if : |
45+ github.event.pull_request.user.login == 'app/github-actions' &&
46+ contains(github.event.pull_request.title, 'Update SDK - Generate')
47+ run : |
48+ echo "=== STARTING AUTO-MERGE PROCESS ==="
49+ echo "PR Number: ${{ github.event.pull_request.number }}"
50+ echo "Token available: ${{ secrets.AUTO_MERGE_TOKEN != '' }}"
51+
52+ echo "Step 1: Approving PR..."
53+ gh pr review ${{ github.event.pull_request.number }} --approve --body "Auto-approved by workflow"
54+ echo "✅ Approval completed"
55+
56+ echo "Step 2: Enabling auto-merge..."
57+ gh pr merge ${{ github.event.pull_request.number }} --auto --merge --delete-branch
58+ echo "✅ Auto-merge enabled"
59+
60+ echo "Step 3: Final PR status..."
61+ gh pr view ${{ github.event.pull_request.number }} --json state,mergeable,mergeStateStatus
62+ env :
63+ GH_TOKEN : ${{ secrets.AUTO_MERGE_TOKEN }}
0 commit comments