Trigger to run only when branch is created?

Hi all,

I am trying to create a workflow that will run only when new branch is created and never in some other case.

I tried this:

on:
  create:
    branches:
    - '*'

and this:

on:
  create:
    branches:
    - 'refs/heads/*'

even this:

on:
  create:
    branches:

It runs when I create new branch. But it runs also when I push new tag, which is not the desired behavior. I am not sure if it’s a bug or I am doing something wrong. It could be related to this https://github.community/t5/GitHub-Actions/Github-Actions-CI-CD-pipeline-branch-gt-master-gt-release-tag/m-p/29924#M116, but @jeremyepling said that it should be fixed last week. Jeremy, could you please confirm if it’s fixed?

Thanks a lot for your help.

1 Like

It is fixed, but this is a different scenario. Have you tried the create event? 

https://help.github.com/en/articles/events-that-trigger-workflows#webhook-events

I am not sure what you mean. I already tried the create trigger as I mentioned in my question. Is there some other trigger setup I should try?

And I know the other issue linked was something different, but I was just hoping that my issue could be fixed as it seemed to be related to event/trigger filtering.

Thanks for being here @eskimag, on create represents both a created branch or tag, and as far as I know defining only one of tags: or branches: will mean the workflow skips events affecting the other type of ref ONLY on push and pull_request events. Is that right @jeremyepling

1 Like

That’s right. You might be able to work around this with an expression that looks for refs/heads vs. refs/tags in the workflow steps. There should be an easier way to do this.

@chrispat FYI

We need to fix the documentation here becuase unexpectedly the following acctually seems to work

# Trigger on the create of a tag
on:
  create:
    ref_type: tag

https://github.com/chrispat/test-action/commit/dd4d1f85b49aa6d34e8926f4ec133ab7d6880262/checks#step:2:6

# Trigger on the create of a branch
on:
  create:
    ref_type: branch

https://github.com/chrispat/test-action/commit/eb322b4832f19f4bf38e00c0f5b4ca4df876ed51/checks#step:2:6
1 Like

Oops, I was a bit too fast. This is not a solution.

For this trigger:

on:
  create:
    ref_type: tag

When I create new branch and push it to github, the workflow runs, which should not happen’.

Is there currently a way to run a workflow on certain branches creation?

I would like to do something like that:

on:
  create:
    branches-ignore:
      - "!pr-*"
    tags-ignore:
      - "*"
2 Likes