name: auto-merge

on:
  pull_request_target:
    types:
    - opened
    - reopened
    - synchronize
    branches:
    - master

jobs:
  dependabot:
    runs-on: ubuntu-latest
    if: ${{ github.actor == 'dependabot[bot]' }}

    steps:
    - name: Wait for tests to succeed
      uses: lewagon/wait-on-check-action@v1.3.4
      with:
        ref: ${{ github.ref }}
        check-name: check
        wait-interval: 10
        repo-token: ${{ secrets.GITHUB_TOKEN }}

    - name: Enable auto-merge for Dependabot PRs
      run: gh pr merge --auto --squash ${{ github.event.pull_request.html_url }}
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
