This fork extends the command line interface (CLI) and is distributed as a convenient one-file-executable (Windows, Linux, Mac). It is also available via Docker Hub, PyPI and Binder.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

131 lines
4.7 KiB

  1. #!/bin/bash
  2. # Script for running tests with different OpenRefine and Java versions based on Docker images.
  3. # Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>
  14. # defaults:
  15. all=(3.4.1 3.4 3.3 3.2-java12 3.2-java11 3.2-java10 3.2-java9 3.2 3.1-java9 3.1 3.0-java9 3.0 2.8-java9 2.8 2.8-java7 2.7 2.7-java7 2.5-java7 2.5-java6 2.1-java6 2.0-java6)
  16. main=(3.4.1 3.4 3.3 3.2 3.1 3.0 2.8 2.7 2.5-java6 2.1-java6 2.0-java6)
  17. interactively=false
  18. port="3333"
  19. # help screen
  20. function usage () {
  21. cat <<EOF
  22. Usage: ./tests.sh [-t TAG] [-i] [-p] [-a] [-h]
  23. Script for running tests with different OpenRefine and Java versions.
  24. It uses docker images from https://hub.docker.com/r/felixlohmeier/openrefine.
  25. Examples:
  26. ./tests.sh -a # run tests on all OpenRefine versions (from 2.0 up to 3.4.1)
  27. ./tests.sh -t 3.4.1 # run tests on tag 3.4.1
  28. ./tests.sh -t 3.4.1 -i # run tests on tag 3.4.1 interactively (pause before and after tests)
  29. ./tests.sh -t 3.4.1 -t 2.7 # run tests on tags 3.4.1 and 2.7
  30. Advanced:
  31. ./tests.sh -j # run tests on all OpenRefine versions and each with all supported Java versions (requires a lot of docker images to be downloaded!)
  32. ./tests.sh -t 3.1 -i -p 3334 # run tests on tag 3.1 interactively on port 3334
  33. Running tests interactively (-i) allows you to examine OpenRefine GUI at http://localhost:3333.
  34. Execute the script concurrently in another terminal on another port (-p 3334) to compare changes in the OpenRefine GUI at http://localhost:3333 and http://localhost:3334.
  35. Available tags (java 8 if java not mentioned in tag):
  36. EOF
  37. for t in ${all[*]} ; do
  38. echo "$t"
  39. done
  40. exit 1
  41. }
  42. # check input
  43. NUMARGS=$#
  44. if [ "$NUMARGS" -eq 0 ]; then
  45. usage
  46. fi
  47. # check system requirements
  48. DOCKER="$(command -v docker 2> /dev/null)"
  49. if [ -z "$DOCKER" ] ; then
  50. echo 1>&2 "This action requires you to have 'docker' installed and present in your PATH. You can download it for free at http://www.docker.com/"
  51. exit 1
  52. fi
  53. DOCKERINFO="$(docker info 2>/dev/null | grep 'Server Version')"
  54. if [ -z "$DOCKERINFO" ]
  55. then
  56. echo "command 'docker info' failed, trying again with sudo..."
  57. DOCKERINFO="$(sudo docker info 2>/dev/null | grep 'Server Version')"
  58. echo "OK"
  59. docker=(sudo docker)
  60. if [ -z "$DOCKERINFO" ] ; then
  61. echo 1>&2 "This action requires you to start the docker daemon. Try 'sudo systemctl start docker' or 'sudo start docker'. If the docker daemon is already running then maybe some security privileges are missing to run docker commands.'"
  62. exit 1
  63. fi
  64. else
  65. docker=(docker)
  66. fi
  67. CURLINFO="$(command -v curl 2>/dev/null)"
  68. if [ -z "$CURLINFO" ] ; then
  69. echo 1>&2 "This action requires you to have 'curl' installed and present in your PATH."
  70. exit 1
  71. fi
  72. # get user input
  73. options="t:p:iajh"
  74. while getopts $options opt; do
  75. case $opt in
  76. t ) tags+=("${OPTARG}");;
  77. p ) port="${OPTARG}";export OPENREFINE_PORT="$port";;
  78. i ) interactively=true;;
  79. a ) tags=("${main[*]}");;
  80. j ) tags=("${all[*]}");;
  81. h ) usage ;;
  82. \? ) echo 1>&2 "Unknown option: -$OPTARG"; usage; exit 1;;
  83. : ) echo 1>&2 "Missing option argument for -$OPTARG"; usage; exit 1;;
  84. * ) echo 1>&2 "Unimplemented option: -$OPTARG"; usage; exit 1;;
  85. esac
  86. done
  87. shift $((OPTIND - 1))
  88. # print config
  89. echo "Tags: ${tags[*]}"
  90. echo "Port: $port"
  91. echo ""
  92. # safe cleanup handler
  93. cleanup()
  94. {
  95. echo "cleanup..."
  96. ${docker[*]} stop "$t"
  97. }
  98. trap "cleanup;exit" SIGHUP SIGINT SIGQUIT SIGTERM
  99. # run setup.py tests for each docker tag
  100. for t in ${tags[*]} ; do
  101. echo "=== Tests for $t ==="
  102. echo ""
  103. echo "Begin: $(date)"
  104. ${docker[*]} run -d -p "$port":3333 --rm --name "$t" felixlohmeier/openrefine:"$t"
  105. until curl --silent -N http://localhost:"$port" | cat | grep -q -o "Refine" ; do sleep 1; done
  106. echo "Refine running at http://localhost:${port}"
  107. if [ $interactively = true ]; then read -r -p "Press [Enter] key to start tests..."; fi
  108. python2 setup.py test
  109. if [ $interactively = true ]; then read -r -p "Press [Enter] key to stop OpenRefine..."; fi
  110. ${docker[*]} stop "$t"
  111. echo "End: $(date)"
  112. echo ""
  113. done