#!/bin/bash
set -e
DEVSHOP_PATH="$( cd "$(dirname "$0")"/../bin ; pwd -P )"
PATH="$DEVSHOP_PATH:$PATH"

devshop-logo "Running DevShop Tests"
devshop-log echo "Path: $PATH"

cd /usr/share/devshop
git status
git show
devshop status

# Print the lines and exit if a failure happens.
devshop-log "Checking versions of devshop, drush, node, npm..."
devshop-log "DevShop Version: $(devshop --version)"
devshop-log "Drush Version: $(drush --version)"

echo "Drush RC: "
cat ~/.drush/drushrc.php

#echo "Node Version:     " && node --version
#echo "NPM Version:      " && npm --version

# Removing to see if this caused the fail in 9a9ed11ce28dbaccb28e9c8d1ae3e52d43820a26
# devshop-log "Verifying Hostmaster Platform (includes composer install)..."
# drush @hostmaster provision-verify

# Run remaining tasks from install process.
# Pause the task queue.
devshop-log "Disabling hosting queue..."
drush @hostmaster dis hosting_queued -y
drush @hostmaster vset hosting_queued_paused 1
drush @hostmaster vset hosting_queue_tasks_enabled 0

#echo "DevShop | devshop-tests.sh | Verify hostmaster platform first..."
#PLATFORM_ALIAS=`drush @hm php-eval "print d()->platform->name"`
#drush @hostmaster hosting-task $PLATFORM_ALIAS verify --fork=0 --strict=0 --force

# devshop-log "Running remaining tasks: drush @hostmaster hosting-tasks --fork=0 --strict=0 --force || true"
# drush @hostmaster hosting-tasks --fork=0 --strict=0 --force || true

# devshop-log "Running remaining tasks: Complete!"

# Enable watchdog
drush @hostmaster en dblog -y

# Save GitHub Token
if [ -n "${GITHUB_TOKEN}" ]; then
  drush @hostmaster vset devshop_github_token ${GITHUB_TOKEN}
  devshop-log "Drupal variable set from GITHUB_TOKEN environment variable."
else
  devshop-log "WARNING: GITHUB_TOKEN environment variable not found."
fi

echo "Drush RC Right before devmaster:test"
cat ~/.drush/drushrc.php

# Run the test suite.
devshop devmaster:test
#drush @hostmaster provision-test --behat-folder-path=profiles/devmaster/tests --test-type=behat

# Unpause the task queue.
drush @hostmaster vset hosting_queued_paused 0
