name: Dependabot auto-merge

on:
  pull_request_target:
    branches: [master]

permissions:
  contents: write
  pull-requests: write

jobs:
  auto-merge:
    name: Auto-merge low-risk Dependabot PRs
    if: github.event.pull_request.user.login == 'dependabot[bot]'
    runs-on: ubuntu-latest
    steps:
      - name: Fetch Dependabot metadata
        id: metadata
        uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Auto-approve + auto-merge GH Actions minor + patch
        if: |
          steps.metadata.outputs.package-ecosystem == 'github_actions' &&
          (steps.metadata.outputs.update-type == 'version-update:semver-minor' ||
           steps.metadata.outputs.update-type == 'version-update:semver-patch')
        env:
          PR_URL: ${{ github.event.pull_request.html_url }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh pr review --approve "$PR_URL"
          gh pr merge --auto --squash "$PR_URL"
