language: php
sudo: false

cache:
  directories:
    - $HOME/.composer/cache

php:
  - 7.1
  - 7.0
  - 5.6

env:
  global:
    - MOODLE_BRANCH=MOODLE_32_STABLE
  matrix:
    - DB=pgsql
#   - DB=mysqli

before_install:
  - echo $TRAVIS_PHP_VERSION
  - echo "Travis tag $TRAVIS_TAG"
  - echo "Travis branch $TRAVIS_BRANCH"
  - composer install --no-interaction
  - phpenv config-rm xdebug.ini
  - nvm install 8
  - cd ../..
  - composer selfupdate
  - composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2
  - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"

install:
  - moodle-plugin-ci install

script:
# - moodle-plugin-ci phplint
# - moodle-plugin-ci phpcpd
# - moodle-plugin-ci phpmd
# - moodle-plugin-ci codechecker
  - moodle-plugin-ci validate
  - moodle-plugin-ci savepoints
# - moodle-plugin-ci mustache
# - moodle-plugin-ci grunt
  - moodle-plugin-ci phpunit
# - moodle-plugin-ci behat

  # run codechecker without the vendor/ directory
  - rm -rf "$(find -type d -name xapi)/vendor"
  - moodle-plugin-ci codechecker
  - cd $TRAVIS_BUILD_DIR

after_success:
  - if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then
    npm install;
    export BUILD_LEADER_ID=1;
    npm run semantic-release;
    fi

before_deploy:
  - sh ./scripts/generateVersionFile.sh
  - sh ./scripts/generateZipFile.sh

deploy:
  provider: releases
  api_key: $GH_TOKEN
  file: xapi.zip
  skip_cleanup: true
  on:
    tags: true
    php: 7.1
