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

Merging fails if master is a protected branch and required checks have not yet passed #14

Closed
wereHamster opened this issue Oct 4, 2019 · 18 comments

Comments

@wereHamster
Copy link

I made the master branch in my repo protected, such that certain checks must pass before merging is allowed. Unfortunately the automerge-action runs in parallel to the required check, and so the merge fails (Failed to merge PR: Required status check "build" is in progress). It seems that automerge-action is not triggered when checks finish, so it never re-runs.

@pascalgn
Copy link
Owner

pascalgn commented Oct 4, 2019

Yes, unfortunately GH does not (did not? maybe they fixed it now) correctly report the status of checks every time. You should see a log line, before "Failed to merge", like "PR is probably ready: mergeable_state: ...", do you know which state is logged there?

Regarding

It seems that automerge-action is not triggered when checks finish, so it never re-runs.

I think it's the same as described in #7

@wereHamster
Copy link
Author

INFO  Event name: pull_request
INFO  Updating PR #140 Bump mocha from 6.2.0 to 6.2.1
INFO  No update necessary
INFO  PR is probably ready: mergeable_state: unknown
INFO  Failed to merge PR: Required status check "build" is in progress.
INFO  Retrying after 10000 ms ... (1/3)
INFO  Failed to merge PR: Required status check "build" is in progress.
INFO  Retrying after 10000 ms ... (2/3)
INFO  Failed to merge PR: Required status check "build" is in progress.
INFO  Retrying after 10000 ms ... (3/3)
INFO  Failed to merge PR: Required status check "build" is in progress.
INFO  PR could not be merged after 3 tries

@pascalgn
Copy link
Owner

pascalgn commented Oct 4, 2019

Yes, as I suspected, GH reports a wrong state here, in my opinion:

PR is probably ready: mergeable_state: unknown

This state is also reported when checks are running that are not required and I think I remember this state being reported in some cases where no checks were running at all. So the only thing we can do at that moment is to try and merge and see if we get an error back.

Regarding your other point, "automerge-action is not triggered when checks finish", I think we can do something. There's an open issue #7 and even a PR #8, but I never heard back from the original author. So maybe check if this already helps you and if not, create a new PR 👍

@wereHamster
Copy link
Author

I tried the code from the PR and I can't get it to work. I can't even get GitHub to trigger the automerge action when the check run completes (even if I register for the check_suite and check_run events). I found this in the GitHub docs:

An action in a workflow run can't trigger a new workflow run. For example, if an action pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.

If this applies to my situation (ie. if one check run finishes it won't trigger any other actions) then I'm afraid my idea won't ever work.

@pascalgn
Copy link
Owner

pascalgn commented Oct 6, 2019

Yes, that's correct, and I think GH will not change this anytime soon, since it can very easily result in an infinite loop of actions triggering each other. However, I think this is still useful in all the cases where an external CI is used, like CircleCI, TravisCI, etc.

@pascalgn
Copy link
Owner

I'm closing this now, but if you have any additional input or need support, feel free to reopen this and/or create a new issue, of course!

@zacharylawrence
Copy link

Would it be possible to use needs syntax here? Or does that not work since it requires both checks to run in the same workflow?

https://help.github.com/en/github/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idneeds

@pascalgn
Copy link
Owner

pascalgn commented Nov 4, 2019

needs might work, but it has the big limitation that it will only work for checks created from GH actions (and even them, I'm not sure it will really work). But many checks also come from external services, like CircleCI or Jenkins

@ChristophWurst
Copy link

Hi!

I'm facing the same problem in our repo, where we enabled this action today: https://github.com/nextcloud/nextcloud-moment/pull/125/checks?check_run_id=443656543. The master branch is protected. But even after all required checks are finished and no other ones are run, the action is stuck with the protected branch error.

Dependabot, however, is able to auto merge PRs. I read a bit of your action's code. Am I understanding this correctly that you merge the branch locally and try to push it back to the target branch? Would it be possible to invoke Github's merge operation instead? It's a wild guess but I could imagine that this makes a difference for Githubs branch protection.

@pascalgn
Copy link
Owner

I think the workflow you described is only used to rebase the branch onto the base branch, in case it's out of date ("behind").

The actual merging into the base happens using regular GH API calls, see https://github.com/pascalgn/automerge-action/blob/master/lib/merge.js#L259

@ChristophWurst
Copy link

Thanks for the info!

I'm pretty sure the branch was up to date, hence it shouldn't need to update anything. Tried with merge and squash, btw, and got the same results.

@ChristophWurst
Copy link

If there is a way to get more debug logs from the action please let me know and I'll try to gather that!

@pascalgn pascalgn reopened this Feb 16, 2020
@pascalgn
Copy link
Owner

Yes, GH user olivierlefloch was so nice and provided details in the README, see here: https://github.com/pascalgn/automerge-action#debugging

@ChristophWurst
Copy link

Thanks, that gives some great insight: https://github.com/nextcloud/nextcloud-moment/pull/139/checks?check_run_id=449857817

What I find most interesting is

mergeable: true,
...
mergeable_state: 'blocked',

No idea why it's blocked, though. Checks pass and there was a review. Is this a bug in Github? It might be "blocked" by this action, though it's not set as required step.

@ChristophWurst
Copy link

Also now it says mergeable_state: 'clean' https://api.github.com/repos/nextcloud/nextcloud-moment/pulls/139

@pascalgn
Copy link
Owner

This could be a bug in the GitHub API and it might be related or even the same problem as described here: #8 (comment) 😞

@shugybugy-assaf
Copy link

Until you resolve this issue -
Here is a workaround -

Add a bookmark, (name it AutoMerge if you want), paste the following script as a URL:

This works when the repo is configured to "rebase and merge".
Edit the strings for your repo if it is configured otherwise.

javascript:(
function(){
    alert("AutoMerge is w8ing for the possibility to merge - please keep the tab open and DO NOT refresh the page");
    function queryItems(kind){
        return Array.prototype.slice.call(document.querySelectorAll(kind));
    };
   function autoMerge (){
   console.log("running");
   const blocked = queryItems('div').filter(el=>el.innerText === 'Merging is blocked')[0];
   const blocked2 = queryItems('p').filter(el=>el.innerText === 'As an administrator, you may still merge this pull request.')[0];

   if(blocked || blocked2){
       console.log("mergeIsBlocked-sleeping");
       setTimeout(autoMerge, 1000);
     return;
   }
   const btn = queryItems('button').filter(el=>el.innerText === 'Rebase and merge')[0];
       if (btn) {
            console.log("merging...");
           btn.click();
           var btn2 = queryItems('button').filter(btn=>btn.innerText === 'Confirm rebase and merge')[0];
           if(!btn2){
               btn2 = queryItems('button').filter(btn=>btn.innerText === 'Confirm merge')[0];
           }
           if (btn2) {
               btn2.click();
           }
       }
       const btn3 = queryItems('button').filter(btn=>btn.innerText === 'Delete branch')[0];
       if (btn3) {
            console.log("removing branch...");
           btn3.click();
           return;
       }
       console.log(123);
       setTimeout(autoMerge, 1000);
   };

    autoMerge();
}
)();

Tested on Firefox.

@pascalgn
Copy link
Owner

I think this might be fixed now, but the error is quite hard to reproduce and it's a long time since there was any activity here. I would ask you to try with the latest version and if you have any new information or need any help, feel free to reopen this issue!

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

5 participants