Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 11

Action runs when PR is created, but not when PR is merged

Solved! Go to Solution.

Hi,

 

This is the same issue as described in support ticket 358105, but it's been 11 days and I haven't had any reply on that ticket. I have links to relevant PR's and stuff in that ticket if any staff would find those useful.

 

I have a GitHub action which runs when a PR is created, and runs when I add reviewers to the PR, all of which is expected. But it does not run when the PR gets merged. And given that this is the jessfraz branch cleanup action, the only relevant event for this action is when a PR gets merged. When a PR gets merged, there's no logs or any indication in the 'Actions' UI that the action runs, though I do see logs for it when a PR is created and reviewers are added.

 

Note that this worked great on the old HCL system, then it stopped running entirely for all events a few weeks ago. I have since migrated it to YAML and it now runs when a PR is created, but not when the PR is merged. In case of any of that is relevant.

 

Anybody know why this isn't running when a PR gets merged? Thanks.

 

Here's my YAML:

on: pull_request
name: on pull request merge, delete the branch
jobs:
  branchCleanup:
    name: branch cleanup
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: branch cleanup
      uses: jessfraz/branch-cleanup-action@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        NO_BRANCH_DELETED_EXIT_CODE: 0
10 Replies
GitHub Staff
Message 2 of 11

Re: Action runs when PR is created, but not when PR is merged

By default a workflow is run when a PR is opened, synchronized or reopened to better optimize for CI workflows.  If you want to run when the PR is merged you can specify that as follows.

 

on:
  pull_request:
    types: [merged]

Since events are not really individual events but are a set of events that could occur on a givne resources (at lest mostly).  Using the types: field you can filter against the action element in the payload.

Copilot Lvl 2
Message 3 of 11

Re: Action runs when PR is created, but not when PR is merged

Thanks for your reply. I adjusted my `.github/workflows/pull_request.yml` file as you suggested, but it still didn't run upon merging a PR. Any further suggestion or insight?

 

on:
  pull_request:
    types: [merged]
name: on pull request merge, delete the branch
jobs:
  branchCleanup:
    name: branch cleanup
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: branch cleanup
      uses: jessfraz/branch-cleanup-action@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        NO_BRANCH_DELETED_EXIT_CODE: 0
GitHub Staff cdb
GitHub Staff
Message 4 of 11

Re: Action runs when PR is created, but not when PR is merged

@jrobison-sb  - @talldan was exactly right, it should be `closed`, not `merged`.

 

However, even that's not going to work right now as you've uncovered a bug in the system where actions aren't triggering on a closed PR even when they should be (using this exact setup). I've been able to recreate it and I have a fix in the works. I'll report back here when I have something deployed and working!

 

(btw, I'm an engineer on the Actions team, not sure if my profile says that)

Copilot Lvl 3
Message 5 of 11

Re: Action runs when PR is created, but not when PR is merged

Thanks @cdb, that fix and the `types` option would make us very happy :)

Solution
GitHub Staff cdb
GitHub Staff
Message 6 of 11

Re: Action runs when PR is created, but not when PR is merged

Awesome @talldan, good to know! Fixing things makes me happy too :) 

 

@jrobison-sb  The immediate bug is deployed and working now. It uncovered another issue which I'm going to work on, but the workaround is to simply remove the following line completely:

- uses: actions/checkout@master 

 

It's not working right now in this use case (something we have to fix on our side), but for this specific action you don't actually have to checkout your code so removing it should get things running I believe!

Copilot Lvl 2
Message 7 of 11

Re: Action runs when PR is created, but not when PR is merged

@ cbd Thanks for identifying this, and thanks for the super quick turn around time on the fix.

 

It's working again as expected. 

Copilot Lvl 2
Message 8 of 11

Re: Action runs when PR is created, but not when PR is merged

And what about checkout? Is there any workaround if I need to get the code from the merged branch for the pipeline? 

Copilot Lvl 2
Message 9 of 11

Re: Action runs when PR is created, but not when PR is merged

are there any updates?

 

I'm just trying excute workflow when PR merged.

But it doesn't kicked from platform...

 

https://github.com/vvakame/til/blob/master/.github/workflows/pr-to-blog.yml

 

Copilot Lvl 3
Message 10 of 11

Re: Action runs when PR is created, but not when PR is merged


@cdb wrote:

@jrobison-sb  - @talldan was exactly right, it should be `closed`, not `merged`.


Would it be possible to create a `merged` type? I'm building a pipeline that automatically creates a release when a release/* branch is merged into master. But closed (canceled) pull requests will also trigger this build.