|
| 1 | +name: Dependabot auto-merge |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize, ready_for_review] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + automerge: |
| 13 | + if: github.actor == 'dependabot[bot]' && github.event.pull_request.user.login == 'dependabot[bot]' |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Fetch Dependabot metadata |
| 18 | + id: metadata |
| 19 | + uses: dependabot/fetch-metadata@v2 |
| 20 | + with: |
| 21 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + |
| 23 | + # Auto-approve (only matters if your branch protection requires reviews) |
| 24 | + - name: Approve PR |
| 25 | + if: steps.metadata.outputs.update-type != 'version-update:semver-major' |
| 26 | + uses: actions/github-script@v7 |
| 27 | + with: |
| 28 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + script: | |
| 30 | + const { data: reviews } = await github.rest.pulls.listReviews({ |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + pull_number: context.payload.pull_request.number, |
| 34 | + }); |
| 35 | +
|
| 36 | + const alreadyApprovedByBot = reviews.some( |
| 37 | + (review) => |
| 38 | + review.state === "APPROVED" && |
| 39 | + review.user?.login === "github-actions[bot]" |
| 40 | + ); |
| 41 | +
|
| 42 | + if (!alreadyApprovedByBot) { |
| 43 | + await github.rest.pulls.createReview({ |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + pull_number: context.payload.pull_request.number, |
| 47 | + event: "APPROVE", |
| 48 | + }); |
| 49 | + } |
| 50 | +
|
| 51 | + # Enable GitHub auto-merge; it will merge once required checks (your Test Suite) are green |
| 52 | + - name: Enable auto-merge (squash) |
| 53 | + if: steps.metadata.outputs.update-type != 'version-update:semver-major' |
| 54 | + uses: peter-evans/enable-pull-request-automerge@v3 |
| 55 | + with: |
| 56 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + pull-request-number: ${{ github.event.pull_request.number }} |
| 58 | + merge-method: squash |
0 commit comments