Condition to check tag name and branch the tag was created from


I’m trying to check if a specific tag pattern was created from a particular branch. I’m wondering if the condition below would work for that case?

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

Please let me know if there is a different way to do the above check. Thanks!

Unfortunately, no, only one of those can be true.  The ref is either the tag _or_ the branch.

Git does not maintain a history that corresponds tags and branches.  Although a tag and a branch could be pointing to the same commit, there’s no notion that a tag was “created from” that branch.  That these are the same could be coincidental, and there could be multiple tags and branches all pointing to the same commit, which you could not reason about.

If you have a naming pattern that will allow you to deduce this (and from your example, it seems like you may) then this may help with the matching.  If you create tags named refs/tags/staging-release-* from your staging branch, then you can indeed say:

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

Hi @ethomson ,

Thanks for the response! Actually, I’m trying to check if a specific tagpattern was created from a specific branch. It looks like when I 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.