Created
March 28, 2014 21:05
-
-
Save ke4roh/9842970 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 | |
set -e | |
[ -e /etc/profile.d/proxy.sh ] && source /etc/profile.d/proxy.sh | |
# Some defaults that may be overridden by command line | |
HEADLESS=false | |
CLEAN=false | |
# Execute getopt | |
ARGS=$(getopt -o hc -l "headless,clean,help" -n "${0}" -- "$@"); | |
echoerr() { echo $* >&2; } | |
usage() { | |
cat <<EOF >&2 | |
USAGE | |
${0} [--headless] [--clean] [dev|qa|stage|prod [[~]@tag ...]] | |
Tags beginning with ~ are excluded. Tags beginning with @ are included. | |
EOF | |
} | |
#Bad arguments | |
if [ $? -ne 0 ]; then | |
echoerr "Invalid arguments" | |
usage; | |
exit 1; | |
fi | |
eval set -- "$ARGS"; | |
while true; do | |
case "$1" in | |
-h|--headless) | |
shift; | |
HEADLESS=true; | |
;; | |
-c|--clean) | |
shift; | |
CLEAN=true; | |
;; | |
--help) | |
shift; | |
echoerr "Help:" | |
usage; | |
exit 1; | |
;; | |
--) | |
shift; | |
break; | |
;; | |
esac | |
done | |
TARGET_ENVIRONMENT="$1" | |
shift | |
while [ $# -gt 0 ] ; do | |
(echo ${1} | egrep -q '^(@|~@)\w+') || (echoerr "Invalid tag: $1" && usage && exit 1); | |
TAGS="${TAGS} --tags ${1}"; | |
shift; | |
done | |
[ $HEADLESS == "true" ] && export HEADLESS | |
# Collect input if needed | |
if [ -z "$TARGET_ENVIRONMENT" ] ; then | |
echo "Environment (dev|qa|stage|prod)?" | |
read TARGET_ENVIRONMENT | |
fi | |
clean() { | |
rm -rf ./junit-results* | |
rm -rf ./cucumber-results*.html | |
rm -f screenshot_*.{html,png} | |
} | |
# Set up Ruby to run | |
[ -x ${HOME}/.rvm/scripts/rvm ] || curl -sSL https://get.rvm.io | bash -s stable | |
echo hello, world | |
set -x | |
source ${HOME}/.rvm/scripts/rvm | |
echo hello again | |
set -x | |
rvm use 2.1.0 || rvm install ruby-2.1.0 | |
(gem list --local | grep -q bundler) || gem install bundler | |
# show the setup for diagnostics | |
rvm info | |
# Run the tests found below the current directory, identified | |
# by the presence of Gemfiles mentioning cucumber | |
for cukePlace in \ | |
$(find . -name Gemfile | xargs grep -H cucumber |\ | |
cut -f1 -d: | xargs -n 1 dirname | sort -u); do | |
pushd $cukePlace | |
[ ${CLEAN} == "true" ] && clean | |
bundle install | |
CUKE_CMD="cucumber \ | |
$(find . -name \*.feature) \ | |
--format pretty \ | |
--format junit \ | |
--out junit-results \ | |
--format html \ | |
--out cucumber-results.html \ | |
--strict \ | |
$TAGS" | |
echo "Running $CUKE_CMD" | |
RH_ENV_NAME="$TARGET_ENVIRONMENT" bundle exec $CUKE_CMD | |
popd | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment