.travis-init.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #/bin/bash
  2. if [[ ! "$WORKSPACE" = /* ]] ||
  3. [[ ! "$PATH_TO_PLUGIN" = /* ]] ||
  4. [[ ! "$PATH_TO_REDMINE" = /* ]];
  5. then
  6. echo "You should set"\
  7. " WORKSPACE, PATH_TO_PLUGIN, PATH_TO_REDMINE"\
  8. " environment variables"
  9. echo "You set:"\
  10. "$WORKSPACE"\
  11. "$PATH_TO_PLUGIN"\
  12. "$PATH_TO_REDMINE"
  13. exit 1;
  14. fi
  15. case $REDMINE_VERSION in
  16. 1.4.*) export PATH_TO_PLUGINS=./vendor/plugins # for redmine < 2.0
  17. export GENERATE_SECRET=generate_session_store
  18. export MIGRATE_PLUGINS=db:migrate_plugins
  19. export REDMINE_TARBALL=https://github.com/redmine/redmine/archive/$REDMINE_VERSION.tar.gz
  20. ;;
  21. 2.* | 3.*) export PATH_TO_PLUGINS=./plugins # for redmine 2.x and 3.x
  22. export GENERATE_SECRET=generate_secret_token
  23. export MIGRATE_PLUGINS=redmine:plugins:migrate
  24. export REDMINE_TARBALL=https://github.com/redmine/redmine/archive/$REDMINE_VERSION.tar.gz
  25. ;;
  26. master) export PATH_TO_PLUGINS=./plugins
  27. export GENERATE_SECRET=generate_secret_token
  28. export MIGRATE_PLUGINS=redmine:plugins:migrate
  29. export REDMINE_GIT_REPO=https://github.com/redmine/redmine.git
  30. export REDMINE_GIT_TAG=master
  31. ;;
  32. *) echo "Unsupported platform $REDMINE_VERSION"
  33. exit 1
  34. ;;
  35. esac
  36. export BUNDLE_GEMFILE=$PATH_TO_REDMINE/Gemfile
  37. clone_redmine() {
  38. set -e # exit if clone fails
  39. rm -rf $PATH_TO_REDMINE
  40. if [ ! "$VERBOSE" = "yes" ]; then
  41. QUIET=--quiet
  42. fi
  43. if [ -n "${REDMINE_GIT_TAG}" ]; then
  44. git clone -b $REDMINE_GIT_TAG --depth=100 $QUIET $REDMINE_GIT_REPO $PATH_TO_REDMINE
  45. cd $PATH_TO_REDMINE
  46. git checkout $REDMINE_GIT_TAG
  47. else
  48. mkdir -p $PATH_TO_REDMINE
  49. wget $REDMINE_TARBALL -O- | tar -C $PATH_TO_REDMINE -xz --strip=1 --show-transformed -f -
  50. fi
  51. }
  52. run_tests() {
  53. # exit if tests fail
  54. set -e
  55. cd $PATH_TO_REDMINE
  56. if [ "$VERBOSE" = "yes" ]; then
  57. TRACE=--trace
  58. fi
  59. script -e -c "bundle exec rake redmine:plugins:test NAME="$PLUGIN $VERBOSE
  60. }
  61. uninstall() {
  62. set -e # exit if migrate fails
  63. cd $PATH_TO_REDMINE
  64. # clean up database
  65. if [ "$VERBOSE" = "yes" ]; then
  66. TRACE=--trace
  67. fi
  68. bundle exec rake $TRACE $MIGRATE_PLUGINS NAME=$PLUGIN VERSION=0
  69. }
  70. run_install() {
  71. # exit if install fails
  72. set -e
  73. # cd to redmine folder
  74. cd $PATH_TO_REDMINE
  75. # create a link to the plugin, but avoid recursive link.
  76. if [ -L "$PATH_TO_PLUGINS/$PLUGIN" ]; then rm "$PATH_TO_PLUGINS/$PLUGIN"; fi
  77. ln -s "$PATH_TO_PLUGIN" "$PATH_TO_PLUGINS/$PLUGIN"
  78. if [ "$VERBOSE" = "yes" ]; then
  79. export TRACE=--trace
  80. fi
  81. cp $PATH_TO_PLUGINS/$PLUGIN/.travis-database.yml config/database.yml
  82. # install gems
  83. mkdir -p vendor/bundle
  84. bundle install --path vendor/bundle
  85. bundle exec rake db:migrate $TRACE
  86. bundle exec rake redmine:load_default_data REDMINE_LANG=en $TRACE
  87. bundle exec rake $GENERATE_SECRET $TRACE
  88. bundle exec rake $MIGRATE_PLUGINS $TRACE
  89. }
  90. while getopts :irtu opt
  91. do case "$opt" in
  92. r) clone_redmine; exit 0;;
  93. i) run_install; exit 0;;
  94. t) run_tests $2; exit 0;;
  95. u) uninstall; exit 0;;
  96. [?]) echo "i: install; r: clone redmine; t: run tests; u: uninstall";;
  97. esac
  98. done