before_script.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/usr/bin/env bash
  2. # Copyright © Magento, Inc. All rights reserved.
  3. # See COPYING.txt for license details.
  4. set -e
  5. trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit code $?' ERR
  6. # prepare for test suite
  7. case $TEST_SUITE in
  8. integration)
  9. cd dev/tests/integration
  10. test_set_list=$(find testsuite/* -maxdepth 1 -mindepth 1 -type d | sort)
  11. test_set_count=$(printf "$test_set_list" | wc -l)
  12. test_set_size[1]=$(printf "%.0f" $(echo "$test_set_count*0.13" | bc)) #13%
  13. test_set_size[2]=$(printf "%.0f" $(echo "$test_set_count*0.30" | bc)) #30%
  14. test_set_size[3]=$((test_set_count-test_set_size[1]-test_set_size[2])) #55%
  15. echo "Total = ${test_set_count}; Batch #1 = ${test_set_size[1]}; Batch #2 = ${test_set_size[2]}; Batch #3 = ${test_set_size[3]};";
  16. echo "==> preparing integration testsuite on index $INTEGRATION_INDEX with set size of ${test_set_size[$INTEGRATION_INDEX]}"
  17. cp phpunit.xml.dist phpunit.xml
  18. # remove memory usage tests if from any set other than the first
  19. if [[ $INTEGRATION_INDEX > 1 ]]; then
  20. echo " - removing testsuite/Magento/MemoryUsageTest.php"
  21. perl -pi -0e 's#^\s+<!-- Memory(.*?)</testsuite>\n##ims' phpunit.xml
  22. fi
  23. # divide test sets up by indexed testsuites
  24. i=0; j=1; dirIndex=1; testIndex=1;
  25. for test_set in $test_set_list; do
  26. test_xml[j]+=" <directory suffix=\"Test.php\">$test_set</directory>\n"
  27. if [[ $j -eq $INTEGRATION_INDEX ]]; then
  28. echo "$dirIndex: Batch #$j($testIndex of ${test_set_size[$j]}): + including $test_set"
  29. else
  30. echo "$dirIndex: Batch #$j($testIndex of ${test_set_size[$j]}): + excluding $test_set"
  31. fi
  32. testIndex=$((testIndex+1))
  33. dirIndex=$((dirIndex+1))
  34. i=$((i+1))
  35. if [ $i -eq ${test_set_size[$j]} ] && [ $j -lt $INTEGRATION_SETS ]; then
  36. j=$((j+1))
  37. i=0
  38. testIndex=1
  39. fi
  40. done
  41. # replace test sets for current index into testsuite
  42. perl -pi -e "s#\s+<directory.*>testsuite</directory>#${test_xml[INTEGRATION_INDEX]}#g" phpunit.xml
  43. echo "==> testsuite preparation complete"
  44. # create database and move db config into place
  45. mysql -uroot -e '
  46. SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION;
  47. CREATE DATABASE magento_integration_tests;
  48. '
  49. mv etc/install-config-mysql.travis.php.dist etc/install-config-mysql.php
  50. cd ../../..
  51. ;;
  52. static)
  53. cd dev/tests/static
  54. echo "==> preparing changed files list"
  55. changed_files_ce="$TRAVIS_BUILD_DIR/dev/tests/static/testsuite/Magento/Test/_files/changed_files_ce.txt"
  56. php get_github_changes.php \
  57. --output-file="$changed_files_ce" \
  58. --base-path="$TRAVIS_BUILD_DIR" \
  59. --repo='https://github.com/magento/magento2.git' \
  60. --branch="$TRAVIS_BRANCH"
  61. sed 's/^/ + including /' "$changed_files_ce"
  62. cd ../../..
  63. ;;
  64. js)
  65. cp package.json.sample package.json
  66. cp Gruntfile.js.sample Gruntfile.js
  67. yarn
  68. if [[ $GRUNT_COMMAND != "static" ]]; then
  69. echo "Installing Magento"
  70. mysql -uroot -e 'CREATE DATABASE magento2;'
  71. php bin/magento setup:install -q \
  72. --admin-user="admin" \
  73. --admin-password="123123q" \
  74. --admin-email="admin@example.com" \
  75. --admin-firstname="John" \
  76. --admin-lastname="Doe"
  77. echo "Deploying Static Content"
  78. php bin/magento setup:static-content:deploy -f -q -j=2 \
  79. --no-css --no-less --no-images --no-fonts --no-misc --no-html-minify
  80. fi
  81. ;;
  82. functional)
  83. echo "Installing Magento"
  84. mysql -uroot -e 'CREATE DATABASE magento2;'
  85. php bin/magento setup:install -q \
  86. --language="en_US" \
  87. --timezone="UTC" \
  88. --currency="USD" \
  89. --base-url="http://${MAGENTO_HOST_NAME}/" \
  90. --admin-firstname="John" \
  91. --admin-lastname="Doe" \
  92. --backend-frontname="backend" \
  93. --admin-email="admin@example.com" \
  94. --admin-user="admin" \
  95. --use-rewrites=1 \
  96. --admin-use-security-key=0 \
  97. --admin-password="123123q"
  98. echo "Enabling production mode"
  99. php bin/magento deploy:mode:set production
  100. echo "Prepare functional tests for running"
  101. cd dev/tests/functional
  102. composer install && composer require se/selenium-server-standalone:2.53.1
  103. export DISPLAY=:1.0
  104. sh ./vendor/se/selenium-server-standalone/bin/selenium-server-standalone -port 4444 -host 127.0.0.1 \
  105. -Dwebdriver.firefox.bin=$(which firefox) -trustAllSSLCertificate &> ~/selenium.log &
  106. cp ./phpunit.xml.dist ./phpunit.xml
  107. sed -e "s?127.0.0.1?${MAGENTO_HOST_NAME}?g" --in-place ./phpunit.xml
  108. sed -e "s?basic?travis_acceptance?g" --in-place ./phpunit.xml
  109. cp ./.htaccess.sample ./.htaccess
  110. cd ./utils
  111. php -f generate/moduleSequence.php
  112. php -f mtf troubleshooting:check-all
  113. cd ../../..
  114. ;;
  115. graphql-api-functional)
  116. echo "Installing Magento"
  117. mysql -uroot -e 'CREATE DATABASE magento2;'
  118. php bin/magento setup:install -q \
  119. --language="en_US" \
  120. --timezone="UTC" \
  121. --currency="USD" \
  122. --base-url="http://${MAGENTO_HOST_NAME}/" \
  123. --admin-firstname="John" \
  124. --admin-lastname="Doe" \
  125. --backend-frontname="backend" \
  126. --admin-email="admin@example.com" \
  127. --admin-user="admin" \
  128. --use-rewrites=1 \
  129. --admin-use-security-key=0 \
  130. --admin-password="123123q"
  131. echo "Prepare api-functional tests for running"
  132. cd dev/tests/api-functional
  133. cp -r _files/Magento/TestModuleGraphQl* ../../../app/code/Magento # Deploy and enable test modules before running tests
  134. cp ./phpunit_graphql.xml.dist ./phpunit.xml
  135. sed -e "s?magento.url?${MAGENTO_HOST_NAME}?g" --in-place ./phpunit.xml
  136. cd ../../..
  137. php bin/magento setup:upgrade
  138. echo "Enabling production mode"
  139. php bin/magento deploy:mode:set production
  140. ;;
  141. esac