dependabot-approve.yml 1.6 KB

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