githubgithub-actions

How to configure GitHub Actions to trigger create and push events exclusively for branch creation and future updates?


I have this condition on my workflow:

on:
  push:
    branches:
      - '**'
  create:
    branches:
      - 'release/[0-9]+.[0-9]+'

When I create a branch named something like release/1.2 I want only one pipeline triggered with create event, and future pushes to this branch will trigger with push.
Basically push and create should be exclusive like so:

event_name=create workflow event_name=push workflow
Branch created V X
Push to existing branch X V

I do not want to put conditions on jobs, I need the workflow to not even start.
Is this possible?

Thanks.


Solution

  • I ended up having only "push" event

    on:
      push:
        branches:
          - '**'
    

    And whenever I need to know if it is a branch creation within my pipeline I use github.event.created from the context.

    For example here is a custom title for each scenario:

    run-name: >
      ${{ 
      startsWith(github.ref_name, 'release/') && github.event.created && 'Create Release' ||
      startsWith(github.ref_name, 'release/') && 'Hotfix' ||
      'Push' 
      }}
    

    First one is for release, second for Hotfix and third for push to any other branch.