| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- name: Dependabot Pull Request Approve and Merge
- on: pull_request_target
- permissions:
- contents: read
- jobs:
- dependabot:
- permissions:
- pull-requests: write
- contents: write
- runs-on: ubuntu-latest
- # Checking the actor will prevent your Action run failing on non-Dependabot
- # PRs but also ensures that it only does work for Dependabot PRs.
- if: ${{ github.actor == 'dependabot[bot]' }}
- steps:
- - uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
- with:
- egress-policy: audit
- - uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
- id: app-token
- with:
- app-id: ${{ secrets.APP_ID }}
- private-key: ${{ secrets.PRIVATE_KEY }}
- # This first step will fail if there's no metadata and so the approval
- # will not occur.
- - name: Dependabot metadata
- id: dependabot-metadata
- uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # v2.5.0
- with:
- github-token: "${{ steps.app-token.outputs.token }}"
- # Here the PR gets approved.
- - name: Approve a PR
- run: gh pr review --approve "$PR_URL"
- env:
- PR_URL: ${{ github.event.pull_request.html_url }}
- GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"
- # Finally, this sets the PR to allow auto-merging for patch and minor
- # updates if all checks pass
- - name: Enable auto-merge for Dependabot PRs
- if: ${{ steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' }}
- run: gh pr merge --auto --squash "$PR_URL"
- env:
- PR_URL: ${{ github.event.pull_request.html_url }}
- GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"
|