Created
July 25, 2016 22:24
-
-
Save mikejholly/a66afc4a2476d0e62c3b15510dbc2d5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PARENT=$1 | |
VERSION=$2 | |
BRANCH=feature/core-bump-$VERSION | |
if [[ -z $PARENT || -z $VERSION ]]; then | |
echo "Usage: $0 <dir-with-repos> <core-version>" | |
exit 1 | |
fi | |
if [[ ! -d $PARENT ]]; then | |
echo "$PARENT is not a valid directory" | |
exit 1 | |
fi | |
if [[ ! -d "$PARENT/api" || ! -d "$PARENT/cloud" ]]; then | |
echo "api or cloud not found in $PARENT" | |
exit 1 | |
fi | |
for REPO in cloud api; do | |
cd $PARENT/$REPO | |
echo "Updating core in $REPO..." | |
EXISTS=$(cat Gemfile | grep "gem 'core'" | grep $VERSION) | |
if [[ -n $EXISTS ]]; then | |
echo "$VERSION has already been updated" | |
exit 1 | |
fi | |
git stash > /dev/null && | |
git checkout master > /dev/null 2>&1 && | |
git pull > /dev/null 2>&1 && | |
(git checkout -b $BRANCH master > /dev/null 2>&1 || git checkout $BRANCH > /dev/null 2>&1) && | |
sed -i.new -E "s/^gem 'core', '~> [0-9\.]+'$/gem 'core', '~> $VERSION'/g" Gemfile && | |
mv Gemfile.new Gemfile && | |
echo "Bundling..." && bundle install > /dev/null && | |
git commit -am "Updated core to $VERSION" > /dev/null | |
if [[ $? != 0 ]]; then | |
echo "Something went wrong. Restoring." | |
git stash > /dev/null 2>&1 | |
git checkout master > /dev/null 2>&1 | |
exit 1 | |
fi | |
echo -n "Push update to origin? (y or n): " | |
read PUSHIT | |
if [[ $PUSHIT == "y" ]]; then | |
git push | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment