2016-11-29 07:44:56 -05:00
|
|
|
#!/bin/bash
|
2016-04-07 08:34:58 -04:00
|
|
|
# This script is used as a single command to run the x-plugins tests.
|
2016-01-18 18:20:33 -05:00
|
|
|
#
|
2016-04-07 08:34:58 -04:00
|
|
|
# It will attempt to check out 'elasticsearch' into a sibling directory
|
2016-12-05 19:10:33 -05:00
|
|
|
# unless the environment variable `USE_EXISTING_ES` has a value. The
|
|
|
|
# branch of elasticsearch which will be checked out depends on
|
|
|
|
# environment variables. If running locally, set GIT_BRANCH. When
|
|
|
|
# running in Jenkins, that env var is set. When running a PR
|
|
|
|
# jenkins job, the variables PR_SOURCE_BRANCH and PR_TARGET_BRANCH
|
|
|
|
# will be set and the source branch will be looked for in elasticsearch
|
|
|
|
# before falling back to the target branch name.
|
2016-01-18 18:20:33 -05:00
|
|
|
#
|
2016-09-12 14:32:12 -04:00
|
|
|
# It will also attempt to install the appropriate version of node.js
|
2016-09-13 08:34:22 -04:00
|
|
|
# for the Kibana plugin tests using nvm, unless
|
|
|
|
# `xpack.kibana.build=false` is defined in
|
|
|
|
# ~/.gradle/gradle.properties. Set a custom nvm directory using the
|
|
|
|
# `NVM_DIR` environment variable.
|
2016-09-12 14:32:12 -04:00
|
|
|
#
|
2016-01-18 18:20:33 -05:00
|
|
|
|
2016-11-23 06:44:15 -05:00
|
|
|
# Turn on semi-strict mode
|
|
|
|
set -e
|
2016-11-29 07:44:56 -05:00
|
|
|
set -o pipefail
|
2016-11-21 09:36:55 -05:00
|
|
|
|
2016-11-23 06:44:15 -05:00
|
|
|
# Allow the user choose different test through a single cli arg
|
2016-11-28 06:19:48 -05:00
|
|
|
# default to `check` if no argument has been supplied
|
|
|
|
key=${1-check}
|
2016-11-21 09:36:55 -05:00
|
|
|
case $key in
|
2016-11-28 06:19:48 -05:00
|
|
|
packagingTest)
|
2016-11-23 06:44:15 -05:00
|
|
|
GRADLE_OPT_STRING="--info -Pvagrant.boxes=all :x-plugins:qa:vagrant:packagingTest"
|
2016-11-29 07:44:56 -05:00
|
|
|
;;
|
2016-11-28 06:19:48 -05:00
|
|
|
check)
|
2016-11-23 06:44:15 -05:00
|
|
|
GRADLE_OPT_STRING="--info check -Dtests.network=true -Dtests.badapples=true"
|
2016-11-29 07:44:56 -05:00
|
|
|
;;
|
2016-11-28 06:19:48 -05:00
|
|
|
*)
|
2016-11-29 07:44:56 -05:00
|
|
|
echo "Unsupported cli argument $1. Allowed arguments are packagingTest or check. No argument defaults to check."
|
2016-11-28 06:19:48 -05:00
|
|
|
exit 1;;
|
2016-11-21 09:36:55 -05:00
|
|
|
esac
|
2016-01-18 18:20:33 -05:00
|
|
|
|
2016-04-07 08:34:58 -04:00
|
|
|
SCRIPT="$0"
|
2016-01-18 18:20:33 -05:00
|
|
|
|
2016-04-07 08:34:58 -04:00
|
|
|
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
|
|
|
|
while [ -h "$SCRIPT" ] ; do
|
2016-11-29 07:44:56 -05:00
|
|
|
ls=$(ls -ld "$SCRIPT")
|
2016-04-07 08:34:58 -04:00
|
|
|
# Drop everything prior to ->
|
2016-11-29 07:44:56 -05:00
|
|
|
link=$(expr "$ls" : '.*-> \(.*\)$')
|
2016-04-07 08:34:58 -04:00
|
|
|
if expr "$link" : '/.*' > /dev/null; then
|
|
|
|
SCRIPT="$link"
|
|
|
|
else
|
2016-11-29 07:44:56 -05:00
|
|
|
SCRIPT=$(dirname "$SCRIPT")/"$link"
|
2016-04-07 08:34:58 -04:00
|
|
|
fi
|
|
|
|
done
|
2016-01-18 18:20:33 -05:00
|
|
|
|
2016-04-07 08:34:58 -04:00
|
|
|
# determine base directory
|
2016-11-29 07:44:56 -05:00
|
|
|
BASE_DIR=$(dirname "$SCRIPT")/..
|
2016-04-07 08:34:58 -04:00
|
|
|
|
|
|
|
# make BASE_DIR absolute
|
2016-11-29 07:44:56 -05:00
|
|
|
BASE_DIR=$(cd "$BASE_DIR"; pwd)
|
2016-04-07 08:34:58 -04:00
|
|
|
|
2016-11-29 07:44:56 -05:00
|
|
|
PARENT_DIR=$(cd "$BASE_DIR"/..; pwd)
|
2016-04-07 08:34:58 -04:00
|
|
|
|
|
|
|
# go to the parent directory
|
|
|
|
cd $PARENT_DIR
|
|
|
|
|
|
|
|
if [ -z ${USE_EXISTING_ES:+x} ]; then
|
2016-01-18 18:20:33 -05:00
|
|
|
if [ -d "./elasticsearch" ]; then
|
2016-04-07 08:34:58 -04:00
|
|
|
echo "I expected a clean workspace but an 'elasticsearch' sibling directory already exists in [$PARENT_DIR]!"
|
2016-01-18 18:20:33 -05:00
|
|
|
echo
|
2016-04-07 08:34:58 -04:00
|
|
|
echo "Either define 'USE_EXISTING_ES' or remove the existing 'elasticsearch' sibling."
|
2016-01-18 18:20:33 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-12-06 03:52:03 -05:00
|
|
|
BRANCH=${PR_SOURCE_BRANCH:-${GIT_BRANCH#*/}} # GIT_BRANCH starts with the repo, i.e., origin/master
|
2016-12-06 03:43:28 -05:00
|
|
|
BRANCH=${BRANCH:-master} # fall back to CI branch if not testing a PR
|
2016-12-05 19:10:33 -05:00
|
|
|
echo "Checking if branch '$BRANCH' has elasticsearch sibling..."
|
2016-12-06 05:37:50 -05:00
|
|
|
if [[ -z "$(git ls-remote --heads https://github.com/elastic/elasticsearch.git $BRANCH)" ]]; then
|
2016-12-05 19:10:33 -05:00
|
|
|
echo "No sibling branch, using PR target branch"
|
|
|
|
BRANCH=$PR_TARGET_BRANCH
|
|
|
|
fi
|
|
|
|
echo "Checking out Elasticsearch '$BRANCH' branch..."
|
|
|
|
git clone -b $BRANCH https://github.com/elastic/elasticsearch.git --depth=1
|
2016-01-18 18:20:33 -05:00
|
|
|
else
|
|
|
|
if [ -d "./elasticsearch" ]; then
|
|
|
|
echo "Using existing 'elasticsearch' checkout"
|
|
|
|
else
|
2016-04-07 08:34:58 -04:00
|
|
|
echo "You have defined 'USE_EXISTING_ES' but no existing Elasticsearch directory exists!"
|
2016-01-18 18:20:33 -05:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-09-12 14:32:12 -04:00
|
|
|
# back to base directory
|
|
|
|
cd "$BASE_DIR"
|
|
|
|
|
2016-09-13 08:34:22 -04:00
|
|
|
if ! grep -q -e '^xpack\.kibana\.build=false$' ~/.gradle/gradle.properties
|
|
|
|
then
|
|
|
|
# install the correct node.js version
|
|
|
|
if [ -z ${NVM_DIR:+x} ]; then
|
|
|
|
export NVM_DIR="/var/lib/jenkins/.nvm";
|
|
|
|
fi
|
2016-09-12 14:32:12 -04:00
|
|
|
|
2016-09-13 08:34:22 -04:00
|
|
|
NVM_SCRIPT="$NVM_DIR/nvm.sh"
|
|
|
|
if [ -s "$NVM_SCRIPT" ]; then
|
|
|
|
. "$NVM_SCRIPT" # load nvm
|
|
|
|
else
|
|
|
|
echo "Unable to find the nvm script at \"$NVM_SCRIPT\""
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-09-12 14:32:12 -04:00
|
|
|
|
2016-09-13 08:34:22 -04:00
|
|
|
echo "Installing node.js version $(cat ./kibana/.node-version)..."
|
|
|
|
nvm install "$(cat ./kibana/.node-version)"
|
|
|
|
fi
|
2016-09-12 14:32:12 -04:00
|
|
|
|
2016-01-18 18:20:33 -05:00
|
|
|
echo "Running X-Plugins tests..."
|
2016-09-12 14:32:12 -04:00
|
|
|
echo "Running in $PWD"
|
2016-04-07 08:34:58 -04:00
|
|
|
|
|
|
|
# output the commands
|
2016-09-12 14:32:12 -04:00
|
|
|
set -xuf
|
2016-04-07 08:34:58 -04:00
|
|
|
|
|
|
|
# clean
|
|
|
|
gradle --stacktrace clean
|
2016-01-18 18:20:33 -05:00
|
|
|
|
2016-04-07 08:34:58 -04:00
|
|
|
# Actually run the tests
|
2016-11-23 06:44:15 -05:00
|
|
|
gradle $GRADLE_OPT_STRING
|
2016-01-18 18:20:33 -05:00
|
|
|
|
|
|
|
# ~*~ shell-script-mode ~*~
|