pascalgn / automerge-action

GitHub action to automatically merge pull requests that are ready
MIT License
841 stars 207 forks source link

Use repository_dispatch event to trigger events for merged PRs #117

Open llucax opened 3 years ago

llucax commented 3 years ago

The limitation of actions not being run for pushes done by this action is a bit annoying, as merge commits are not tested.

GiHub offers a repository_dispatch event that can be used to trigger actions manually using a GitHub API call to generate the event.

I wonder if this mechanism can be integrated into this action, so to make sure other actions are ran for merges, one just need to add one more on: event trigger including repository_dispatch.

pascalgn commented 3 years ago

This is already integrated: https://github.com/pascalgn/automerge-action/blob/master/lib/api.js#L73

It's also included in the list of supported events: https://github.com/pascalgn/automerge-action#supported-events

llucax commented 3 years ago

I'm not sure if we are talking about the same thing. If I understand correctly, that is so the automerge action is run on repository_dispatch, right? What I want is the automerge action to trigger the repository_dispatch event, so I can use it as a trigger for my own actions that I want to be run when a PR is auto-merged.

I'm still a bit new to GitHub actions so I'm not sure if I am making sense, but what I actually want is to workaround this limitation: When a pull request is merged by this action, the merge will not trigger other GitHub workflows. by having some configuration to tell the automerge action to create a repository_dispatch event, with a, (possibly configurable) event_type: "automerged".

Would that be possible?

pascalgn commented 3 years ago

The workflow_run event is always triggered by this action (as all other actions). I've updated the README accordingly.

llucax commented 3 years ago

Hi @pascalgn, I still find it hard to see how I can do what I request here. If in my test/deploy workflow I act upon a workflow_run (completed) for the automerge workflow for example, how do I know if the PR was actually merged or the automerge workflow just ran but all the automerge conditions weren't met? Is there any repository you know that has what I am requesting implemented so I can have a look to a full working example?

Thanks!

runephilosof-abtion commented 3 years ago

When I use this action to automerge a PR (using squash and merge). A commit is generated in our target branch, but our CI tests are not being run against that commit. This in turn results in our deployment not being run, because it wait for a green CI before deploying.

pascalgn commented 3 years ago

Yes, you need to configure that CI action to be triggered on workflow_run, I suppose. But this has nothing to do with the automerge action per se, so I cannot really help you here.

llucax commented 3 years ago

Sorry to bother you again, but then I assume that you don't know of any examples to point us to, right?

Again, I know very little about GitHub actions as I only started to use them not too long ago, but from what I understand from the documentation of the repository dispatch event, the action should create the even via an API call (and only when the PR was merged) so other workflows can run on: repository_dispatch.

Using just on: workflow_run, it will be triggered on every automerge run, not only when the PR was merged. I'm not sure if there is any way to check if the result of the automerge workflow was a merge or not, but I think it would make much easier to configure this use case if the automerge action would just create a repository_dispatch event with an event_type like automerge-merged (it could also be a configuration variable for the action).