diff --git a/.travis.yml b/.travis.yml index 16fcf8b..ef01664 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,12 @@ language: c os: [linux, osx] osx_image: mavericks +env: + global: + - SRC_REPO=$TRAVIS_BUILD_DIR + - GVM_NO_GIT_BAK=1 + - GVM_NO_UPDATE_PROFILE=1 before_install: - - "binscripts/gvm-installer $TRAVIS_COMMIT $TRAVIS_BUILD_DIR/tmp" +- binscripts/gvm-installer $TRAVIS_COMMIT $TRAVIS_BUILD_DIR/tmp install: gem install tf -v '>=0.4.1' -script: source $TRAVIS_BUILD_DIR/tmp/gvm/scripts/gvm; tf --text tests/*.sh +script: source $TRAVIS_BUILD_DIR/tmp/gvm/scripts/gvm; rake default scenario diff --git a/Rakefile b/Rakefile index 009bba1..40b6fc7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,27 +1,41 @@ require 'tmpdir' +def root_path + File.expand_path('../.', __FILE__) +end + +def commit + @commit ||= ( + ENV['TRAVIS_COMMIT'] || `git rev-parse --abbrev-ref HEAD`.chomp + ) +end + task :default do - root_path = File.expand_path "../.", __FILE__ - Dir.mktmpdir("gvm-test") do |tmpdir| - puts `binscripts/gvm-installer binary_default #{tmpdir}` - pid = fork do - exec("bash -c 'source #{tmpdir}/gvm/scripts/gvm; tf --text #{tmpdir}/gvm/tests/*.sh'") - end - Process.waitpid(pid) + Dir.mktmpdir('gvm-test') do |tmpdir| + system(<<-EOSH) || fail + bash -c ' + set -e + #{root_path}/binscripts/gvm-installer #{commit} #{tmpdir} + source #{tmpdir}/gvm/scripts/gvm + tf --text #{tmpdir}/gvm/tests/*.sh + ' + EOSH end end task :scenario do - root_path = File.expand_path "../.", __FILE__ Dir["#{root_path}/tests/scenario/*_comment_test.sh"].each do |test| name = File.basename(test) puts "Running scenario #{name}..." - Dir.mktmpdir("gvm-test") do |tmpdir| - install = `binscripts/gvm-installer binary_default #{tmpdir}` - pid = fork do - exec("bash -c 'source #{tmpdir}/gvm/scripts/gvm; tf --text #{tmpdir}/gvm/tests/scenario/#{name}'") - end - Process.waitpid(pid) + Dir.mktmpdir('gvm-test') do |tmpdir| + system(<<-EOSH) || fail + bash -c ' + set -e + #{root_path}/binscripts/gvm-installer #{commit} #{tmpdir} + source #{tmpdir}/gvm/scripts/gvm + tf --text #{tmpdir}/gvm/tests/scenario/#{name} + ' + EOSH end end end diff --git a/binscripts/gvm-installer b/binscripts/gvm-installer index 3a493be..801e8fd 100755 --- a/binscripts/gvm-installer +++ b/binscripts/gvm-installer @@ -60,7 +60,7 @@ SRC_REPO=${SRC_REPO:-https://github.com/moovweb/gvm.git} # Is gvm-installer being called from the origin repo? # If so, skip the clone and source locally! -# This prevents, the CI to break on non-merge commits +# This prevents CI from breaking on non-merge commits. GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) @@ -87,20 +87,22 @@ cd "$GVM_DEST/$GVM_NAME" && git checkout --quiet "$BRANCH" 2> /dev/null || displ popd > /dev/null -mv "$GVM_DEST/$GVM_NAME/.git" "$GVM_DEST/$GVM_NAME/git.bak" +[ -z "$GVM_NO_GIT_BAK" ] && mv "$GVM_DEST/$GVM_NAME/.git" "$GVM_DEST/$GVM_NAME/git.bak" source_line="[[ -s \"${GVM_DEST}/$GVM_NAME/scripts/gvm\" ]] && source \"${GVM_DEST}/$GVM_NAME/scripts/gvm\"" source_file="${GVM_DEST}/$GVM_NAME/scripts/gvm" -if [ -n "$ZSH_NAME" ]; then - update_profile "$HOME/.zshrc" -elif [ "$(uname)" == "Linux" ]; then - update_profile "$HOME/.bashrc" || update_profile "$HOME/.bash_profile" -elif [ "$(uname)" == "Darwin" ]; then - update_profile "$HOME/.profile" || update_profile "$HOME/.bash_profile" +if [ -z "$GVM_NO_UPDATE_PROFILE" ] ; then + if [ -n "$ZSH_NAME" ]; then + update_profile "$HOME/.zshrc" + elif [ "$(uname)" == "Linux" ]; then + update_profile "$HOME/.bashrc" || update_profile "$HOME/.bash_profile" + elif [ "$(uname)" == "Darwin" ]; then + update_profile "$HOME/.profile" || update_profile "$HOME/.bash_profile" + fi fi -if [ "$?" != "0" ]; then +if [ -z "$GVM_NO_UPDATE_PROFILE" ] && [ "$?" != "0" ]; then echo "Unable to locate profile settings file(Something like $HOME/.bashrc or $HOME/.bash_profile)" echo echo " You will have to manually add the following line:"