Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not automerge when "branch is out-of-date with the base branch" #74

Closed
hugovk opened this issue Apr 30, 2020 · 15 comments
Closed

Does not automerge when "branch is out-of-date with the base branch" #74

hugovk opened this issue Apr 30, 2020 · 15 comments

Comments

@hugovk
Copy link

hugovk commented Apr 30, 2020

In a private repo, using default config from the README, with added MERGE_REMOVE_LABELS:

name: automerge
on:
  pull_request:
    types:
      - labeled
      - unlabeled
      - synchronize
      - opened
      - edited
      - ready_for_review
      - reopened
      - unlocked
  pull_request_review:
    types:
      - submitted
  check_suite:
    types:
      - completed
  status: {}
jobs:
  automerge:
    runs-on: ubuntu-latest
    steps:
      - name: automerge
        uses: "pascalgn/automerge-action@135f0bdb927d9807b5446f7ca9ecc2c51de03c4a"
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
          MERGE_REMOVE_LABELS: "automerge"

We have branch protection rules like this:

image

The PR to add this action was approved by two people (1 approval is required). The master branch had since moved forward from other PRs, meaning normally I need to manually click this button, wait ~5 minutes for CI to pass, before I can manually merge:

image

Instead, I added the automerge label, and the action was triggered but failed to merge:

INFO  Event name: pull_request
INFO  Updating PR #2541 GHA: Merge PRs automatically when labelled "automerge"
INFO  No update necessary, mergeable_state: clean
INFO  Merging PR #2541 GHA: Merge PRs automatically when labelled "automerge"
INFO  PR is probably ready: mergeable_state: clean
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (1/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (2/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (3/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (4/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (5/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (6/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  PR could not be merged after 6 tries

I expected it would merge master into the PR, wait for the checks to pass, and then merge the PR into master.

The checks looks like this:

image

This looks wrong, "Travis CI - Branch" is green:

INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.

So the PR is in a clean mergeable state, but branch protection rules require master to be merged into the PR branch, before the PR can be merged into master.

Is it possible for this action to do the update from master into the PR? Basically the same as clicking that button?

@progapandist
Copy link

same issue here, will subscribe to comments

@pascalgn
Copy link
Owner

I just tried again in my test repository, but cannot reproduce the error.

I used the exact same config that you have:

name: automerge
on:
  pull_request:
    types:
      - labeled
      - unlabeled
      - synchronize
      - opened
      - edited
      - ready_for_review
      - reopened
      - unlocked
  pull_request_review:
    types:
      - submitted
  check_suite:
    types:
      - completed
  status: {}
jobs:
  automerge:
    runs-on: ubuntu-latest
    steps:
      - name: automerge
        uses: "pascalgn/automerge-action@135f0bdb927d9807b5446f7ca9ecc2c51de03c4a"
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
          MERGE_REMOVE_LABELS: "automerge"

I also made sure that the branch was behind (GH shows "This branch is out-of-date with the base branch" message)

After the build has run (CircleCI in my case), automerge is triggered correctly:

2020-05-17T14:30:42.6903835Z INFO  Event name: status
2020-05-17T14:30:42.8990165Z INFO  Updating PR #41 Update README.md
2020-05-17T14:30:44.4202773Z INFO  Merge succeeded, new HEAD: pascalgn-patch-27 39b570dfb6fefdac32e5a87e1e76a69471a8924c
2020-05-17T14:30:44.4206306Z INFO  Merging PR #41 Update README.md
2020-05-17T14:30:44.4209634Z INFO  PR is probably ready: mergeable_state: undefined
2020-05-17T14:30:44.6619594Z INFO  Failed to merge PR: Head branch was modified. Review and try the merge again.
2020-05-17T14:30:44.6619874Z INFO  Retrying after 10000 ms ... (1/6)
2020-05-17T14:30:55.4781694Z INFO  Failed to merge PR: Required status check "ci/circleci: build" is pending.
2020-05-17T14:30:55.4782492Z INFO  Retrying after 10000 ms ... (2/6)
2020-05-17T14:31:06.1173126Z INFO  Failed to merge PR: Required status check "ci/circleci: build" is pending.
2020-05-17T14:31:06.1173571Z INFO  Retrying after 10000 ms ... (3/6)
2020-05-17T14:31:18.4114512Z INFO  PR successfully merged!
2020-05-17T14:31:18.7268099Z INFO  Removed labels: [ { id: �[33m1570336508�[39m,
2020-05-17T14:31:18.7268448Z     node_id: �[32m'MDU6TGFiZWwxNTcwMzM2NTA4'�[39m,
2020-05-17T14:31:18.7268544Z     url:
2020-05-17T14:31:18.7274148Z      �[32m'https://api.github.com/repos/pascalgn/test/labels/automerge'�[39m,
2020-05-17T14:31:18.7274436Z     name: �[32m'automerge'�[39m,
2020-05-17T14:31:18.7274637Z     color: �[32m'68d142'�[39m,
2020-05-17T14:31:18.7274820Z     default: �[33mfalse�[39m,
2020-05-17T14:31:18.7275027Z     description: �[32m''�[39m } ]
2020-05-17T14:31:18.9104470Z Cleaning up orphan processes

@hugovk
Copy link
Author

hugovk commented May 17, 2020

@pascalgn Thanks for checking!

Did you manually click the "Update branch" button?

I didn't, and was hoping automerge would take care of this initial merge too.

@pascalgn
Copy link
Owner

No, I did not click that button manually, that's what the action is supposed to do. You can see it in lines 3 in the logs I posted:

2020-05-17T14:30:42.6903835Z INFO  Event name: status
2020-05-17T14:30:42.8990165Z INFO  Updating PR #41 Update README.md
2020-05-17T14:30:44.4202773Z INFO  Merge succeeded, new HEAD: pascalgn-patch-27 39b570dfb6fefdac32e5a87e1e76a69471a8924c

(it's from https://github.com/pascalgn/automerge-action/blob/master/lib/update.js#L102)

@hugovk
Copy link
Author

hugovk commented May 18, 2020

I removed the label, waited for the action to finish, then added it again and got the same log as before:

INFO  Event name: pull_request
INFO  Updating PR #2541 GHA: Merge PRs automatically when labelled "automerge"
INFO  No update necessary, mergeable_state: clean
INFO  Merging PR #2541 GHA: Merge PRs automatically when labelled "automerge"
INFO  PR is probably ready: mergeable_state: clean
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (1/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (2/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (3/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (4/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (5/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  Retrying after 10000 ms ... (6/6)
INFO  Failed to merge PR: Required status check "Travis CI - Branch" is expected.
INFO  PR could not be merged after 6 tries

It didn't merge the master into the PR (so the CI didn't trigger), as it thought it was clean:

INFO  Updating PR #2541 GHA: Merge PRs automatically when labelled "automerge"
INFO  No update necessary, mergeable_state: clean

Could it be because it's with a private repo?

@progapandist Is it happening for you with a private repo too?

I'll try and reproduce it in a public repo or a dummy private repo which I can then make public.

@progapandist
Copy link

Exactly, private repo for me too! My required check is also an Action one, and I test again after merge so I have to use a private token too that’s not the repo admin, but has a write access

@hugovk
Copy link
Author

hugovk commented May 18, 2020

Reproduced on a public repo: hugovk/test#24

Branch protection rules are same as above (except without "Require pull request reviews before merging" because I can't approve my own PRs):

image

When I added the automerge label it triggered this action:

INFO  Event name: pull_request
INFO  Updating PR #24 GHA: Add automerge
INFO  No update necessary, mergeable_state: clean
INFO  Merging PR #24 GHA: Add automerge
INFO  PR is probably ready: mergeable_state: clean
INFO  Failed to merge PR: Required status check "continuous-integration/travis-ci" is expected.
INFO  Retrying after 10000 ms ... (1/6)
INFO  Failed to merge PR: Required status check "continuous-integration/travis-ci" is expected.
INFO  Retrying after 10000 ms ... (2/6)
INFO  Failed to merge PR: Required status check "continuous-integration/travis-ci" is expected.
INFO  Retrying after 10000 ms ... (3/6)
INFO  Failed to merge PR: Required status check "continuous-integration/travis-ci" is expected.
INFO  Retrying after 10000 ms ... (4/6)
INFO  Failed to merge PR: Required status check "continuous-integration/travis-ci" is expected.
INFO  Retrying after 10000 ms ... (5/6)
INFO  Failed to merge PR: Required status check "continuous-integration/travis-ci" is expected.
INFO  Retrying after 10000 ms ... (6/6)
INFO  Failed to merge PR: Required status check "continuous-integration/travis-ci" is expected.
INFO  PR could not be merged after 6 tries

https://github.com/hugovk/test/pull/24/checks?check_run_id=686145556

But it didn't do any merges. Again, the same thing:

INFO  Updating PR #24 GHA: Add automerge
INFO  No update necessary, mergeable_state: clean

@pascalgn
Copy link
Owner

pascalgn commented May 18, 2020

Hey everyone, really sorry, but this looks like #47, not sure why I didn't make the connection earlier!

So I just pushed another commit (#78), could you change your action config to uses: "pascalgn/automerge-action@c2174ed3528ef18341085aeb27d2b562ea02f078" and try again?

@hugovk
Copy link
Author

hugovk commented May 18, 2020

Getting closer!

On hugovk/test#24:

  1. remove label
  2. wait for checks to settle
  3. update automerge commit
  4. wait for checks to settle
  5. add label
    -> the action merged master into the PR
    -> https://github.com/hugovk/test/runs/686644621?check_suite_focus=true
    -> but then stopped there
INFO  Event name: pull_request
INFO  Updating PR #24 GHA: Add automerge
INFO  Merge succeeded, new HEAD: gha-automerge 944c95507e2fd6fbca51f542ce97e31253f69bcc
INFO  Merging PR #24 GHA: Add automerge
INFO  Current PR status: mergeable_state: behind
INFO  Retrying after 5000 ms ... (1/6)
INFO  Current PR status: mergeable_state: blocked
INFO  Retrying after 5000 ms ... (2/6)
INFO  Current PR status: mergeable_state: blocked
INFO  Retrying after 5000 ms ... (3/6)
INFO  Current PR status: mergeable_state: blocked
INFO  Retrying after 5000 ms ... (4/6)
INFO  Current PR status: mergeable_state: blocked
INFO  Retrying after 5000 ms ... (5/6)
INFO  Current PR status: mergeable_state: blocked
INFO  Retrying after 5000 ms ... (6/6)
INFO  Current PR status: mergeable_state: blocked
INFO  PR not ready to be merged after 6 tries

Does it need the retry timeout to be long enough to wait for the CI to finish?

@pascalgn
Copy link
Owner

Ah, yes, that's to be expected. After the build is finished, a status or check_suite event should be triggered and that time, automerge should be able to successfully merge the PR

@progapandist
Copy link

However it does not get triggered if the check is also a GHA. would love to know workarounds for that one! 🙏

@pascalgn
Copy link
Owner

Yes, unfortunately that's a limitation of GH actions, as also mentioned here: https://github.com/pascalgn/automerge-action#limitations. If you do come across a workaround for it, let me know! 👍

@pascalgn
Copy link
Owner

I think the original issue is fixed now. However, feel free to reopen this or create a new issue if you disagree or if there are any other problems! 👍

@hugovk
Copy link
Author

hugovk commented Jun 19, 2020

Yes, I think so too. It's a bit of a problem with private repos where minutes are in a quota/billed, but thank you for the help!

@jainankit
Copy link

This may be related to Github Actions, but there are other approaches to automating merges as well. One that I've used in past is https://mergequeue.com that does not use Github Action to manage automerge, so some of the limitations here can be overcome. It also support auto-rebasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants