Auto-merge for PRs to a branch whether it's protected or not, once tests succeed #49730
Replies: 3 comments 4 replies
-
|
To achieve your desired workflow, you can set up a GitHub Action that runs your tests whenever a pull request is opened or updated. If the tests pass, the action can automatically approve and merge the pull request. Here's an example of what the GitHub Action workflow file might look like: name: Run tests and merge on success
on:
pull_request:
branches:
- main
jobs:
build-and-merge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: ./run-tests.sh
- name: Merge on success
if: ${{ success() }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Automated merge of PR
delete-branch: trueIn this workflow, the on section specifies that the action should be triggered whenever a pull request is opened or updated on the main branch. The build-and-merge job runs on an Ubuntu environment and consists of three steps:
With this workflow in place, pull requests will be automatically merged if the tests pass, and will not be merged if the tests fail. This allows you to maintain a balance between speed of development and code quality, without compromising on the integrity of your codebase. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I might not have made that clear, I do not want this to be automatic in any way. I want to use the opt-in Github UI for it "pressing the merge for me" PR per PR. I don't want "valid" PRs to auto-merge. For some PRs, I want to not have to go back to a PR and check if the tests passed. For others, I just want to keep them happy and open. |
Beta Was this translation helpful? Give feedback.
-
|
You can achieve this by configuring the branch protection rules for your repository in GitHub. Here's how:
With this configuration, a PR will only be mergeable if all the selected status checks have passed. However, you can still manually override this restriction by clicking the "Merge pull request" button on the PR and confirming the merge. This allows you to opt-in to merge the PR without having to go back and check if the tests passed. Note that if you want to keep some PRs open without having to merge them, you can simply leave them unmerged. The branch protection rules only apply to mergeable PRs, so you can safely ignore the rules for PRs you don't want to merge. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
We've got tests that easily run for 20 minutes.
We don't necessarily want to require a review or that all tests must pass in order to merge a PR, this is on a GitHub Enterprise private repo.
I want to have a PR merge if the tests succeed. If the tests don't pass, I don't want it to merge even if we don't require them to pass.
Beta Was this translation helpful? Give feedback.
All reactions