Pull_request event not triggered if push event has already triggered once

Hey all!

TL;DR: When I create a PR which is made up of commits which have already had the push trigger applied to them, it will not re-run the checks using the pull_request trigger. Is there a way to fix this?

I have an action which is run on push if pushing to master or production and also run on pull_request. When I’m trying to merge master --> production, I first create a PR; during the actions run for this PR, I would expect it to push a special “test” environment, but it looks like the actions aren’t triggering at all and it is instead showing the status for the checks run for the last commit in the PR.

Example GH Actions config:

on:
  pull_request:
  push:
    branches:
      - master
      - production

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Set env to DEV
         if: ${{ github.event_name == 'pull_request' && contains(github.base_ref, 'master')
      - name: Set env to TEST
         if: ${{ github.event_name == 'push' && contains(github.ref, 'master')
      - name: Set env to BETA
         if: ${{ github.event_name == 'pull_request' && contains(github.base_ref, 'production')
      - name: Set env to PROD
         if: ${{ github.event_name == 'push' && contains(github.ref, 'production')

The operations I am doing are:

$ git clone ...
$ git checkout master && git fetch  # setup repo
$ git checkout -b release/123  # make a new branch, mostly so I can make a PR to merge --> production
$ git push origin release/123
# create pull request from "release/123" --> production

It seems like it decides not to run the pull_request trigger because the actions have already been run for the latest commit in the PR (they were run previously when pushed to master). Is there a way to get the actions to run when this PR is created without it just reusing the results from the push? This is not a forked repo and if you push changes directly to the branch the pull_request even will trigger as expected.

@jeshua-clipchamp,
According to your description, you executed the following commands in your workflow run:

$ git clone ...
$ git checkout master && git fetch
$ git checkout -b release/123
$ git push origin release/123
# create pull request from "release/123" --> production

Please confirm the following points:

  1. How did you create the PR to merge from release/123 branch into production, manually on the web UI or continue some commands in the workflow run?

  2. If all the operations ( include creating the PR to merge from release/123 branch into production) were execute via the commands in the workflow run, what token were you using to authenticate, the GITHUB_TOKEN or a personal access token you created?

When you use the GITHUB_TOKEN to authenticate in the workflow, you need to know:

Events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.

So you should use a personal access token to authenticate, if you want the workflow can be triggered.

If the personal access token or manual creation of the PR still can’t trigger the workflow, please share more information with us so that we can check more details to analyze the root cause:

  1. Share your repository if possible.
  2. The complete workflow file you are using and other related operations.

Thanks for your response!

The PR is created using the API called from within Python which is authenticated using GITHUB_TOKEN, so it seems like your comment about how events are not triggered when using GITHUB_TOKEN is the solution. I’ll give it a go using the personal access token and will re-comment here if it doesn’t work :slight_smile:

Thanks for the help!