From 1277cf92b2e1893f5a986b9d897ed27f5d8cb574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Wed, 12 Sep 2012 20:44:37 +0200 Subject: [PATCH] refactor ci scripts --- .rvmrc | 9 ++---- .travis.yml | 12 ++++---- config/database.yml.example | 18 ++++++----- lib/tasks/ci.rake | 51 ++++++-------------------------- script/ci/before.sh | 32 -------------------- script/ci/before_install.sh | 15 ++-------- script/ci/build.sh | 13 ++++++++ script/ci/xvfb | 28 ------------------ script/env/ensure_right_rubygems | 3 ++ script/env/ruby_env | 3 ++ 10 files changed, 49 insertions(+), 135 deletions(-) delete mode 100755 script/ci/before.sh create mode 100755 script/ci/build.sh delete mode 100755 script/ci/xvfb create mode 100644 script/env/ensure_right_rubygems create mode 100644 script/env/ruby_env diff --git a/.rvmrc b/.rvmrc index 5bff212ea..59800542f 100644 --- a/.rvmrc +++ b/.rvmrc @@ -1,8 +1,6 @@ #!/bin/bash -rubygems_version="1.8.24" -ruby_version="1.9.3-p194" -gemset="diaspora" +source ./script/env/ruby_env if [ -e '.rvmrc.local' ]; then source .rvmrc.local; @@ -18,7 +16,4 @@ else fi fi - -if [ "$(gem --version)" != "$rubygems_version" ]; then - rvm rubygems "$rubygems_version" -fi +source ./script/env/ensure_right_rubygems diff --git a/.travis.yml b/.travis.yml index 6303726b7..a7245c27a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,27 +1,25 @@ branches: only: - 'master' - - 'develop' - + language: ruby rvm: - 1.9.3 + env: - DB=postgres BUILD_TYPE=other - DB=mysql BUILD_TYPE=other - DB=postgres BUILD_TYPE=cucumber - DB=mysql BUILD_TYPE=cucumber -before_install: - - "./script/ci/before_install.sh" bundler_args: "--without development production heroku" -before_script: "./script/ci/before.sh" -script: "bundle exec rake travis" +before_install: "./script/ci/before_install.sh" +script: "./script/ci/build.sh" notifications: irc: channels: - - 'irc.freenode.org:6667#diaspora-dev' + - "irc.freenode.org:6667#diaspora-dev" diff --git a/config/database.yml.example b/config/database.yml.example index 858d998a7..89b8f28cd 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -16,20 +16,24 @@ postgres: &postgres password: encoding: unicode -# You can ignore this -postgres_travis: &postgres_travis - adapter: postgresql - username: postgres - # Comment the the mysql line and uncomment the postgres line # if you want to use postgres -common: &common +choose: &choose # Choose one of the following <<: *mysql #<<: *postgres - + +################################################## +#### CONFIGURE ABOVE ############################# +################################################## # Normally you don't need to touch anything here + +postgres_travis: &postgres_travis + adapter: postgresql + username: postgres +common: &common + <<: *choose development: <<: *common database: diaspora_development diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 882690f66..5bfd81970 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -1,45 +1,12 @@ namespace :ci do - - desc "Run tests in the cloud. ZOMG!" - task :travis do - if ENV['BUILD_TYPE'] == 'cucumber' - puts "Running cucumber features..." - system("export DISPLAY=:99.0 && bundle exec rake cucumber") - raise "Cucumber failed!" unless $?.exitstatus == 0 - else - ["rake generate_fixtures", "rake spec"].each do |cmd| - puts "Running bundle exec #{cmd}..." - system("bundle exec #{cmd}") - raise "#{cmd} failed!" unless $?.exitstatus == 0 - end - ["rake jasmine:ci"].each do |cmd| - puts "Running bundle exec #{cmd}..." - system("export DISPLAY=:99.0 && GROUP=oauth bundle exec #{cmd}") - raise "#{cmd} failed!" unless $?.exitstatus == 0 - end - end - end - - desc "Run tests that can't run on travis" - task :hard_things => [:environment, :'ci:migrate'] do - puts "Starting virtual display..." - `sh -e /etc/init.d/xvfb start` - puts "Starting specs..." - system('export DISPLAY=:99.0 && CI=true bundle exec rake cucumber') - exit_status = $?.exitstatus - puts "Stopping virtual display..." - `sh -e /etc/init.d/xvfb stop` - puts "Cleaning up..." - FileUtils.rm_rf(Rails.root.join('public', 'uploads', 'images')) - FileUtils.rm_rf(Rails.root.join('public', 'uploads', 'tmp')) - raise "tests failed!" unless exit_status == 0 - puts "All tests passed!" - end - - task :migrate => ['db:drop', 'db:create', 'db:schema:load'] do - system('bundle exec rake db:test:prepare') - raise "migration failed!" unless $?.exitstatus == 0 + namespace :travis do + desc "Run everyhting except cucumber" + task :other => [ :prepare_db, :generate_fixtures, :spec, "jasmine:ci" ] + + desc "Run cucumber" + task :cucumber => [ :prepare_db, "rake:cucumber" ] + + desc "Prepare db" + task :prepare_db => [ "db:create", "db:test:load"] end end - -task :travis => "ci:travis" diff --git a/script/ci/before.sh b/script/ci/before.sh deleted file mode 100755 index e447c2432..000000000 --- a/script/ci/before.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -# Install firefox & Xvfb, in preparation for cucumber & jasmine - -#echo "Installing Firefox and Xvfb" -#sudo aptitude --quiet=2 --without-recommends --assume-yes install firefox xvfb -#sudo cp script/ci/xvfb /etc/init.d/xvfb -echo "Start Xvfb" -sh -e /etc/init.d/xvfb start - -# Regenerate css files -#echo "Regenerating CSS files" -#bundle exec sass -q --update public/stylesheets/sass/:public/stylesheets/ - -# setup swapfile -#echo "creating a swapfile" -#sudo dd if=/dev/zero of=swapfile bs=1M count=96 -#sudo mkswap swapfile -#sudo swapon swapfile -#sudo sysctl vm.swappiness=100 - -# Create a database.yml for the right database -echo "Setting up database.yml for $DB" -cp config/database.yml.example config/database.yml -if [ "$DB" = "postgres" ]; then - sed -i 's/*mysql/*postgres_travis/' config/database.yml -fi - -# Set up database -echo "Creating databases for $DB and loading schema" -bundle exec rake db:create --trace -bundle exec rake db:schema:load --trace diff --git a/script/ci/before_install.sh b/script/ci/before_install.sh index 859cebf9c..8d49a3ced 100755 --- a/script/ci/before_install.sh +++ b/script/ci/before_install.sh @@ -1,15 +1,6 @@ #!/bin/bash -# Workaround dependency issues -if ([ "$DB" == "postgres" -a "$TRAVIS_RUBY_VERSION" == "ree" ]); then - echo "Rebuild Gemfile.lock to get rid of diaspora-clients 1.9 dependencies" - bundle update diaspora-client -fi - - # Ensure known RubyGems version -if [ "$(gem --version)" != "1.8.17" ]; then - echo "RubyGems version is $(gem --version). Changing..." - rvm rubygems 1.8.17 - echo "Changed RubyGems version to $(gem --version)." -fi +envdir="$(readlink -e $(dirname $0))/../env" +source "$envdir/ruby_env" +source "$envdir/ensure_right_rubygems" diff --git a/script/ci/build.sh b/script/ci/build.sh new file mode 100755 index 000000000..263199deb --- /dev/null +++ b/script/ci/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + + +# Create a database.yml for the right database +echo "Setting up database.yml for $DB" +cp config/database.yml.example config/database.yml +if [ "$DB" = "postgres" ]; then + sed -i 's/*choose/*postgres_travis/' config/database.yml +fi + +command="bundle exec rake --trace ci:travis:${BUILD_TYPE}" + +exec xvfb-run --auto-servernum --server-num=1 --server-args="-screen 0 1280x1024x8" $command diff --git a/script/ci/xvfb b/script/ci/xvfb deleted file mode 100755 index 97be37b90..000000000 --- a/script/ci/xvfb +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -XVFB=/usr/bin/Xvfb -XVFBARGS=":99 -ac -screen 0 1024x768x16" -PIDFILE=/tmp/cucumber_xvfb_99.pid -case "$1" in - start) - echo -n "Starting virtual X frame buffer: Xvfb" - /sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS - echo "." - ;; - stop) - echo -n "Stopping virtual X frame buffer: Xvfb" - /sbin/start-stop-daemon --stop --quiet --pidfile $PIDFILE - rm -f $PIDFILE - echo "." - ;; - restart) - $0 stop - $0 start - ;; - *) - echo "Usage: /etc/init.d/xvfb {start|stop|restart}" - exit 1 -esac -exit 0 \ No newline at end of file diff --git a/script/env/ensure_right_rubygems b/script/env/ensure_right_rubygems new file mode 100644 index 000000000..ae7967217 --- /dev/null +++ b/script/env/ensure_right_rubygems @@ -0,0 +1,3 @@ +if [ "$(gem --version)" != "$rubygems_version" ]; then + rvm rubygems "$rubygems_version" +fi diff --git a/script/env/ruby_env b/script/env/ruby_env new file mode 100644 index 000000000..40ce85acc --- /dev/null +++ b/script/env/ruby_env @@ -0,0 +1,3 @@ +rubygems_version="1.8.24" +ruby_version="1.9.3-p194" +gemset="diaspora"