Which branch should workflow files be located on for GitHub Actions to execute them?

Viewed 3918

I have created on my main branch with

on:  
  push:
      branches: [ test ]

I have noticed, that while I can trigger it manually, and it will work, it will not actually trigger if I push to test. For that, I needed to create that same action file on test. Now, it seems like I don't even need to have the action on the main branch, is that correct?

So why does even the option so specify the branch that it should trigger on exist? It only triggers on the branches the file exists anyway. That said, I found it frustrating that I have to merge my one file from main to my test branch, is there a way to trigger the action automatically on push even if I do not have it on my test branch, only on main?

1 Answers

No, it's not possible. The order of operations in a workflow run triggered by push or pull request is described in the reference documentation:

  1. An event occurs on your repository. The event has an associated commit SHA and Git ref.

  2. GitHub searches the .github/workflows directory in your repository for workflow files that are present in the associated commit SHA or Git ref of the event.

  3. A workflow run is triggered for any workflows that have on: values that match the triggering event. Some events also require the workflow file to be present on the default branch of the repository in order to run.

Related