diff --git a/README.markdown b/README.markdown index 07f786a453..f43856daf6 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,4 @@ -[![Build Status](http://ci.openfood.com.au:8080/buildStatus/icon?job=openfoodweb - tests)](http://ci.openfood.com.au:8080/job/openfoodweb%20-%20tests/) +[![Build status](https://badge.buildkite.com/e18473fffac95ed2735ca75700673bd301cac5cffc64de821a.svg?branch=master)](https://buildkite.com/open-food-foundation/open-food-network) [![Code Climate](https://codeclimate.com/github/openfoodfoundation/openfoodnetwork.png)](https://codeclimate.com/github/openfoodfoundation/openfoodnetwork) # Open Food Network diff --git a/config/ng-test.conf.js b/config/ng-test.conf.js index f87aa3d48a..0456d5eb88 100644 --- a/config/ng-test.conf.js +++ b/config/ng-test.conf.js @@ -42,7 +42,7 @@ module.exports = function(config) { autoWatch: true, - browsers: ['Chrome'], + browsers: ['PhantomJS'], junitReporter: { outputFile: 'log/testacular-unit.xml', diff --git a/script/ci/includes.sh b/script/ci/includes.sh new file mode 100644 index 0000000000..4b07dacfdc --- /dev/null +++ b/script/ci/includes.sh @@ -0,0 +1,13 @@ +function load_environment { + source /var/lib/jenkins/.rvm/environments/ruby-1.9.3-p392 + if [ ! -f config/application.yml ]; then + ln -s application.yml.example config/application.yml + fi +} + +function exit_unless_master_merged { + if [[ `git branch -a --merged origin/$BUILDKITE_BRANCH` != *origin/master* ]]; then + echo "This branch does not have the current master merged. Please merge master and push again." + exit 1 + fi +} diff --git a/script/ci/load_staging_baseline.sh b/script/ci/load_staging_baseline.sh new file mode 100755 index 0000000000..0a59b66d3b --- /dev/null +++ b/script/ci/load_staging_baseline.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Every time staging is deployed, we load a baseline data set before running the new code's +# migrations. This script loads the baseline data set, after first taking a backup of the +# current database. + +set -e + +cd /home/openfoodweb/apps/openfoodweb/current + +echo "Stopping unicorn..." +service unicorn_openfoodweb stop + +echo "Backing up current data..." +mkdir -p db/backup +pg_dump -h localhost -U openfoodweb openfoodweb_production |gzip > db/backup/staging-`date +%Y%m%d%H%M%S`.sql.gz + +echo "Loading baseline data..." +dropdb -U openfoodweb -w openfoodweb_production +createdb -U openfoodweb -w openfoodweb_production +gunzip -c db/backup/staging-baseline.sql.gz |psql -h localhost -U openfoodweb openfoodweb_production + +echo "Restarting unicorn..." +service unicorn_openfoodweb start + +echo "Done!" diff --git a/script/ci/merge_branch_to_master.sh b/script/ci/merge_branch_to_master.sh new file mode 100755 index 0000000000..0bb07b43e2 --- /dev/null +++ b/script/ci/merge_branch_to_master.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e +source ./script/ci/includes.sh + +echo "--- Verifying branch is based on current master" +exit_unless_master_merged + +echo "--- Pushing branch" +echo git push origin $BUILDKITE_COMMIT:master diff --git a/script/push_to_production.sh b/script/ci/push_to_production.sh similarity index 89% rename from script/push_to_production.sh rename to script/ci/push_to_production.sh index 72fa2a5edc..b731b538ca 100755 --- a/script/push_to_production.sh +++ b/script/ci/push_to_production.sh @@ -9,7 +9,7 @@ if [[ "$PROD_TEST" != *production* ]]; then fi echo "--- Saving baseline data for staging" -ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/save_staging_baseline.sh $BUILDKITE_COMMIT" +ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/save_staging_baseline.sh $BUILDKITE_COMMIT" echo "--- Pushing to production" [[ $(git push production $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh new file mode 100755 index 0000000000..582f500a76 --- /dev/null +++ b/script/ci/push_to_staging.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e +source ./script/ci/includes.sh + +# Add staging git remote if required +ST2_TEST=`git remote | grep -s 'staging2' || true` +if [[ "$ST2_TEST" != *staging2* ]]; then + git remote add staging2 openfoodweb@ofn-staging2:apps/openfoodweb/current +fi + +echo "--- Verifying branch is based on current master" +exit_unless_master_merged + +echo "--- Loading baseline data" +ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/load_staging_baseline.sh" + +echo "--- Pushing to staging" +[[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/run_js_tests.sh b/script/ci/run_js_tests.sh new file mode 100755 index 0000000000..91a4be09d9 --- /dev/null +++ b/script/ci/run_js_tests.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +echo "--- Loading environment" +source ./script/ci/includes.sh +load_environment + +echo "--- Verifying branch is based on current master" +exit_unless_master_merged + +echo "--- Bundling" +bundle install + +echo "--- Running tests" +bundle exec rake karma:run diff --git a/script/ci/run_tests.sh b/script/ci/run_tests.sh new file mode 100755 index 0000000000..189875f1e1 --- /dev/null +++ b/script/ci/run_tests.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +echo "--- Loading environment" +source ./script/ci/includes.sh +load_environment + +echo "--- Verifying branch is based on current master" +exit_unless_master_merged + +echo "--- Bundling" +bundle install + +echo "--- Loading test database" +bundle exec rake db:test:load + +echo "--- Running tests" +bundle exec rspec spec --format progress diff --git a/script/save_staging_baseline.sh b/script/ci/save_staging_baseline.sh old mode 100644 new mode 100755 similarity index 100% rename from script/save_staging_baseline.sh rename to script/ci/save_staging_baseline.sh diff --git a/script/delayed_job.sh b/script/delayed_job.sh old mode 100644 new mode 100755 diff --git a/script/prepare_imported_db.rb b/script/prepare_imported_db.rb old mode 100644 new mode 100755 diff --git a/script/push_to_staging.sh b/script/push_to_staging.sh deleted file mode 100755 index e3a16ebb3b..0000000000 --- a/script/push_to_staging.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -e - -ST2_TEST=`git remote | grep -s 'staging2' || true` -if [[ "$ST2_TEST" != *staging2* ]]; then - git remote add staging2 openfoodweb@ofn-staging2:apps/openfoodweb/current -fi - -[[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] diff --git a/script/run_tests.sh b/script/run_tests.sh deleted file mode 100755 index 72d895c04e..0000000000 --- a/script/run_tests.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -set -e - -echo "--- Loading environment" -source /var/lib/jenkins/.rvm/environments/ruby-1.9.3-p392 -if [ ! -f config/application.yml ]; then - ln -s application.yml.example config/application.yml -fi - -echo "--- Bundling" -bundle install - -echo "--- Preparing test database" -bundle exec rake db:test:prepare - -echo "--- Running tests" -bundle exec rspec spec -f d