Skip to content

Instantly share code, notes, and snippets.

@FZambia
Last active December 18, 2015 02:39
Show Gist options
  • Save FZambia/5712693 to your computer and use it in GitHub Desktop.
Save FZambia/5712693 to your computer and use it in GitHub Desktop.
creating tag with version for deploying purposes
function version_tag() {
# Script automatically increments revision in REVISION file.
# Creates tag and pushes it to git origin for deploy.
if [ ! -d .git ]; then
echo "not a git repo"
return
fi
if [ ! -f REVISION ]; then
# create REVISION file with zero version
echo "v0.0.0" > REVISION
fi
rev=$(<REVISION);
new_rev=$(echo "$rev" | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}');
echo "New version is $new_rev";
echo "$new_rev" > REVISION;
git add REVISION
git commit REVISION -m "Revision updated $new_rev";
git tag -a $new_rev -m "Deploy tag $new_rev";
git push origin master;
git push origin $new_rev;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment