Trigger workflow for a pull request and for all subsequent commits in it

I want to run a workflow such that if a pull request has a certain filename pattern (amongst all commits when the pull request was opened or any subsequent commits before it’s merged ), it should run that workflow the moment a file was found matching the pattern.

I thought this would work but it doesn’t run for any commits inside the pull request that don’t have a matching file (which makes sense).

      - '**.md'

In essence, the moment a pull request has a file matching the filetype (whether when it was opened or due to any subsequent commit), it should run that workflow for all commits pushed to that pull request subsequently till it’s merged.

Note: The only other potential alternative I can think of is to only run the workflow when the pull request is about to be merged and give an error if that’s possible.

Note: Another inquiry: is the event pull_request.edited fired when commits are pushed into it?

@raunaqgupta ,

I think you have some misunderstandings about Push event, Push event will be triggered when you directly push commits to a repository branch or push tags to the repository.
If you wants a workflow runs for pull request, in the YAML file of this workflow, you should set it runs on the events that are related to pull request (such as Pull request event and Pull request review event), not Push event.

For example:

    types: [assigned, opened, synchronize, reopened]

    types: [edited, dismissed]

In an opening PR, if you want the subsequent commits pushed to this PR can trigger the workflow, you can set the workflow runs on the activity type  pull_request.synchronize.

    types: [opened, synchronize]

By default, a workflow only runs when a pull_request’s activity type is opened , synchronize , or reopened. So you can just set it like this:

on: pull_request

It equals the below configuration:

    types: [opened, synchronize, reopened]

About the path filters on Pull request event, you need to know:

Every time you push a new commit to the opening PR, the Actions app will read all the modified files in this PR from the first to last. Once at least one modified file matches the path filters to trigger the workflow, the workflow will be triggered.

That means, if in the previous commits have modified files match the path filters, although in a subsequent commit you only modify the files that do not match the path filters, the workflow still will be triggered by the activity type  pull_request.synchronize.

In addition, the activity type  pull_request.edited  will trigger the workflow when the users edit somethings on the PR, such as changes the PR’s title, changes the PR’s description, or some other information displayed on the web page of the PR.

Thanks @brightran!

@raunaqgupta to summarize, you can accomplish your goal by using the opened and synchronize activity types for the pull_request event. The opened type is obvious :grinning: The synchronize type happens whenever a commit is pushed to the PR. I’d also recommend using reopened in case a PR is closed and then later opened again.

Here’s an example:

    types: [opened, synchronize, reopened]
    paths: '**.md'

This workflow will not run if a PR is opened, or pushed to, without any markdown changes. One a markdown change is pushed to the PR, it will run with every subsequent push (even when a particular commit does not contain any markdown files).

1 Like

Thanks for the explanation. I was aware that push would not give me what I needed and Github’s event documentation is pretty sparse in explaining what those sub-events actually mean or when are they fired. I’m talking about this particular page: Is there any other page which I have clearly been unable to find where the sub-events (especially synchronize ) are clearly explained?

Anyway, synchronize is exactly what I need. Cheers.