You are here

travis-ci.sh in Open Atrium 7.2

#!/bin/bash

COMMAND=$1
BUILD_TOP=`dirname $TRAVIS_BUILD_DIR`
EXIT_VALUE=0

export PATH="$HOME/.composer/vendor/bin:$PATH"
export DISPLAY=:99.0
export CHROME_SANDBOX=/opt/google/chrome/chrome-sandbox

##
# SCRIPT COMMANDS
##

# system-install
#
# This is meant to setup the server on Travis-CI so that it can run the tests.
#
system_install() {
  # Add the Google Chrome packages.
  header Setting up APT
  wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
  sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
  sudo apt-get update > /dev/null

  # Create a database for our Drupal site.
  mysql -e 'create database drupal;'

  # Install the latest Drush 6.
  header Installing Drush
  composer global require --prefer-source --no-interaction drush/drush:6.*
  drush dl -y drupalorg_drush-7.x-1.x-dev --destination=$HOME/.drush
  drush cc drush

  # Build Codebase
  mkdir profiles
  mv openatrium profiles/
  mkdir drupal
  mv profiles drupal/

  # Build the current branch.
  header Building Open Atrium from current branch
  cd drupal
  pwd
  drush make --yes profiles/openatrium/drupal-org-core.make --prepare-install
  drush make --yes profiles/openatrium/scripts/oa-drush6-dev.make --no-core --contrib-destination=profiles/openatrium
  drush dl panopoly_demo-7.x-1.x-dev
  mkdir sites/default/files
  mkdir sites/default/files/private
  mkdir sites/default/files/temp

  # Build Behat dependencies
  header Installing Behat
  cd profiles/openatrium/modules/panopoly/panopoly_test/tests
  composer install --prefer-source --no-interaction
  cd ../../../../../../../

  # Verify that all the .make files will work on Drupal.org.
  header Verifying .make file
  #verify the release makefile instead
  #drush verify-makefile drupal/profiles/openatrium/drupal-org-dev.make
  drush verify-makefile drupal/profiles/openatrium/drupal-org.make
  find drupal/profiles/openatrium/modules -name \*.make -print0 | xargs -0 -n1 drush verify-makefile

  # Download an old version to test upgrading from.
  if [[ "$UPGRADE" != none ]]; then
    header Downloading Open Atrium $UPGRADE
    drush dl openatrium-$UPGRADE
  fi

  # Setup files
  sudo chmod -R 777 drupal/sites/all

  # Setup display for Selenium
  header Starting X
  sh -e /etc/init.d/xvfb start
  sleep 5

  # Get Chrome and ChromeDriver
  header Installing Google Chrome
  sudo apt-get install google-chrome-stable
  wget http://chromedriver.storage.googleapis.com/2.9/chromedriver_linux64.zip
  unzip -a chromedriver_linux64.zip

  # Insane hack from jsdevel:
  #   https://github.com/jsdevel/travis-debugging/blob/master/shim.bash
  # This allows chrome-sandbox to work in side of OpenVZ, because I can't
  # figure out how to start chrome with --no-sandbox.
  sudo rm -f $CHROME_SANDBOX
  sudo wget https://googledrive.com/host/0B5VlNZ_Rvdw6NTJoZDBSVy1ZdkE -O $CHROME_SANDBOX
  sudo chown root:root $CHROME_SANDBOX
  sudo chmod 4755 $CHROME_SANDBOX
  sudo md5sum $CHROME_SANDBOX

  # Get Selenium
  header Downloading Selenium
  wget http://selenium-release.storage.googleapis.com/2.41/selenium-server-standalone-2.41.0.jar
 
  # Disable sendmail
  echo sendmail_path=`which true` >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
}

# before_tests
#
# Setup Drupal to run the tests.
#
before_tests() {
  UPGRADE_DEMO_VERSION=`echo $UPGRADE | sed -e s/^7.x-//`

  # Do the site install (either the current revision or old for the upgrade).
  header Installing Drupal
  if [[ "$UPGRADE" == none ]]; then
    cd drupal
  else
    cd openatrium-$UPGRADE
    drush dl panopoly_demo-$UPGRADE_DEMO_VERSION
  fi
  drush si openatrium --db-url=mysql://root:@127.0.0.1/drupal --account-name=admin --account-pass=admin --site-mail=admin@example.com --site-name="Open Atrium" --yes
  drush dis -y dblog
  drush vset -y file_private_path "sites/default/files/private"
  drush vset -y file_temporary_path "sites/default/files/temp"

  # Switch to the Panopoly platform built from Git (if we aren't there already).
  cd ../drupal

  # If we're an upgrade test, run the upgrade process.
  if [[ "$UPGRADE" != none ]]; then
    header Upgrading to latest version
    cp -a ../openatrium-$UPGRADE/sites/default/* sites/default/ && drush updb --yes
  fi
  drush cc all

  # Our tests depend on panopoly_demo.
  drush en -y panopoly_demo

  # Our tests depend on panopoly_test.
  drush en -y panopoly_test

  # Run the webserver
  header Starting webserver
  drush runserver --server=builtin 8888 > /dev/null 2>&1 &
  echo $! > /tmp/web-server-pid
  wait_for_port 8888
  sleep 3

  cd ..

  # Run the selenium server
  header Starting selenium
  java -jar selenium-server-standalone-2.41.0.jar -Dwebdriver.chrome.driver=`pwd`/chromedriver > /dev/null 2>&1 &
  echo $! > /tmp/selenium-server-pid
  wait_for_port 4444

  # Prime the site to prevent timeouts when the tests run
  wget -q -O - http://localhost:8888
  sleep 3
}

# before_tests
#
# Run the tests.
#
run_tests() {
  header Running tests

  # Make the Travis tests repos agnostic by injecting drupal_root with BEHAT_PARAMS
  export BEHAT_PARAMS="extensions[Drupal\\DrupalExtension\\Extension][drupal][drupal_root]=$BUILD_TOP/drupal"

  # cd drupal/profiles/openatrium/modules/contrib/oa_test/tests
  cd drupal/profiles/openatrium/modules/panopoly/panopoly_test/tests

  # If this isn't an upgrade, we test if any features are overridden.
  #if [[ "$UPGRADE" == none ]]; then
  #  run_test ../../../../scripts/check-overridden.sh
  #fi

  # First, run all the tests in Firefox.
  run_test ./bin/behat --config behat.travis.yml

  # Then run some Chrome-only tests.
  run_test ./bin/behat --config behat.travis.yml -p chrome
}

# after_tests
#
# Clean up after the tests.
#
after_tests() {
  header Cleaning up after tests

  WEB_SERVER_PID=`cat /tmp/webserver-server-pid`
  SELENIUM_SERVER_PID=`cat /tmp/selenium-server-pid`

  # Stop the servers we started
  kill $WEB_SERVER_PID
  kill $SELENIUM_SERVER_PID
}

##
# UTILITY FUNCTIONS:
##

# Prints a message about the section of the script.
header() {
  set +xv
  echo
  echo "** $@"
  echo
  set -xv
}

# Sets the exit level to error.
set_error() {
  EXIT_VALUE=1
}

# Runs a command and sets an error if it fails.
run_test() {
  if ! $@; then
    set_error
  fi
}

# Runs a command showing all the lines executed
run_command() {
  set -xv
  $@
  set +xv
}

# Wait for a specific port to respond to connections.
wait_for_port() {
  local port=$1
  while echo | telnet localhost $port 2>&1 | grep -qe 'Connection refused'; do
    echo "Connection refused on port $port. Waiting 5 seconds..."
    sleep 5
  done
}

##
# SCRIPT MAIN:
##

# Capture all errors and set our overall exit value.
trap 'set_error' ERR

# We want to always start from the same directory:
cd $BUILD_TOP

case $COMMAND in
  system-install)
    run_command system_install
    ;;

  drupal-install)
    run_command drupal_install
    ;;

  before-tests)
    run_command before_tests
    ;;

  run-tests)
    run_command run_tests
    ;;

  after-tests)
    run_command after_tests
    ;;
esac

exit $EXIT_VALUE

File

scripts/travis-ci.sh
View source
  1. #!/bin/bash
  2. COMMAND=$1
  3. BUILD_TOP=`dirname $TRAVIS_BUILD_DIR`
  4. EXIT_VALUE=0
  5. export PATH="$HOME/.composer/vendor/bin:$PATH"
  6. export DISPLAY=:99.0
  7. export CHROME_SANDBOX=/opt/google/chrome/chrome-sandbox
  8. ##
  9. # SCRIPT COMMANDS
  10. ##
  11. # system-install
  12. #
  13. # This is meant to setup the server on Travis-CI so that it can run the tests.
  14. #
  15. system_install() {
  16. # Add the Google Chrome packages.
  17. header Setting up APT
  18. wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
  19. sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
  20. sudo apt-get update > /dev/null
  21. # Create a database for our Drupal site.
  22. mysql -e 'create database drupal;'
  23. # Install the latest Drush 6.
  24. header Installing Drush
  25. composer global require --prefer-source --no-interaction drush/drush:6.*
  26. drush dl -y drupalorg_drush-7.x-1.x-dev --destination=$HOME/.drush
  27. drush cc drush
  28. # Build Codebase
  29. mkdir profiles
  30. mv openatrium profiles/
  31. mkdir drupal
  32. mv profiles drupal/
  33. # Build the current branch.
  34. header Building Open Atrium from current branch
  35. cd drupal
  36. pwd
  37. drush make --yes profiles/openatrium/drupal-org-core.make --prepare-install
  38. drush make --yes profiles/openatrium/scripts/oa-drush6-dev.make --no-core --contrib-destination=profiles/openatrium
  39. drush dl panopoly_demo-7.x-1.x-dev
  40. mkdir sites/default/files
  41. mkdir sites/default/files/private
  42. mkdir sites/default/files/temp
  43. # Build Behat dependencies
  44. header Installing Behat
  45. cd profiles/openatrium/modules/panopoly/panopoly_test/tests
  46. composer install --prefer-source --no-interaction
  47. cd ../../../../../../../
  48. # Verify that all the .make files will work on Drupal.org.
  49. header Verifying .make file
  50. #verify the release makefile instead
  51. #drush verify-makefile drupal/profiles/openatrium/drupal-org-dev.make
  52. drush verify-makefile drupal/profiles/openatrium/drupal-org.make
  53. find drupal/profiles/openatrium/modules -name \*.make -print0 | xargs -0 -n1 drush verify-makefile
  54. # Download an old version to test upgrading from.
  55. if [[ "$UPGRADE" != none ]]; then
  56. header Downloading Open Atrium $UPGRADE
  57. drush dl openatrium-$UPGRADE
  58. fi
  59. # Setup files
  60. sudo chmod -R 777 drupal/sites/all
  61. # Setup display for Selenium
  62. header Starting X
  63. sh -e /etc/init.d/xvfb start
  64. sleep 5
  65. # Get Chrome and ChromeDriver
  66. header Installing Google Chrome
  67. sudo apt-get install google-chrome-stable
  68. wget http://chromedriver.storage.googleapis.com/2.9/chromedriver_linux64.zip
  69. unzip -a chromedriver_linux64.zip
  70. # Insane hack from jsdevel:
  71. # https://github.com/jsdevel/travis-debugging/blob/master/shim.bash
  72. # This allows chrome-sandbox to work in side of OpenVZ, because I can't
  73. # figure out how to start chrome with --no-sandbox.
  74. sudo rm -f $CHROME_SANDBOX
  75. sudo wget https://googledrive.com/host/0B5VlNZ_Rvdw6NTJoZDBSVy1ZdkE -O $CHROME_SANDBOX
  76. sudo chown root:root $CHROME_SANDBOX
  77. sudo chmod 4755 $CHROME_SANDBOX
  78. sudo md5sum $CHROME_SANDBOX
  79. # Get Selenium
  80. header Downloading Selenium
  81. wget http://selenium-release.storage.googleapis.com/2.41/selenium-server-standalone-2.41.0.jar
  82. # Disable sendmail
  83. echo sendmail_path=`which true` >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
  84. }
  85. # before_tests
  86. #
  87. # Setup Drupal to run the tests.
  88. #
  89. before_tests() {
  90. UPGRADE_DEMO_VERSION=`echo $UPGRADE | sed -e s/^7.x-//`
  91. # Do the site install (either the current revision or old for the upgrade).
  92. header Installing Drupal
  93. if [[ "$UPGRADE" == none ]]; then
  94. cd drupal
  95. else
  96. cd openatrium-$UPGRADE
  97. drush dl panopoly_demo-$UPGRADE_DEMO_VERSION
  98. fi
  99. drush si openatrium --db-url=mysql://root:@127.0.0.1/drupal --account-name=admin --account-pass=admin --site-mail=admin@example.com --site-name="Open Atrium" --yes
  100. drush dis -y dblog
  101. drush vset -y file_private_path "sites/default/files/private"
  102. drush vset -y file_temporary_path "sites/default/files/temp"
  103. # Switch to the Panopoly platform built from Git (if we aren't there already).
  104. cd ../drupal
  105. # If we're an upgrade test, run the upgrade process.
  106. if [[ "$UPGRADE" != none ]]; then
  107. header Upgrading to latest version
  108. cp -a ../openatrium-$UPGRADE/sites/default/* sites/default/ && drush updb --yes
  109. fi
  110. drush cc all
  111. # Our tests depend on panopoly_demo.
  112. drush en -y panopoly_demo
  113. # Our tests depend on panopoly_test.
  114. drush en -y panopoly_test
  115. # Run the webserver
  116. header Starting webserver
  117. drush runserver --server=builtin 8888 > /dev/null 2>&1 &
  118. echo $! > /tmp/web-server-pid
  119. wait_for_port 8888
  120. sleep 3
  121. cd ..
  122. # Run the selenium server
  123. header Starting selenium
  124. java -jar selenium-server-standalone-2.41.0.jar -Dwebdriver.chrome.driver=`pwd`/chromedriver > /dev/null 2>&1 &
  125. echo $! > /tmp/selenium-server-pid
  126. wait_for_port 4444
  127. # Prime the site to prevent timeouts when the tests run
  128. wget -q -O - http://localhost:8888
  129. sleep 3
  130. }
  131. # before_tests
  132. #
  133. # Run the tests.
  134. #
  135. run_tests() {
  136. header Running tests
  137. # Make the Travis tests repos agnostic by injecting drupal_root with BEHAT_PARAMS
  138. export BEHAT_PARAMS="extensions[Drupal\\DrupalExtension\\Extension][drupal][drupal_root]=$BUILD_TOP/drupal"
  139. # cd drupal/profiles/openatrium/modules/contrib/oa_test/tests
  140. cd drupal/profiles/openatrium/modules/panopoly/panopoly_test/tests
  141. # If this isn't an upgrade, we test if any features are overridden.
  142. #if [[ "$UPGRADE" == none ]]; then
  143. # run_test ../../../../scripts/check-overridden.sh
  144. #fi
  145. # First, run all the tests in Firefox.
  146. run_test ./bin/behat --config behat.travis.yml
  147. # Then run some Chrome-only tests.
  148. run_test ./bin/behat --config behat.travis.yml -p chrome
  149. }
  150. # after_tests
  151. #
  152. # Clean up after the tests.
  153. #
  154. after_tests() {
  155. header Cleaning up after tests
  156. WEB_SERVER_PID=`cat /tmp/webserver-server-pid`
  157. SELENIUM_SERVER_PID=`cat /tmp/selenium-server-pid`
  158. # Stop the servers we started
  159. kill $WEB_SERVER_PID
  160. kill $SELENIUM_SERVER_PID
  161. }
  162. ##
  163. # UTILITY FUNCTIONS:
  164. ##
  165. # Prints a message about the section of the script.
  166. header() {
  167. set +xv
  168. echo
  169. echo "** $@"
  170. echo
  171. set -xv
  172. }
  173. # Sets the exit level to error.
  174. set_error() {
  175. EXIT_VALUE=1
  176. }
  177. # Runs a command and sets an error if it fails.
  178. run_test() {
  179. if ! $@; then
  180. set_error
  181. fi
  182. }
  183. # Runs a command showing all the lines executed
  184. run_command() {
  185. set -xv
  186. $@
  187. set +xv
  188. }
  189. # Wait for a specific port to respond to connections.
  190. wait_for_port() {
  191. local port=$1
  192. while echo | telnet localhost $port 2>&1 | grep -qe 'Connection refused'; do
  193. echo "Connection refused on port $port. Waiting 5 seconds..."
  194. sleep 5
  195. done
  196. }
  197. ##
  198. # SCRIPT MAIN:
  199. ##
  200. # Capture all errors and set our overall exit value.
  201. trap 'set_error' ERR
  202. # We want to always start from the same directory:
  203. cd $BUILD_TOP
  204. case $COMMAND in
  205. system-install)
  206. run_command system_install
  207. ;;
  208. drupal-install)
  209. run_command drupal_install
  210. ;;
  211. before-tests)
  212. run_command before_tests
  213. ;;
  214. run-tests)
  215. run_command run_tests
  216. ;;
  217. after-tests)
  218. run_command after_tests
  219. ;;
  220. esac
  221. exit $EXIT_VALUE