Trigger Job on branch created

Hello, community.

I didn’t find documentation on how to trigger an action when I’m creating a branch.

What I want, on creating branch releases/** to trigger publish. Is it possible right now?

When you push newly created branches to Github. You can watch on push events on the branch. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#onpushpull_requestbranchestags

Hi @dmfilipenko ,

You can use the Create event to do this, mode details please reference here:
https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#create-event-create
Note: When you create a new branch, in the branch which the new branch is based on, the YAML file for the Create event workflow must have been existing, otherwise the new branch will not trigger the workflow run.

I tried

on:
  create:
    branches: 
      - releases/*

and


on:
  push:
    types: [created]
    branches:
      - 'releases/**'

But I am still seeing jobs getting triggered by non-release branches.

@shkhaliq,

The create event does not support branch filter and tag filter. Anytime you create a new branch or tag, the workflow will be triggered as long as the workflow runs on create event has been existing on the base ref of the new branch or tag.

The push event does not have any Activity types. The activity type “created” you set on the push event does not exist.

If your projects really need the feature that the create event supports branch filter and tag filter, I recommend that you can directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

In addition, as the workaround, you can use the expression github.ref to get the name of the created branch from the github context, then add an if conditional on each job to skip all the jobs in the workflow according to the branch name.
For example:

on: create
jobs:
  job1:
    if: ${{ contains(github.ref, 'refs/heads/releases/') }}
    . . .
  job2:
    if: ${{ contains(github.ref, 'refs/heads/releases/') }}
    . . .
  jobN:
    if: ${{ contains(github.ref, 'refs/heads/releases/') }}
    . . .