peter-evans / enable-pull-request-automerge Goto Github PK
View Code? Open in Web Editor NEWA GitHub action to enable auto-merge on a pull request
License: MIT License
A GitHub action to enable auto-merge on a pull request
License: MIT License
I am getting this error - Can't enable auto-merge for this pull request.
Its merging to the protected branch (main). Should i need to update any branch protection settings?
Here is the code
# Create Pull Request with the updated changes
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ steps.generate_token.outputs.token }}
branch: ${{ steps.application.outputs.application-names }}
delete-branch: true
labels: promotion
title: "[Promotion] ${{ steps.application.outputs.application-names }}"
# Enable Auto-merge option in the Pull Request
- name: Enable Pull Request Automerge
uses: peter-evans/enable-pull-request-automerge@v1
with:
token: ${{ steps.generate_token.outputs.token }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash
After the v2.4.0
is released our workflows started breaking, have attached relevant screenshots, please check.
Download action repository 'peter-evans/enable-pull-request-automerge@v2' (SHA:51b7924f8e9b3bb022e2bb6f30e478e199bfca43)
.../_temp/13c7f0de-517d-4ec7-9fc3-993eb6814875.sh: line 1: merge-method=${INPUT,,}: bad substitution Error: Process completed with exit code 1.
self-hosted
runnersmac-mini
machines as of nowhttps://github.blog/changelog/2023-02-08-pull-request-merge-queue-public-beta/
Investigated a little and it appears to be using the same GraphQL API to "merge when ready." There are some notes in the GraphQL documentation that suggest this is the case.
Todo:
Not sure exactly what's going on, because I have this enabled on a different repo and it works perfectly (or did? Maybe something is wrong with Github at the moment)
Anyways, I have a secret token with repo
privileges, it's all verified to be a valid token with correct privileges, the name is right, etc etc.
I'm using peter-evans/enable-pull-request-automerge@v2
I'm using the following, and the action does run, I know it gets the right PR number.
- name: Enable Pull Request Automerge
uses: peter-evans/enable-pull-request-automerge@v2
with:
# same token I'm using elsewhere, verified it works and is valid
token: ${{ secrets.REPO_SCOPED_TOKEN }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: rebase
In my repo settings, I have both Automatically delete head branches
and Allow auto-merge
enabled, and I have a branch protection rule enabled Require a pull request before merging
and Require approvals
(1), along with your example of auto approving it (though it never gets that far).
I'm certain I've checked off every box for this to work, and yet it seems github is refusing to work. Any ideas?
My guess is maybe github itself is broken, cause I used my secret token for the create pull request action, and it ALWAYS fails saying something like fatal: could not read Username for 'https://github.com/': No such file or directory
, unless I let it use the default GITHUB_TOKEN
. Creating a new secret token with the same privileges results in exactly the same errors
I think I'm at my wits end. Github seems to hate me :/
Can you please add proxy support like you did for the create-pull-request action?
It may be just a matter of bumping octokit to version 3.12.0 or later, see here.
Thanks in advance
I know in the docs it says that it's required a repo scoped Personal Access Token (PAT) is used, where GITHUB_TOKEN
won't work.
Is it possible to use Github Apps instead of PAT, which seems more appropriate in organization projects?
I tried something like this and doesn't work, even with all permissions set to Read & Write
for the App.
steps:
- name: Generate token
id: automerge_t
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Enable Pull Request Automerge
uses: peter-evans/enable-pull-request-automerge@v1
with:
token: ${{ steps.automerge_t.outputs.token }}
pull-request-number: ${{ github.event.pull_request.number }}
merge-method: "REBASE"
Error message isn't very informative:
Fetching pull request ID
##[debug]PullRequestId: 'MDExOlB1bGxSZXXXXXXXXjEyMTM0MTM2'
Enabling auto-merge on pull request ID MDExOlB1bGxSZXXXXXXXjEyMTM0MTM2
##[debug]AutoMergeRequest: { enabledAt: null, enabledBy: { login: 'my-github-app' } }
Error: Failed to enable auto-merge
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Enable Pull Request Automerge
I am getting this error (Error: Could not resolve to a PullRequest with the number of 0). Not sure what this mean. Can you explain why this error is happening? Can you help me out to fix this?
Here is my code
# Create Pull Request with the updated changes
- name: Create Pull Request
if: steps.application.outputs.application-names != ''
id: cpr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ steps.generate_token.outputs.token }}
body: |
Automated promotion of the following applications: ${{ steps.application.outputs.application-names }}
Revision: ${{ github.event.inputs.revision }}
branch: ${{ steps.application.outputs.application-names }}
delete-branch: true
labels: promotion
title: "[Promotion] ${{ matrix.service }}"
# Enable Auto-merge option in the Pull Request
- name: Enable Pull Request Automerge
if: steps.application.outputs.auto-merge == 'true'
uses: peter-evans/enable-pull-request-automerge@v1
with:
token: ${{ steps.generate_token.outputs.token }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash
The pull request also DID NOT get created.
Hey @peter-evans im attempting to create a PR to merge a dev branch into a qa branch. However, seeing an error message when this runs on the merge PR job of the workflow. The error appears with the message Error: Pull Request is not mergable.
Run juliangruber/merge-pull-request-action@v1
with:
github-token: ***
number: 1
method: merge
Error: Pull Request is not mergeable
Here is the particular part of the config being used in the yaml:
- name: create PR to deploy to QA
uses: peter-evans/create-pull-request@v3
with:
branch: deploy-qa
base: react-qa
title: QA Deploy (${{ github.actor }})
commit-message: create PR to deploy react-dev to react-qa
body: Auto-generated PR (via Github Actions manual workflow) to deploy react-dev to react-qa. Intiated by ${{ github.actor }}.
delete-branch: true
I have my theories on why this is not working, but was wondering if you have seen this particular appear or if you see something that should be improved in that particular part of the yaml. Any advice is appreciated. Thank you.
Hello,
I tried to use the action in combination with the Create PR action.
My develop
branch has protection rule activated with "Require status checks before merging". However then the Auto merge action failed with the following errors:
Error: Unable to enable automerge. Make sure you have enabled branch protection with at least one status check marked as required. See https://github.com/peter-evans/enable-pull-request-automerge#conditions for more information.
Error: Request failed due to following response errors:
- ["Pull request Pull request is in clean status"]
When I selected additionally "Require approvals", the auto merge was successful, but then obviously the branch required approval.
I then added (as described in README) https://github.com/juliangruber/approve-pull-request-action but then again it failed with "Cannot approve your own pull request".
Is this scenario at all possible?
If I understand correctly I'm covering all the conditions specified here, but I might me wrong cause I'm quite a noob ๐. Would you mind having a look?
Run peter-evans/enable-pull-request-automerge@v2
Fetching pull request ID
Enabling auto-merge on pull request ID PR_kwDOF66_ps45hpts
Error: Request failed due to following response errors:
- ["Pull request Pull request is closed"]
Corresponding run: https://github.com/billsioros/cookiecutter-pypackage/actions/runs/5068669630
Found this in README:
- name: Auto approve
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ steps.cpr.outputs.pull-request-number }},
event: 'APPROVE'
})
This could be a separate action.
The code is committed to dev automatically after all checks are passed with automerge as intended. But then the PR remains in Open state and the branch is not deleted though delete-branch is set to true.
Also, ensured that we have set Automatically delete head branches.
Below is the code snippet that is used. Please advise if we are missing something or it is how it is. Thanks!
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
with:
author: xxx
base: dev
branch: xxx
commit-message: xxx
committer: xxx
delete-branch: true
team-reviewers: |
xxx
title: |
xxx
token: ${{ steps.xxx.outputs.token }}
- name: Enable Pull Request Automerge
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@v1
with:
token: ${{ steps.xxx.outputs.token }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash
- name: Approve Pull Request
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: juliangruber/approve-pull-request-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.cpr.outputs.pull-request-number }}
Hi,
I am interested in github action that will help me to merge the PR not simply try to enable the automerge flag.
The subtle difference is going to be, that for branches that are not protected it should simply merge the pr instead of reporting error.
Same thing for the case where the PR is already checked, instead of failing to enable the auto merge flag, it should just merge it.
Are you interested in enhancing this tool in that direction?
I'm getting Error: Failed to enable auto-merge
https://github.com/06kellyjac/suckless-git-overlay/runs/2355710781?check_suite_focus=true
I've got auto merge enabled
The branch is protected and requires the tests to pass
The auto-merge button shows up if I look after it's been created
But for some reason the action can't enable it
Is there anything else I can do to debug this? Or do you have any idea what could be the cause?
Maybe it's because it's triggering push and pr tests??
I'm using cron
to update dependencies. Sometimes it produces no change and makes peter-evans/enable-pull-request-automerge
fail.
It's possible to add if
condition, but I guess it would be nicer to just ignore such error.
I propose that peter-evans/enable-pull-request-automerge
ignores pull-request-number: 0
instead of failing
on:
schedule:
- cron: '0 0 * * *'
# ...
- uses: actions/checkout@v2
# update dependencies
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.PAT }}
- name: Enable Pull Request Automerge
uses: peter-evans/enable-pull-request-automerge@v1
with:
token: ${{ secrets.PAT }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash
I was looking to an alternative for juliangruber/approve-pull-request-action and I thought it could be useful for someone else:
- name: Approve pull request
run: gh pr review ${{ steps.create-pr.outputs.pull-request-number }} --approve
env:
GITHUB_TOKEN: ${{ secrets.AUTHORIZED_TOKEN }}
if: steps.create-pr.outputs.pull-request-operation == 'created'
I'm having an issue using this in GitHub Enterprise. It appears that the API base URl is likely api.github.com
. I was able to resolve my issue by mirroring your repo with a patch to configure the baseUrl
when initializing OctoKit
.
I'd be happy to submit a PR, but it also looks like you support GHE in both your repository-dispatch
and create-pull-request
actions in different ways.
Env var: https://github.com/peter-evans/create-pull-request/blob/main/src/github-helper.ts#L27
And, probably this github.getOctokit
method: https://github.com/peter-evans/repository-dispatch/blob/main/src/main.ts#L17
I've been using your repository-dispatch action without issues, so was a bit surprised by this behavior. Please LMK if you'd like me to submit a patch, and your preference on implementation.
Thanks! And, thanks for publishing all these handy actions ๐ฅ
Hi ,
getting the below message when trying to use the action :
Request failed due to following response errors: - ["Pull request Pull request is in unstable status"]
- uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{ secrets.MERGE_SECRET }}
pull-request-number: ${{ github.event.number }}
merge-method: squash
I am unable to auto approve the PR as i get error failed to create review: Message: Can not approve your own pull request
jobs:
otel-collector-patching:
runs-on: [xyz]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Find latest version
id: script
run: |
source test.sh
- name: Create Pull Request
id: automerge
uses: peter-evans/create-pull-request@v5
with:
token: "${{ secrets.GITHUB_TOKEN }}" # Require token to run this PR
author: "sdk[bot] <120429439+sdk-renovate[bot]@users.noreply.github.com>"
branch: abcd-${{ env.branch_name }}
delete-branch: true
base: main
commit-message: Latest version
title: Latest version
body: |
Weekly checked
- bla bla
- bla bla
- name: Enable Pull Request Automerge
run: gh pr merge --squash --auto "${{ steps.automerge.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Auto approve
run: gh pr review --approve "${{ steps.automerge.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
All the steps works fine except the auto approve one. This returns Can not approve your own pull request
This could be totally up to another action project, but still posting here for now just to raise the idea, though I don't know if it's implementable.
I'm proposing adding an input such as mode
, which is default to enable
, and ignores the merge-method
input when set to disable
. The purpose is to allow this action to disable automerge in desired conditions. An example scenario would be something like below, triggered when the base of PR is edited (I bet there's a better way to trigger this).
name: PR Edited
on:
pull_request:
types: [edited]
jobs:
enable-automerge:
if: ${{ github.event.pull_request.base.ref != 'main' }}
runs-on: ubuntu-latest
steps:
- uses: peter-evans/enable-pull-request-automerge@v1
with:
token: ${{ secrets.MY_PAT }}
pull-request-number: ${{ github.event.pull_request.number }}
disable-automerge:
if: ${{ github.event.pull_request.base.ref == 'main' }}
runs-on: ubuntu-latest
steps:
- uses: peter-evans/enable-pull-request-automerge@v1
with:
token: ${{ secrets.MY_PAT }}
pull-request-number: ${{ github.event.pull_request.number }}
mode: disable
I'm struggling with finding another action that disables automerge in marketplace and thought it would be nice if this action has such addition.
Hello Peter!
Thank you for integration. I use Create Pull Request
and it works amazingly.
However, I have a very strange issue with Enable Pull Request Automerge
such as action skipping this step.
I've added below the debug logs. If you have any ideas/tips, it would be very much appreciated.
- name: Enable Pull Request Automerge
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.PAT }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash
Debug logs:
0s
##[debug]Evaluating condition for step: 'Enable Pull Request Automerge'
##[debug]Evaluating: (success() && (steps.cpr.outputs.pull-request-operation == 'created'))
##[debug]Evaluating And:
##[debug]..Evaluating success:
##[debug]..=> true
##[debug]..Evaluating Equal:
##[debug]....Evaluating Index:
##[debug]......Evaluating Index:
##[debug]........Evaluating Index:
##[debug]..........Evaluating steps:
##[debug]..........=> Object
##[debug]..........Evaluating String:
##[debug]..........=> 'cpr'
##[debug]........=> Object
##[debug]........Evaluating String:
##[debug]........=> 'outputs'
##[debug]......=> Object
##[debug]......Evaluating String:
##[debug]......=> 'pull-request-operation'
##[debug]....=> null
##[debug]....Evaluating String:
##[debug]....=> 'created'
##[debug]..=> false
##[debug]=> false
##[debug]Expanded: (true && (null == 'created'))
##[debug]Result: false
Hey,
First of all, thank you for making this Action, it's really helpful.
I wanted to point out that your readme says using a GITHUB_TOKEN will not work when in fact it can.
I had been struggling for days to figure out how to create an action that would auto-merge pull request from approved bots (or any approved user) to a protected branch after passing checks, but would NOT approve requests from just anybody. The question of how to auto-merge dependabot pull requests is a popular one. I ended up pulling it off with this workflow (Which as you can see does not use a PAT):
name: automerge
on:
pull_request_target:
jobs:
automerge:
runs-on: ubuntu-latest
env:
# append additional users below to allow automerge for them
USER_ALLOWLIST: |
'[
"${{github.repository_owner}}",
"dependabot[bot]"
]'
steps:
- name: print troubleshooting info
run: |
echo "event name:" ${{github.event_name}}
echo "event action:" ${{github.event.action}}
echo "actor:" ${{github.actor}}
echo "repository owner:" ${{github.repository_owner}}
echo "pull request user:" ${{github.event.pull_request.user.login}}
echo "pull request number:" ${{github.event.pull_request.number}}
echo "allow list:" ${{ env.USER_ALLOWLIST }}
echo "actor approved?": ${{contains(fromJSON(env.USER_ALLOWLIST), github.actor)}}
echo "pull request user approved?": ${{contains(fromJSON(env.USER_ALLOWLIST), github.event.pull_request.user.login)}}
- name: automerge
if: >-
${{
contains(fromJSON(env.USER_ALLOWLIST), github.actor) &&
contains(fromJSON(env.USER_ALLOWLIST), github.event.pull_request.user.login)
}}
uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{secrets.GITHUB_TOKEN}}
pull-request-number: ${{github.event.pull_request.number}}
merge-method: squash
The trick here is to use the "pull_request_target" event instead of the "pull_request" event. The GITHUB_TOKEN from a pull_request event does not have the required permissions because it runs in the security context of the requestor. On the other hand, the pull_request_target event is identical to the pull_request event in every way except that the GITHUB_TOKEN runs in the security context of the "target" (the approver).
Obviously then pull_request_target can be dangerous because it can allow anyone from the general public full write access to the repo by combining it with enable-pull-request-automerge. You can see that my approach to secure the workflow above is to build an allow list.
Anyway, I just wanted to share this with you because I was pretty excited to finally get it working and not having to use PAT. Feel free to share my workflow above as an example in your readme. I suspect a lot of people who are looking for a way to automerge dependabot and other bots wind up here.
During pull request setup, the delete-branch method was set to true.
Received:
Unexpected input(s) 'delete-branch', valid inputs are ['token', 'repository', 'pull-request-number', 'merge-method']
Configuration:
Run peter-evans/enable-pull-request-automerge@v3
----
with:
token: ***
pull-request-number: 147
merge-method: rebase
delete-branch: true
repository: carstencodes/pdm-bump
env:
pdm_version: 2.8.2
pythonLocation: /opt/hostedtoolcache/Python/[3](https://github.com/carstencodes/pdm-bump/actions/runs/5742218024/job/15563903769#step:15:3).11.[4](https://github.com/carstencodes/pdm-bump/actions/runs/5742218024/job/15563903769#step:15:4)/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.11.4/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.4/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.4/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.4/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.11.4/x64/lib:/opt/hostedtoolcache/Python/3.11.2/x64/lib
PYTHONPATH: /home/runner/.local/share/pdm/venv/lib/python3.11/site-packages/pdm/pep[5](https://github.com/carstencodes/pdm-bump/actions/runs/5742218024/job/15563903769#step:15:5)82
LD_PRELOAD: /lib/x8[6](https://github.com/carstencodes/pdm-bump/actions/runs/5742218024/job/15563903769#step:15:6)_64-linux-gnu/libgcc_s.so.1
PDM_UPDATE_OUTPUT: ๐ Lock successful Packages to update: - chardet 5.1.0 -> 5.2.0 - rich 13.5.1 -> 13.5.2
PDM_PACKAGES_TO_UPDATE: Packages to update:
- chardet 5.1.0 -> 5.2.0
- rich 13.5.1 -> 13.5.2
PDM_UPDATED_PACKAGES_NAMES: - chardet 5.1.0 -> 5.2.0
- rich 13.5.1 -> 13.5.2
PDM_NUMBER_OF_NEW_PACKAGES: 2
GIT_PDM_TITLE: chore: Updated 2 dependencies in pdm.lock
PULL_REQUEST_NUMBER: 147
Hello! I'm trying to add this to one of my repos and I'm running into this error when trying run the action. The full workflow file can be found here. I couldn't really find anything on the internets, do you perhaps have any ideas what might be going wrong? My best guess is that it's attempting to enable automerge before it's ready (definition of ready being: no checks have been registered with the PR yet)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.