Do not run tests on PR merge to master

Is there a way to tell actions not to run my tests.yml file on a PR merge to master? I only care about running tests:

  • When initial PR is Created
  • subsequent commits to an open PR

@dschinkel ,

Once a PR is merged, it will be closed automatically. The activity type ‘closed’ of the pull_request event should work.

In your case, you can reference to the example workflow below to configure yours:

on:
  pull_request:
    types: [opened, synchronize, closed]
    branches:
      - master

jobs:
  build:
  # Some jobs do not have any if statement.
  # They will always be executed in the workflow. For example, 'build' job.

  test:
    if: ${{github.event_name == 'pull_request' && github.event.action != 'closed'}}
  # With this if statement, the 'test' job will only run
  # when the activity type of the PR is not closed.

Of course, you also can remove ‘closed’ from the list of the activity types, so that the workflow will not be triggered every time the PR is closed (manual or merged).

on:
  pull_request:
    types: [opened, synchronize]
    branches:
      - master
1 Like

Thanks. I also had to remove synchronized as well. Now it only runs my CI on PR merges (closed) which is what I’m aiming for.