Skip to content

Instantly share code, notes, and snippets.

@newtriks
Created October 18, 2012 12:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newtriks/3911580 to your computer and use it in GitHub Desktop.
Save newtriks/3911580 to your computer and use it in GitHub Desktop.
Versioning a Rails app with Git and Heroku
#!/bin/bash
REVISION=$(heroku config:get REVISION)
echo " info: heroku REVISION: $REVISION"
function version_release
{
echo -e " info: writing: '\$tagged_release_version = \"$1\"' to version_helper.rb"
echo -e "\$tagged_release_version = \"$1\"" > config/initializers/version_helper.rb
git add config/initializers/version_helper.rb
git commit -am "Updating version_helper with latest tagged version $1"
echo " info: deployed version $REVISION is not yet tagged; tagging now as $1"
git tag -a $1 -m "Deployed $(LANG=en_GB.UTF-8; date '+%d %B %Y')."
echo " info: updating heroku REVISION to: $(git describe)"
heroku config:add REVISION=$(git describe)
}
if [ ! $(git describe 2> /dev/null) ]; then
if [ "$#" -ne 3 ]; then
echo " error: no previous git tags and no semantic version parameters provided e.g. 0 0 1" >&2
return 1
fi
echo " warning: no previous git tags, creating first version using params: $1.$2.$3"
version_release "$1.$2.$3"
elif [ ! $(git describe --exact-match REVISION 2> /dev/null) ]; then
version_release $(git describe $(git rev-list --tags --max-count=1) | awk -F . '{ printf "%d.%d.%d", $1, $2, $3 + 1}')
else
echo " info: local git tag and remote REVISION match, exit versioning"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment