diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml new file mode 100644 index 000000000..fed182e42 --- /dev/null +++ b/.github/workflows/dependabot-auto-merge.yml @@ -0,0 +1,32 @@ +name: Dependabot auto-merge + +# pull_request_target gives this workflow a write token for Dependabot PRs. +# It never checks out PR code, so no untrusted code runs in this context. +on: pull_request_target + +permissions: + contents: write + pull-requests: write + +jobs: + dependabot: + name: Auto-merge minor and patch updates + runs-on: ubuntu-latest + if: github.event.pull_request.user.login == 'dependabot[bot]' + steps: + - name: Fetch Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0 + + # GitHub Actions updates are skipped: they edit workflow files, which + # GITHUB_TOKEN (no workflows permission) cannot merge. + - name: Approve and enable auto-merge + if: (steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch') && steps.metadata.outputs.package-ecosystem != 'github_actions' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_URL: ${{ github.event.pull_request.html_url }} + run: | + if [ "$(gh pr view "$PR_URL" --json reviewDecision --jq .reviewDecision)" != "APPROVED" ]; then + gh pr review --approve "$PR_URL" + fi + gh pr merge --auto --squash "$PR_URL"