Action workflow runs at any push no matter if is not the right branch

Here is the only action workflow file my project has:

name: CI

on:
  push:
    branches:
      - master
  pull_request:

env:
  APP_ENV: test

#jobs:
#  build:
#
#    runs-on: ubuntu-latest
#
#    steps:
#      - uses: actions/checkout@v1
#
#      - name: Install dependencies
#        run: make composer-install
#
#      - name: Start all the environment
#        run: make start
#
#      - name: Wait for the environment to get up
#        run: |
#          while ! make ping-mysql &>/dev/null; do
#              echo "Waiting for database connection..."
#              sleep 3
#          done
##          while ! make ping-localstack &>/dev/null; do
##              echo "Waiting for aws s3..."
##              sleep 2
##          done
#
#      - name: Run the tests
#        run: make test

This previous workflow is executed at any push I perform on a branch different that master.
But why?

1 Like

I’m seeing this same behavior

It looks like, while you are specifying that push should only run on the master branch, pull_request is running for any branch. You would want to configure the branches key in a similar way there. See:

Further to this, from Events that trigger workflows - GitHub Docs

Note: By default, a workflow only runs when a pull_request 's activity type is opened , synchronize , or reopened . To trigger workflows for more activity types, use the types keyword.

From Add in definition of terms like "synchronize" for Github Action Activity types · Issue #2257 · github/docs · GitHub

A synchronize pull_request event it’s only triggered when the pull request’s tracking branch is synchronized with the source branch for the pull request, and that happens when the source branch is updated.

So every time someone pushes to the source branch of the pull request, the workflow will kick off again.

Based on that even after the changes mentioned above, I believe you are likely going to see the pull_request part of this trigger even when the ‘source branch’ is updated, and not just when a PR’s branch is updated (i’m not 100% on this, as the documentation isn’t particularly clear)

Choosing the specific event types you want to react to may be a better choice here:

1 Like

Thank you very much @0xdevalias, i’ll give it (types) a try