|
| 1 | +name: PR Auto-merge |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_review: |
| 5 | + types: [submitted] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + auto-merge: |
| 13 | + name: Auto-merge Release PRs |
| 14 | + runs-on: ubuntu-latest |
| 15 | + # Only run when PR is approved and it's a release PR |
| 16 | + if: | |
| 17 | + github.event.review.state == 'approved' && |
| 18 | + github.event.pull_request.user.login == 'github-actions[bot]' && |
| 19 | + startsWith(github.event.pull_request.head.ref, 'release/') && |
| 20 | + github.event.pull_request.base.ref == 'main' |
| 21 | +
|
| 22 | + steps: |
| 23 | + - name: Check CI status |
| 24 | + id: ci-status |
| 25 | + uses: actions/github-script@v7 |
| 26 | + with: |
| 27 | + script: | |
| 28 | + const { data: checkRuns } = await github.rest.checks.listForRef({ |
| 29 | + owner: context.repo.owner, |
| 30 | + repo: context.repo.repo, |
| 31 | + ref: context.payload.pull_request.head.sha |
| 32 | + }); |
| 33 | +
|
| 34 | + // Include ALL required checks |
| 35 | + const requiredChecks = [ |
| 36 | + 'Lint', |
| 37 | + 'Test Python 3.10', |
| 38 | + 'Test Python 3.11', |
| 39 | + 'Test Python 3.12', |
| 40 | + 'Test Python 3.13', |
| 41 | + 'Build Package' |
| 42 | + ]; |
| 43 | +
|
| 44 | + const allPassed = requiredChecks.every(checkName => { |
| 45 | + const check = checkRuns.check_runs.find(run => run.name === checkName); |
| 46 | + return check && check.conclusion === 'success'; |
| 47 | + }); |
| 48 | +
|
| 49 | + console.log(`All required checks passed: ${allPassed}`); |
| 50 | + return allPassed; |
| 51 | +
|
| 52 | + - name: Auto-merge PR |
| 53 | + if: steps.ci-status.outputs.result == 'true' |
| 54 | + uses: actions/github-script@v7 |
| 55 | + with: |
| 56 | + script: | |
| 57 | + await github.rest.pulls.merge({ |
| 58 | + owner: context.repo.owner, |
| 59 | + repo: context.repo.repo, |
| 60 | + pull_number: context.payload.pull_request.number, |
| 61 | + merge_method: 'squash', |
| 62 | + commit_title: `Release v${context.payload.pull_request.head.ref.split('/')[1]}`, |
| 63 | + commit_message: 'Auto-merged by release workflow' |
| 64 | + }); |
| 65 | +
|
| 66 | + console.log('✓ PR auto-merged successfully'); |
0 commit comments