Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 11

Github Actions on push not master

Solved! Go to Solution.

I am trying to figure out what the syntax would be for running a workflow, on push, on any branch but master. I read through some other posts here that looks like folks are having issues with the tag filtering, so maybe this is related?

 

If I use code like:

on:
  push:
    branches:
      - '*'
      - !master

 

This will throw the error:

### ERRORED 14:48:42Z

- Your workflow file was invalid: .github/workflows/main.yml: Unexpected tag '!master'

 

Does anyone know the syntax I am looking for?

 

Thank you in advance!

10 Replies
Copilot Lvl 3
Message 2 of 11

Re: Github Actions on push not master

To answer my own question, the syntax appears to be:

 

on:
  push:
    branches:
      - /refs/heads/*
      - !master

 

Edit: This is not the correct implementation, and only appeared to work since I had different workflow files in the master and test branches.

Solution
Copilot Lvl 2
Message 3 of 11

Re: Github Actions on push not master

I've found that putting quotes around !master works, but I'm not sure if it's technically correct:

 

on:
  push:
    branches:
      - '*'
      - '!master'

 

Copilot Lvl 3
Message 4 of 11

Re: Github Actions on push not master

@arpanlaha @csumpter 

 

We've been using this at the top of our `default.yml` workflow with success.

 

on: 
  push:
    branches:
    - !master
Hope that helps!
 
Edit:
This apparently is no longer working -- or just appeared to work somehow.
 
The good news is that @arpanlaha 's solution works fine for me.
 
 
Copilot Lvl 3
Message 5 of 11

Re: Github Actions on push not master

@arpanlaha @intolerance 

 

@arpanlaha- your solution works perfectly. Thank you so much for helping out! I will flag your code as the solution.

Pilot Lvl 1
Message 6 of 11

Re: Github Actions on push not master

Leading bangs are reserved for custom tags in YAML. So you need to always use explicit strings.

GitHub Staff
Message 7 of 11

Re: Github Actions on push not master

You need quotes when the branch/tag starts with a ! or *. 

Copilot Lvl 3
Message 8 of 11

Re: Github Actions on push not master

Thank you @jeremyepling. I see that docs have been updated on https://help.github.com/en/articles/workflow-syntax-for-github-actions to reflect the same.

Highlighted
Copilot Lvl 3
Message 9 of 11

Re: Github Actions on push not master

on:
  push:
    branches:
      - '*'
      - '!master'

Does not seem to work for me. :(

Copilot Lvl 3
Message 10 of 11

Re: Github Actions on push not master

For anyone where the solution is not working. This happened to me:

 

I was pushing to a branch called 'release/1.0.1' and the wildcard '*' does not seem to work for this naming. You also need to set '*/*' to make this work.

 

As described on https://golang.org/pkg/path/#Match '*' : 

matches any sequence of non-/ characters