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@fe104658747b27e96e4f7e80cd0a94068e53901d # v2.16.1
  16. with:
  17. egress-policy: audit
  18. - uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
  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@ffa630c65fa7e0ecfa0625b5ceda64399aea1b36 # v3.0.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 }}"