Last active
December 15, 2015 07:18
-
-
Save pboksz/5221997 to your computer and use it in GitHub Desktop.
A little script to upgrade rails from version to version for a project that has rspec and cucumber specs
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 | |
function checkParams() { | |
if [[ ! $1 || ! $2 ]] | |
then | |
echo "use like this: ./upgrade-rails.sh <path-to-rails-project> <rails-version>..." | |
exit 0 | |
fi | |
} | |
function cdToPath() { | |
cd $1 | |
} | |
v20=(2.0.0 2.0.1 2.0.2 2.0.4 2.0.5) | |
v21=(2.1.0 2.1.1 2.1.2) | |
v22=(2.2.2 2.2.3) | |
v23=(2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.3.10 2.3.11 2.3.12 2.3.14 2.3.15 2.3.16 2.3.17 2.3.18) | |
v30=(3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.20) | |
v31=(3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.1.10 3.1.11 3.1.12) | |
v32=(3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.2.10 3.2.11 3.2.12 3.2.13) | |
versions=(${v20[*]} ${v21[*]} ${v22[*]} ${v23[*]} ${v30[*]} ${v31[*]} ${v32[*]}) | |
function containsVersion() { | |
for v in ${versions[*]}; do [[ $1 == ${v} ]] && return 1; done | |
return 0 | |
} | |
function updateFiles() { | |
echo "changing rails to version $1..." | |
sed -i "s/gem 'rails',.*'[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{1,2\}'/gem 'rails', '$1'/g" Gemfile | |
sed -i "s/RAILS_GEM_VERSION = '[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{1,2\}'/RAILS_GEM_VERSION = '$1'/g" config/environment.rb | |
} | |
function runBundle() { | |
echo "running bundler..." | |
bundle update rails | grep " rails" | |
bundle install | grep "Installing" | |
} | |
function runSpecs() { | |
echo "running rspec specs..." | |
bundle exec rspec spec | |
echo "running cucumber specs..." | |
bundle exec cucumber --tag ~@javascript features | |
} | |
function exitScript() { | |
echo "exiting since the input is not a rails version from 2.0.x to 3.2.x..." | |
exit 0 | |
} | |
checkParams $1 $2 | |
cdToPath $1 | |
containsVersion $2 | |
if [[ $? == 1 ]] | |
then | |
updateFiles $2 | |
runBundle | |
runSpecs | |
else | |
exitScript | |
fi | |
unset -f checkParams | |
unset -f cdToPath | |
unset -f containsVersions | |
unset -f updateFiles | |
unset -f runBundle | |
unset -f runSpecs | |
unset -f exitScript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment