Pull requests merged but not closed

I have set up a Github Actions workflow that sets every PR to auto-merge when all the checks pass. When I manually do this through the browser by clicking the auto-merge button the PR, it works fine but through the workflow, most of the time the PR ends up stuck at “Attempting to auto-merge…”.

Sometimes when the merge is successful, the PR ends up merged but stays open. All the configured actions that should run when a commit is pushed to the merged branch also didn’t run. I haven’t found a way to reliably reproduce this yet.

Here’s a simplified version of my workflow file:

name: PR Automerge

    types: [opened, reopened, edited, ready_for_review]

  PR_URL: ${{github.event.pull_request.html_url}}

    runs-on: ubuntu-latest
    - name: Enable auto-merge
      run: gh pr merge --auto --squash "$PR_URL"
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

After reading in the forum, I think this issue is caused by how the GITHUB_TOKEN works in a workflow. This part from the docs explains it:

When you use the repository’s GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run.

Since the merge is triggered by the github bot, which is using the GITHUB_TOKEN for auth, it cannot triggers my deploy workflow.