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

Inconsistent view of mergeable_state resulting in wrong behaviour #103

Closed
mortenlj opened this issue Aug 14, 2020 · 10 comments
Closed

Inconsistent view of mergeable_state resulting in wrong behaviour #103

mortenlj opened this issue Aug 14, 2020 · 10 comments

Comments

@mortenlj
Copy link

I have configured automerge-action to run in a scheduled workflow, every 5 minutes. When it runs, it finds one PR that has the labels I have configured.

The PR needs to be updated from master, which I expect the action to perform. Then it should be ready to merge.

When it runs, it first says mergeable_state is blocked, which results in not doing an update. Then it says mergeable_state is undefined, and that makes it not try to merge. If I try using the API to look up mergeable_state, I get behind.

We have configured branch protections, so unless the branch is updated nobody is allowed to merge. That's why it is failing to merge. The big question is why it is getting two different values for mergeable_state, neither of which are correct as far as I can tell. Presumably, if it had gotten the correct values, it would also do the expected thing (which is to first update, then merge).

Run pascalgn/automerge-action@v0.9.0
  env:
    GITHUB_TOKEN: ***
    MERGE_DELETE_BRANCH: true
    UPDATE_LABELS: terraform/plan:OK
    MERGE_LABELS: terraform/apply:OK,!terraform/plan:FAIL,!terraform/apply:FAIL
/usr/bin/docker run --name cb286b38ed2990440a850dfa5aa6585b56_d5285c --label 8118cb --workdir /github/workspace --rm -e GITHUB_TOKEN -e MERGE_DELETE_BRANCH -e UPDATE_LABELS -e MERGE_LABELS -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/repo/repo":"/github/workspace" 8118cb:286b38ed2990440a850dfa5aa6585b56
INFO  Event name: schedule
INFO  Updating PR #9 Gcp bucket
INFO  No update done due to PR mergeable_state blocked
INFO  Merging PR #9 Gcp bucket
INFO  PR is probably ready: mergeable_state: undefined
INFO  Failed to merge PR: You're not authorized to push to this branch. Visit https://docs.github.com/articles/about-protected-branches/ for more information.
INFO  Retrying after 5000 ms ... (1/6)
INFO  Failed to merge PR: You're not authorized to push to this branch. Visit https://docs.github.com/articles/about-protected-branches/ for more information.
INFO  Retrying after 5000 ms ... (2/6)
INFO  Failed to merge PR: You're not authorized to push to this branch. Visit https://docs.github.com/articles/about-protected-branches/ for more information.
INFO  Retrying after 5000 ms ... (3/6)
INFO  Failed to merge PR: You're not authorized to push to this branch. Visit https://docs.github.com/articles/about-protected-branches/ for more information.
INFO  Retrying after 5000 ms ... (4/6)
INFO  Failed to merge PR: You're not authorized to push to this branch. Visit https://docs.github.com/articles/about-protected-branches/ for more information.
INFO  Retrying after 5000 ms ... (5/6)
INFO  Failed to merge PR: You're not authorized to push to this branch. Visit https://docs.github.com/articles/about-protected-branches/ for more information.
@evis
Copy link

evis commented Aug 17, 2020

3_automerge.txt
I have a similar problem, though, my log looks a bit different:

INFO  Updating PR #1034 introduce automerge action
INFO  No update done due to PR mergeable_state blocked
INFO  Merging PR #1034 introduce automerge action
INFO  Current PR status: mergeable_state: blocked

When it runs, it first says mergeable_state is blocked, which results in not doing an update. <...> If I try using the API to look up mergeable_state, I get behind.

Same problem for me. I'm able to get mergeable_state = behind via API, but automerge-action gets mergeable-state = blocked (check attached log).

Seems like a bug in either octokit usage in automerge-action or a bug in octokit/github api itself.

@evis
Copy link

evis commented Aug 17, 2020

update: tried to query Github API using octokit -- got mergeable_state = behind.

@pascalgn
Copy link
Owner

Are you checking the state at the same time the automerge-action is running? Because it could be that the state is blocked due to automerge-action. So while that action is running, GH API could report blocked. I think I've seen this before sometimes.

@mortenlj
Copy link
Author

Are you checking the state at the same time the automerge-action is running? Because it could be that the state is blocked due to automerge-action. So while that action is running, GH API could report blocked. I think I've seen this before sometimes.

I checked before and after and I think I managed to "catch" in during at least once. I always got behind. What is automerge-action doing before checking the state that could make it blocked?

@evis
Copy link

evis commented Aug 18, 2020

I've just tried to check during automerge check: github api responsed to me with behind (several times), but responsed to automerge-action with blocked (several times too).

@pascalgn
Copy link
Owner

This looks a bit like a GH API bug and I'm afraid I cannot help you here. The correct place to address it is https://github.saobby.my.eu.orgmunity/, I think. Unfortunately, the GH API, especially with regards to GH actions, has some unexpected behaviours which I also struggled with in the beginning. It has gotten a bit better, but there are still issues like this one. Sorry for not being able to give you any better news!

@3h4x
Copy link

3h4x commented Aug 31, 2020

@pascalgn I have a PR which is constantly blocked

INFO Current PR status: mergeable_state: blocked
INFO Retrying after 60000 ms ... (1/60)

Is there a way to try to force merge even with state blocked?

https://github.com/cloudposse/terraform-aws-sns-topic/pull/5/checks?check_run_id=1043109403

@pascalgn
Copy link
Owner

@3h4x That is a different issue, see #3 for more info

@3h4x
Copy link

3h4x commented Aug 31, 2020

Thanks @pascalgn for pointer.
I have already solved my issue. It was that auto-merge.yaml workflow was not on master branch.
This has forbidden runs after checks are completed (such workflow needs to be on master according to documentation).
So in my case tests prevented merge.

Screenshot 2020-08-31 at 20 29 47

@pascalgn
Copy link
Owner

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

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