Search code examples
triggersgithub-actions

Is it possible to trigger a Github workflow only once for a pull request?


With a workflow file like this:

on: [push, pull_request]

runs are triggered for each single commit in a pull request.

Is it possible to only trigger once, for the pull request (including all commits) as a whole?

I just got literally hundreds of runs for a bigger pull request...


Solution

  • From the Webhook events page:

    By default, all activity types trigger a workflow to run. You can limit your workflow runs to specific activity types using the types keyword. For more information, see "Workflow syntax for GitHub Actions."


    The pull_request event has many activities associated with it that trigger any actions that listen for that event. Activities such as synchronize or edited might contribute to the reasons why your action is being called whenever the pull request is modified.

    You can limit the activity types using the types list. For example:

    on:
      pull_request:
        types: [opened]
    

    In the above case, the action will only run when a pull request is opened. You can add more to this list as you see fit.