This is hard because a tag technically has nothing to do with branches, it’s a pointer to a commit. When using a tag, there can be no branch in a way, or multiple branches if a merge occurred at some point.
Personally I would have the script based everything off the tag. A release tag that follows a certain regex pattern for example would be considered “production”. Unless you’re doing continuous deployment in which case I’d ignore tags and just deploy master or a separate “production” branch.