#!/bin/bash

# Make sure we are on the release branch
branch=$( git symbolic-ref HEAD )
branch=${branch#refs/heads/}
echo "on branch: $branch"
if [ "${branch#master}" = "$branch" ]; then
    # we are not on the master branch (release branch)
    echo "not on the release branch ($branch)"
    exit
fi

# Get the date in YYYYMMDD format
date=$( date +"%Y%m%d" )

# See if we have already tagged a releas today. If so what number are we.
count=$( git tag -l "v${date}*" | wc -l | perl -pe's/\s//g' )

# Create the tag and strip off ".0" if this is the first release today
tag="v${date}.$count"
tag=${tag%.0}

# Go ahead and do the tagging
echo "Tagging release with $tag"
git tag -a -m "Autogenerated tag. New version deployed." "$tag"
