dependabot-approve.yml 1.8 KB

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