---
machine:
  php:
    version: 5.5.11

dependencies:
  cache_directories:
    - ~/.composer/cache

  override:
    - sudo apt-get update --quiet && sudo apt-get install --no-install-recommends --quiet --yes cmake && sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-4.9 90
    - echo "pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock" > ~/.phpenv/versions/$(phpenv global)/etc/conf.d/pdo_mysql.ini
    - sed -i 's/^;//' ~/.phpenv/versions/$(phpenv global)/etc/conf.d/xdebug.ini
    - sed -i 's/^;opcache\.enable=0/opcache.enable=0/' ~/.phpenv/versions/$(phpenv global)/etc/php.ini
    - cp ~/CDash/tests/circle/default /etc/apache2/sites-available
    - sudo ln -s ~/CDash/public /var/www/cdash
    - sudo service apache2 restart
    - chmod a+rwx backup log public/rss public/upload
    - sudo composer self-update --no-interaction
    - test -n "${CIRCLE_PR_REPONAME}" || composer config --global --no-interaction github-oauth.github.com $GITHUB_OAUTH_TOKEN
    - composer install --no-interaction --no-progress --prefer-dist
    - npm install
    - node_modules/.bin/webdriver-manager update
    - createdb -O ubuntu cdash4simpletest

test:
  override:
    - mkdir _build
    - node_modules/.bin/webdriver-manager start:
        background: true
    - apache2 -v && cmake --version && mysql --version && php --version && psql --version
    - cd _build && cmake -DCDASH_TESTING_RENAME_LOGS=true -DCDASH_DIR_NAME=cdash -DCDASH_DB_LOGIN=ubuntu -DBUILDNAME="${CIRCLE_BRANCH}_${CIRCLE_BUILD_NUM}_MySQL" -DSITE="CircleCI" ..
    - cd _build && ctest --extra-verbose --no-compress-output --track Continuous --test-action Test --test-action Submit .
    - rm -rf _build/*
    - cd _build && cmake -DCDASH_TESTING_RENAME_LOGS=true -DCDASH_DIR_NAME=cdash -DCDASH_DB_TYPE=pgsql -DCDASH_DB_LOGIN=ubuntu -DBUILDNAME="${CIRCLE_BRANCH}_${CIRCLE_BUILD_NUM}_Postgres" -DSITE="CircleCI" -DCDASH_USE_PROTRACTOR=OFF ..
    - cd _build && ctest --extra-verbose --no-compress-output --track Continuous --test-action Test --test-action Submit .

  post:
    - cp _build/Testing/Temporary/* $CIRCLE_ARTIFACTS
    - cp log/* $CIRCLE_ARTIFACTS
    - mkdir -p $CIRCLE_TEST_REPORTS/junit/
    - xsltproc tests/circle/conv.xsl _build/Testing/`head -n 1 < _build/Testing/TAG`/Test.xml > $CIRCLE_TEST_REPORTS/junit/Test.xml
