diff --git a/.github/workflows/auto_merge.yaml b/.github/workflows/auto_merge.yaml new file mode 100644 index 000000000..8583daf70 --- /dev/null +++ b/.github/workflows/auto_merge.yaml @@ -0,0 +1,59 @@ +name: Auto-merge generated SDK PRs + +on: + pull_request: + types: [opened, reopened, synchronize, labeled, ready_for_review] + +permissions: + contents: write + pull-requests: write + +jobs: + enable-automerge: + if: > + (github.event.pull_request.user.login == 'github-actions' || + github.event.pull_request.user.login == 'github-actions[bot]') && + startsWith(github.event.pull_request.title, 'chore: 🐝 Update SDK - Generate') + runs-on: ubuntu-latest + steps: + - name: Check labels (needs minor or patch) + id: labels + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + const prNumber = context.payload.pull_request.number; + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ owner, repo, issue_number: prNumber }); + const names = labels.map(l => l.name.toLowerCase()); + core.setOutput('match', names.includes('minor') || names.includes('patch')); + + - name: Auto-approve pull request + if: steps.labels.outputs.match == 'true' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const prNumber = context.payload.pull_request.number; + try { + await github.rest.pulls.createReview({ + owner, + repo, + pull_number: prNumber, + event: 'APPROVE', + body: 'Auto-approved: SDK update with minor/patch label' + }); + } catch (error) { + 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.`); + throw error; + } + + - name: Enable auto-merge (squash) + if: steps.labels.outputs.match == 'true' + uses: peter-evans/enable-pull-request-automerge@v3 + with: + pull-request-number: ${{ github.event.pull_request.number }} + merge-method: squash + token: ${{ secrets.GITHUB_TOKEN }} + +