Bug (?) GitHub Actions run on Pull Request from main branch

In a GitHub Actions file that is set to run like this

on:
  push:
    branches:
      - branch_name

The action will run when you create a pull request from branch_name to another branch.
This issue could be very bad when someone has a fork of your repository and creates a pull request from branch_name to their own fork, which would trigger the Action despite it not being a push to branch_name on origin.

I hope this is not a duplicate, I couldn’t find any reports of this issue when attempting to search for it here and on Google.

@NatsumiHB ,

According to the configurations, this workflow only can be triggered when pushing new commits to the branch_name.
When you open a PR to merge commits from branch_name into another branch, the branch_name is the head branch (source branch) of the PR. There is a point you need to understand:

  • All the jobs in the workflow run that triggered by the latest commit push on the head branch will be listed as the checks of the PR.
    Note: it just fetches jobs from the existing workflow run that triggered by the push event on the head branch, it does not trigger new workflow run on the head branch.

If the PR indeed triggers a new workflow run on the head branch, please share your repository with us so that we can check more detailed configurations of your workflows to analyze the root cause.

That makes total sense to me and I believe that’s what happened. I probably thought that it ran the workflow again because it didn’t finish yet but in reality it just showed the progress.

@NatsumiHB ,

So, you just have a misunderstanding for the checks listed on the PR, and my above explanation can answer your doubt, right?

In addition, generally the following things will be listed as the checks of the PR:

  1. The jobs in the workflows triggered by the events related to pull request.

  2. As mentioned above, the jobs in the workflows triggered by push event on the head branch.

  3. Some check runs created from integrated GitHub Apps for the PR. For example, an Azure Pipeline triggered by the PR.

If my above answer is helpful to you, maybe you can mark it as the solution of this topic, so that other people who have the similar questions can notice it when they are looking for an answer.

If you have any other questions about this topic, feel free to tell us. Thanks.

Yep, that’s exactly what happened! I marked your reply as the answer.

And thank you for your very good explanation!

You’re welcome, @NatsumiHB .