#!/usr/bin/env bash # this ensures any failures along the way result in a CI failure set -eu node-0() { is_enabled "drivers" && export ENGINES="h2,mongo,mysql,bigquery" || export ENGINES="h2" if is_engine_enabled "mongo"; then run_step install-mongodb fi run_step lein-test } node-1() { is_enabled "drivers" && export ENGINES="h2,sqlserver,oracle" || export ENGINES="h2" if is_engine_enabled "oracle"; then run_step install-oracle fi MB_DB_TYPE=postgres MB_DB_DBNAME=circle_test MB_DB_PORT=5432 MB_DB_USER=ubuntu MB_DB_HOST=localhost \ run_step lein-test } node-2() { is_enabled "drivers" && export ENGINES="h2,postgres,sqlite,presto" || export ENGINES="h2" if is_engine_enabled "crate"; then run_step install-crate fi if is_engine_enabled "presto"; then run_step install-presto fi MB_ENCRYPTION_SECRET_KEY='Orw0AAyzkO/kPTLJRxiyKoBHXa/d6ZcO+p+gpZO/wSQ=' MB_DB_TYPE=mysql MB_DB_DBNAME=circle_test MB_DB_PORT=3306 MB_DB_USER=ubuntu MB_DB_HOST=localhost \ MB_PRESTO_HOST=localhost MB_PRESTO_PORT=8080 \ run_step lein-test } node-3() { is_enabled "drivers" && export ENGINES="h2,redshift,druid,vertica" || export ENGINES="h2" if is_engine_enabled "vertica"; then run_step install-vertica fi # this is redundant with node 0 unless one of the non-H2 driver tests is enabled if [ ENGINES != "h2" ]; then run_step lein-test fi } node-4() { run_step lein bikeshed run_step lein docstring-checker run_step ./bin/reflection-linter } node-5() { run_step lein eastwood run_step yarn run lint run_step yarn run test run_step yarn run test-jest run_step yarn run flow } node-6() { if is_enabled "jar" || is_enabled "e2e" || is_enabled "screenshots"; then run_step ./bin/build version frontend sample-dataset uberjar fi if is_enabled "e2e" || is_enabled "compare_screenshots"; then USE_SAUCE=true \ run_step yarn run test-e2e fi if is_enabled "screenshots"; then run_step node_modules/.bin/babel-node ./bin/compare-screenshots fi } install-crate() { sudo add-apt-repository ppa:crate/stable -y sudo apt-get update sudo apt-get install -y crate # ulimit setting refused Crate service to start on CircleCI container - so comment it sudo sed -i '/MAX_LOCKED_MEMORY/s/^/#/' /etc/init/crate.conf echo "psql.port: 5200" | sudo tee -a /etc/crate/crate.yml sudo service crate restart } install-mongodb() { sudo apt-get purge mongodb-org* sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list sudo apt-get update sudo apt-get install -y mongodb-org sudo service mongod restart } install-oracle() { wget --output-document=plugins/ojdbc7.jar $ORACLE_JDBC_JAR } install-vertica() { wget --output-document=plugins/vertica-jdbc-7.1.2-0.jar $VERTICA_JDBC_JAR docker run --detach --publish 5433:5433 sumitchawla/vertica sleep 60 } install-presto() { docker run --detach --publish 8080:8080 wiill/presto-mb-ci sleep 10 } lein-test() { lein test } if [ -z ${CIRCLE_BRANCH_REGEX+x} ]; then CIRCLE_BRANCH_REGEX='^master|release-.+$' fi is_enabled() { (echo "$CIRCLE_BRANCH" | grep -qE "$CIRCLE_BRANCH_REGEX") || [[ "$CIRCLE_COMMIT_MESSAGE" == *"[ci $1]"* ]] || [[ "$CIRCLE_COMMIT_MESSAGE" == *"[ci all]"* ]] } is_engine_enabled() { [[ "$ENGINES" == *"$1"* ]] } # print a summary on exit status=0 summary="" # records the time and exit code of each step run_step() { status=0 start=$(date +%s) # run in the background then `wait` so fail_fast can interrupt it "$@" & wait $! || status=$? elapsed=$(expr $(date +%s) - $start || true) summary="${summary}status=$status time=$elapsed command=$@\n" return $status } summary() { # if last status was failure then fail the rest of the nodes if [ $status != 0 ]; then fail_fast fi echo -e "========================================" echo -en "$summary" echo -e "========================================" } trap summary EXIT fail_fast() { echo -e "========================================" echo -e "Failing fast! Stopping other nodes..." # ssh to the other CircleCI nodes and send SIGUSR1 to tell them to exit early for (( i = 0; i < $CIRCLE_NODE_TOTAL; i++ )); do if [ $i != $CIRCLE_NODE_INDEX ]; then ssh node$i 'touch /tmp/fail; pkill -SIGUSR1 -f "bash ./bin/ci"' 2> /dev/null || true fi done } exit_early() { echo -e "========================================" echo -e "Exited early! Did not necesssarily pass!" pkill -TERM -P $$ || true exit 0 } trap exit_early SIGUSR1 if [ -z ${CIRCLE_SHA1+x} ]; then export CIRCLE_SHA1="$(git rev-parse HEAD)" fi if [ -z ${CIRCLE_BRANCH+x} ]; then export CIRCLE_BRANCH="$(git rev-parse --abbrev-ref HEAD)" fi export CIRCLE_COMMIT_MESSAGE="$(git log --format=oneline -n 1 $CIRCLE_SHA1)" if [ -f "/tmp/fail" ]; then exit_early fi if [ -z ${CIRCLE_NODE_INDEX+x} ]; then # If CIRCLE_NODE_INDEX isn't set, read node numbers from the args # Useful for testing locally. for i in "$@"; do node-$i done else # Normal mode on CircleCI node-$CIRCLE_NODE_INDEX fi