| 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@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
- with:
- egress-policy: audit
- - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
- 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@d7267f607e9d3fb96fc2fbe83e0af444713e90b7 # v2.3.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 }}"
|