add automated release workflows (PyPI disabled for testing) #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Auto-merge | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| pull_request_review: | |
| types: [submitted] | |
| check_suite: | |
| types: [completed] | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: [completed] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| auto-merge: | |
| name: Auto-merge Release PRs | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.pull_request.user.login == 'github-actions[bot]' && | |
| startsWith(github.event.pull_request.head.ref, 'release/') && | |
| github.event.pull_request.base.ref == 'main' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Check PR approval status | |
| id: approval | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: reviews } = await github.rest.pulls.listReviews({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number | |
| }); | |
| const approved = reviews.some(review => review.state === 'APPROVED'); | |
| console.log(`PR approved: ${approved}`); | |
| return approved; | |
| - name: Check CI status | |
| id: ci-status | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: checkRuns } = await github.rest.checks.listForRef({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: context.payload.pull_request.head.sha | |
| }); | |
| const requiredChecks = ['Lint', 'Test Python 3.10']; | |
| const allPassed = requiredChecks.every(checkName => { | |
| const check = checkRuns.check_runs.find(run => run.name === checkName); | |
| return check && check.conclusion === 'success'; | |
| }); | |
| console.log(`All required checks passed: ${allPassed}`); | |
| return allPassed; | |
| - name: Auto-merge PR | |
| if: steps.approval.outputs.result == 'true' && steps.ci-status.outputs.result == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.pulls.merge({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number, | |
| merge_method: 'squash', | |
| commit_title: `Release v${context.payload.pull_request.head.ref.split('/')[1]}`, | |
| commit_message: 'Auto-merged by release workflow' | |
| }); | |
| console.log('✓ PR auto-merged successfully'); |