Have a new workflow run from a PR (none main branch) before committing into main branch possible?


I’d like to test a workflow in a PR, but from what I understand it only shows and runs if committed to the “main branch”.

Is there a way to have new workflows show and run in the PR stage?

Just to be clear, a new workflow in .github/workflows/some-workflow.yml, when committed in a new PR, it won’t show up in the actions and I’d like to have it and run it before committing to the main branch.

Thank you!

You can trigger off of a pull request event in your workflow file:



Thanks for looking!

But I should have worded it differently.

I’m looking to have the workflow peer-reviewed before integrating it into the main branch. This means that the workflow is not yet available or merged with the main branch. Because it is not yet available, displayed, showing in the Github actions, I won’t be able to trigger it: manually, by PR, etc.

I believe that Github does not yet support running workflows that only exist in a none main branch. Am I correct?

Example use-case:

  • Create a new branch for a new workflow
  • Create a new workflow under .github/foobar.yaml
  • Commit the file and changes for foobar.yaml
  • Push the branch to Github
  • Create a new PR for the branch against the main branch (or the same, in which the workflow should be triggered)
  • Finally check actions, where the workflow won’t be available, or shown

cc @mickeygousset

It depends on the event type. There are certain event types for which the workflow file must be on the default branch (e.g. schedule), but events associated with a specific branch (e.g. push or pull_request) should work on other branches.

Check GITHUB_REF for different events in Events that trigger workflows - GitHub Docs. :slightly_smiling_face:

1 Like

Thanks for the support!

If the PR holding a new workflow hasn’t yet been approved and merged to the “main” branch, is it expected to show in the actions?

Here’s an example, which is not showing (the workflow yaml only exists in the pending PR):

name: Foobar

    branches: [ main ]


    runs-on: ubuntu-latest


My expectation was that at least I could trigger it manually, as you see the workflow_dispatch, or at least have it display in the actions sidebar. But afaik, it’ll only show once I merge into the main branch.

My apologies, just found that I have the paths, in which the changes at the moment do not full-fill as I’m only working in workflow.

By removing it, the action does show as expected!

1 Like

for workflow_dispatch, you HAVE to have a version of the file in the main branch.

But workflow_dispatch will only run the workflow version that’s checked into the main branch, right?

Ahhh, see that is where things get interesting. To initially make it show up on the Actions tab, and so that you can trigger it manually, it has to be checked in to the main branch.

BUT, when you trigger it, you can pick which branch to run it against. The only caveat is that the workflow file (or a version of it) also has to exist IN THAT BRANCH.

1 Like

ok, got it. thanks.

but for repository_dispatch, the workflow that runs must be in the default branch, right? if not, how can a workflow in a non-default branch be triggered by a repository_dispatch?

That I don’t know I’d have to test it and see. The docs don’t say. Logically it makes sense that yes it would have to be on the main branch for repository_dispatch to work

As far as I can tell with my limited experience with repository_dispatch, it only runs workflows on the default/main branch when triggered by a push on a non-default branch. Would love to be proven wrong. :slight_smile:

This is what I’d love:

push to dev branch -> trigger and run workflow on dev branch

I was struggling with this too. I followed what I picked up from this thread and did the following:

  1. Make a new workflow with a very incomplete set of actions. Just a skeleton basically.
  2. Add the workflow_dispatch to the config so I can trigger it manually
  3. Commit the new workflow to a branch
  4. Open a pull request for that new branch
  5. Merge it into the default branch (main) (even though it’s not functional)
  6. Now you can access the action from the Actions tab on the repo
  7. You can run it against a specific branch.
1 Like