| 1234567891011121314151617181920212223242526272829303132333435363738 |
- name: Dependabot Pull Request Approve and Merge
- on: pull_request_target
- jobs:
- dependabot:
- permissions:
- pull-requests: write
- contents: write
- runs-on: ubuntu-latest
- # Checking the actor will prevent your Action run failing on non-Dependabot
- # PRs but also ensures that it only does work for Dependabot PRs.
- if: ${{ github.actor == 'dependabot[bot]' }}
- steps:
- - uses: actions/create-github-app-token@v1
- id: app-token
- with:
- app-id: ${{ secrets.APP_ID }}
- private-key: ${{ secrets.PRIVATE_KEY }}
- # This first step will fail if there's no metadata and so the approval
- # will not occur.
- - name: Dependabot metadata
- id: dependabot-metadata
- uses: dependabot/fetch-metadata@v1.1.1
- with:
- github-token: "${{ steps.app-token.outputs.token }}"
- # Here the PR gets approved.
- - name: Approve a PR
- run: gh pr review --approve "$PR_URL"
- env:
- PR_URL: ${{ github.event.pull_request.html_url }}
- GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"
- # Finally, this sets the PR to allow auto-merging for patch and minor
- # updates if all checks pass
- - name: Enable auto-merge for Dependabot PRs
- if: ${{ steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' }}
- run: gh pr merge --auto --squash "$PR_URL"
- env:
- PR_URL: ${{ github.event.pull_request.html_url }}
- GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"
|