dependabot-approve.yml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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]' && github.event.pull_request.user.login == 'dependabot[bot]'
  14. steps:
  15. - uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
  16. with:
  17. egress-policy: audit
  18. - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
  19. id: app-token
  20. env:
  21. APP_ID: ${{ secrets.APP_ID }}
  22. with:
  23. app-id: ${{ env.APP_ID }}
  24. private-key: ${{ secrets.PRIVATE_KEY }}
  25. # This first step will fail if there's no metadata and so the approval
  26. # will not occur.
  27. - name: Dependabot metadata
  28. id: dependabot-metadata
  29. uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
  30. with:
  31. github-token: "${{ steps.app-token.outputs.token }}"
  32. # Here the PR gets approved.
  33. - name: Approve a PR
  34. run: gh pr review --approve "$PR_URL"
  35. env:
  36. PR_URL: ${{ github.event.pull_request.html_url }}
  37. GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"
  38. # Finally, this sets the PR to allow auto-merging for patch and minor
  39. # updates if all checks pass
  40. - name: Enable auto-merge for Dependabot PRs
  41. if: ${{ steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' }}
  42. run: gh pr merge --auto --squash "$PR_URL"
  43. env:
  44. PR_URL: ${{ github.event.pull_request.html_url }}
  45. GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"