Action on newly created branch

We delete our QA branch, and recreate it from develop every week.

We currently use:

on:
   push:
     branches:
       - qa

But this does not run when we delete the branch and then push a new one back up.

git push -d origin qa
git push origin qa

Is there anyway I can get QA to build when we re-create it?

@outrunthewolf ,

I tested with the following steps in my repository ( myOrg/myRepo ):
1) Set up a workflow like as below in the master branch.

name: CI-Dev
on:
  push:
    branches:
      - Dev
jobs:
. . .

2) Executed the command “git clone https://github.com/myOrg/myRepo.git” on my local machine to clone the repository from the remote to the local.

3) Executed below commands to generate the Dev branch on the local based on the master branch, then pushed it from local to remote.

git checkout -b Dev
git push origin Dev

4) Checked on the web page of the remote repository, I can see the Dev branch was pushed to the remote successfully, and the workflow CI-Dev was triggered to run.

5) Then, like as you posted, executed below commands on the local to delete the Dev branch from the remote, and re-push the Dev branch from local to remote.

git push -d origin Dev
git push origin Dev

6) Checked on the web page of the remote repository, the Dev branch was re-pushed to the remote successfully, and the workflow CI-Dev also was triggered again to run.

7) If I added paths filter for the push event in the workflow, step 3) and step 5) no longer trigger the workflow:

name: CI-Dev
on:
  push:
    branches:
      - Dev
    paths:
      - '**'
jobs:
. . .

Have you set paths filter for the push event in your workflow?

If the problem still exists, please share your repository with us, so that we can check more detailed configurations in your workflow to analyze the root cause.

1 Like

yes thats right, we do have a paths filter on there!

on:
  push:
    branches:
    - qa
    paths:
    - 'frontend/**'
    - '.github/workflows/build-and-push-frontend-image-qa.yml'

We have frontend and backend folders in the repo which we watch for changes.

Now you’ve mentioned it, I can understand why that might cause an issue. What’s your advice for that? 

@outrunthewolf ,

You can try to add the Create event in your workflow:

on:
push:
branches:
- qa
  create:

The  Create event will trigger the workflow to run on the created branch.  P** ath filters are not evaluated for Create event**.

About why the  p** ath filters** will prevent the workflow from being triggered when create a new branch, I have reported this question to the appropriate engineering team for further investigation and evaluation. If they have any progress, I will notify you in time, and sometimes the appropriate engineers may directly reply you here.

1 Like

You can use on: create and jobs.if:

on: create

jobs:  
job-name:  
if: ${{ (github.event.ref_type == 'branch') && github.event.ref == 'branch-name' }}

Side note: it works for me.

1 Like

Thanks I removed the path filters for now and it operates as expected :+1: