Skip to content

Instantly share code, notes, and snippets.

@gaqzi
Last active August 29, 2015 14:10
Show Gist options
  • Save gaqzi/3dfd50efd5821b4b82e2 to your computer and use it in GitHub Desktop.
Save gaqzi/3dfd50efd5821b4b82e2 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Usage: bump-it.sh [major|minor|patch|nobump]
# Default: patch
#
# This script uses the gem `bump` to do most of the heavy lifting:
# https://rubygems.org/gems/bump
#
# The updating of the Gemfile is really dump, it expects the gem to be
# specified in the following format exactly: gem 'gem-name', 'version-number'
# If that isn't specified it won't get changed.
#
# The projects are assumed to live adjacent to the current project.
# E.g.:
# /my-shared-styles
# /project1
# /project2
projects="project1 project2 project3"
gem_name="project_styles"
if-error() {
local exit_code=$1
local msg=${@:2}
if [ $exit_code -ne 0 ] ; then
echo $msg
exit $exit_code
fi
}
if [ $# -eq 0 ] ; then
bump patch --tag
elif [ "$1" != "nobump" ] ; then
bump ${$1} --tag
fi
if-error $? "Error bumping version ${1}"
rake build # Build set to always clear out the build folder before pushing
if-error $? "Error building gem"
gem="$(pwd)/build/${gem_name}*.gem"
curren_version=$(bump current | sed 's/Current version: //')
set -x
for project in $projects ; do
cp $gem ../$project/vendor/cache && \
sed -i'' "s|^(gem '${gem_name}', '.*')$|gem '${gem_name}', '${current_version}'|" ../$project/Gemfile &&
(cd ../$project && \
bundle --local && \
git add Gemfile* vendor/cache/${gem_name}*.gem)
if-error $? "Error updating gem"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment