|
| 1 | +name: Auto-merge generated SDK PRs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize, labeled, ready_for_review] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + enable-automerge: |
| 13 | + if: > |
| 14 | + (github.event.pull_request.user.login == 'github-actions' || |
| 15 | + github.event.pull_request.user.login == 'github-actions[bot]') && |
| 16 | + startsWith(github.event.pull_request.title, 'chore: 🐝 Update SDK - Generate') |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Check labels (needs minor or patch) |
| 20 | + id: labels |
| 21 | + uses: actions/github-script@v7 |
| 22 | + with: |
| 23 | + script: | |
| 24 | + const { owner, repo } = context.repo; |
| 25 | + const prNumber = context.payload.pull_request.number; |
| 26 | + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ owner, repo, issue_number: prNumber }); |
| 27 | + const names = labels.map(l => l.name.toLowerCase()); |
| 28 | + core.setOutput('match', names.includes('minor') || names.includes('patch')); |
| 29 | +
|
| 30 | + - name: Auto-approve pull request |
| 31 | + if: steps.labels.outputs.match == 'true' |
| 32 | + uses: actions/github-script@v7 |
| 33 | + with: |
| 34 | + github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} |
| 35 | + script: | |
| 36 | + const { owner, repo } = context.repo; |
| 37 | + const prNumber = context.payload.pull_request.number; |
| 38 | + try { |
| 39 | + await github.rest.pulls.createReview({ |
| 40 | + owner, |
| 41 | + repo, |
| 42 | + pull_number: prNumber, |
| 43 | + event: 'APPROVE', |
| 44 | + body: 'Auto-approved: SDK update with minor/patch label' |
| 45 | + }); |
| 46 | + } catch (error) { |
| 47 | + core.warning(`Failed to approve PR: ${error.message}. If using GITHUB_TOKEN, you may need to create a Personal Access Token (PAT) and store it as GH_PAT secret.`); |
| 48 | + throw error; |
| 49 | + } |
| 50 | +
|
| 51 | + - name: Enable auto-merge (squash) |
| 52 | + if: steps.labels.outputs.match == 'true' |
| 53 | + uses: peter-evans/enable-pull-request-automerge@v3 |
| 54 | + with: |
| 55 | + pull-request-number: ${{ github.event.pull_request.number }} |
| 56 | + merge-method: squash |
| 57 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + |
0 commit comments