IF condition grouping with tags and branches

Goal:  To run a job for on tag creation from a spefiic branch i.e. validate both tag name and the branch the tag was created from.

Actual Output:  It looks when a have a condition to check for tags i.e. either using on: release or on: tags, it uses master as the branch though the UI shows the branch the tag was created from.


I have a condition (shown below) for a task. The expected behavior is look if the tag matching that pattern was created from a specific branch i.e. 


Ideally, I would like to check if a specific pattern tag was created from a specific branch, but that’s not how the condition below works.

if: startsWith(github.ref, 'refs/tags/staging-release-') && github.ref == 'refs/heads/staging'

It looks like github.ref  gives either the branch or tag ref, but not both. Could someone let me know if there’s a way to check for both the tag and the branch the tag was created from? Thanks!

@andreagriffiths11  Could you check if this is a bug? Please advise!


A workflow run only have one github.ref , a branch ref or a tag ref, this is based on what triggered the workflow run.

I checked from the github context of a workflow run triggered by the push to tag event, we can get the values of   github.ref , github.sha and the default branch, but not the branch where the tag is created from.

I also did not find any other way to get the branch where the tag is created from. Mabybe you can try to find the branch via the github.sha.

So this is structural? I must assume that if a tag is being built, that means it’s on master?

That won’t work, unless you only ever tag commits that are on master. Tags refer to a commit, regardless of what branch(es) that commit is a part of.

If you have tags for different purposes (e.g. releases and some other things) a common approach is to use a specific pattern for each purpose. You could then have the workflow trigger only for tags that match a certain pattern.

So I’d have to use a workflow where I know certain tags will only occur on certain branches?

How does travis do this? On travis I would get both branch and tag.