Can't enable auto-merge for this pull request
bennycode opened this issue · comments
I am using "dependabot/fetch-metadata" v1.2.1 but I am often receiving an error message that it cannot automatically merge PRs:
Enable auto-merge for Dependabot PRs
Run gh pr merge --auto --squash "$PR_URL"
Message: Can't enable auto-merge for this pull request., Locations: [{Line:[1](https://github.com/southpolecarbon/alaska/runs/5287794531#step:3:1) Column:[7](https://github.com/southpolecarbon/alaska/runs/5287794531#step:3:7)2}]
Error: Process completed with exit code 1.
Am I missing something in my workflow to make it work?
name: Dependabot auto-merge
on: pull_request_target
permissions:
pull-requests: write
contents: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.2.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@bennycode - your action isn't actually using fetch-metadata
(it's ignoring the output) - so it's equivalent to:
name: Dependabot auto-merge
on: pull_request_target
permissions:
pull-requests: write
contents: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
The error you're getting is being thrown by the github cli. I see you already posted about this cli/cli#3660 - if you got an answer on how we can update our example workflow to address this issue, please let me know.
@bennycode Did you resolve this issue? I am facing the same. In my repo, I have branch protection enabled with:
- Require approvals
- Require status checks to pass before merging
- Restrict who can push to matching branches
My latest attempt (ampproject/amp-wp#6975) is to wait to run gh pr merge --auto
until after all of the checks have passed but before I run gh pr review --approve
. Not sure yet if it works.
@bennycode Does using a personal access token solve the issue?
I added a personal access token but I am still seeing this error:
gh pr merge --auto --squash "$PR_URL"
shell: /usr/bin/bash -e {0}
env:
PR_URL: ***
GITHUB_TOKEN: ***
Message: Can't enable auto-merge for this pull request., Locations: [{Line:1 Column:72}]
Error: Process completed with exit code 1.
I got it working in my personal public repository (implementation, proof that it works) but it doesn't work in my org's private repository (that uses the same YML config and has a personal access token configured in GitHub Secrets). 😢
Phew! I just found the issue. I ran into the "Can't enable auto-merge for this pull request" problem because auto-merge wasn't activated in my repo. After activating the "Allow auto-merge" feature in my repository settings it worked:
This made the GitHub Actions bot do the following:
Here is my final config:
name: Dependabot auto-merge
on: [pull_request_target]
permissions:
pull-requests: write
contents: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
steps:
- name: Enable auto-merge on PR
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Approve PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
It actually works without "dependabot/fetch-metadata". I thought I needed "dependabot/fetch-metadata" because it was listed here. I also didn't knew that the secrets.GITHUB_TOKEN is something very special and not just a secret that you setup yourself in the "Action secrets" section of your repository settings.
Thanks to everyone who has helped!!
@brrygrdn: Can the "Can't enable auto-merge for this pull request" error message be improved in GitHub's cli to give a hint that auto-merge must be enabled on repository-level?