dependabot-approve.yml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. name: Dependabot Pull Request Approve and Merge
  2. on: pull_request_target
  3. jobs:
  4. dependabot:
  5. permissions:
  6. pull-requests: write
  7. contents: write
  8. runs-on: ubuntu-latest
  9. # Checking the actor will prevent your Action run failing on non-Dependabot
  10. # PRs but also ensures that it only does work for Dependabot PRs.
  11. if: ${{ github.actor == 'dependabot[bot]' }}
  12. steps:
  13. - uses: actions/create-github-app-token@v1
  14. id: app-token
  15. with:
  16. app-id: ${{ secrets.APP_ID }}
  17. private-key: ${{ secrets.PRIVATE_KEY }}
  18. # This first step will fail if there's no metadata and so the approval
  19. # will not occur.
  20. - name: Dependabot metadata
  21. id: dependabot-metadata
  22. uses: dependabot/fetch-metadata@v1.1.1
  23. with:
  24. github-token: "${{ steps.app-token.outputs.token }}"
  25. # Here the PR gets approved.
  26. - name: Approve a PR
  27. run: gh pr review --approve "$PR_URL"
  28. env:
  29. PR_URL: ${{ github.event.pull_request.html_url }}
  30. GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"
  31. # Finally, this sets the PR to allow auto-merging for patch and minor
  32. # updates if all checks pass
  33. - name: Enable auto-merge for Dependabot PRs
  34. if: ${{ steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' }}
  35. run: gh pr merge --auto --squash "$PR_URL"
  36. env:
  37. PR_URL: ${{ github.event.pull_request.html_url }}
  38. GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"