dist: trusty

language: python

git:
  depth: 1

cache:
  - pip

addons:
  hosts: test_site
  mariadb: 10.3

jobs:
  include:
  - name: "Python 2.7 Server Side Test"
    python: 2.7
    script: bench --site test_site run-tests --app erpnext --coverage

  - name: "Python 3.6 Server Side Test"
    python: 3.6
    script: bench --site test_site run-tests --app erpnext --coverage

  - name: "Python 2.7 Patch Test"
    python: 2.7
    before_script:
      - wget http://build.erpnext.com/20171108_190013_955977f8_database.sql.gz
      - bench --site test_site --force restore ~/frappe-bench/20171108_190013_955977f8_database.sql.gz
    script: bench --site test_site migrate

  - name: "Python 3.6 Patch Test"
    python: 3.6
    before_script:
      - wget http://build.erpnext.com/20171108_190013_955977f8_database.sql.gz
      - bench --site test_site --force restore ~/frappe-bench/20171108_190013_955977f8_database.sql.gz
    script: bench --site test_site migrate

install:
  - cd ~
  - nvm install 10

  - git clone https://github.com/frappe/bench --depth 1
  - pip install -e ./bench

  - git clone https://github.com/frappe/frappe --branch $TRAVIS_BRANCH --depth 1
  - bench init --skip-assets --frappe-path ~/frappe --python $(which python) frappe-bench

  - mkdir ~/frappe-bench/sites/test_site
  - cp -r $TRAVIS_BUILD_DIR/.travis/site_config.json ~/frappe-bench/sites/test_site/

  - mysql -u root -e "SET GLOBAL character_set_server = 'utf8mb4'"
  - mysql -u root -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"

  - mysql -u root -e "CREATE DATABASE test_frappe"
  - mysql -u root -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"
  - mysql -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'"

  - mysql -u root -e "UPDATE mysql.user SET Password=PASSWORD('travis') WHERE User='root'"
  - mysql -u root -e "FLUSH PRIVILEGES"

  - wget -O /tmp/wkhtmltox.tar.xz https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
  - tar -xf /tmp/wkhtmltox.tar.xz -C /tmp
  - sudo mv /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
  - sudo chmod o+x /usr/local/bin/wkhtmltopdf
  - sudo apt-get install libcups2-dev

  - cd ~/frappe-bench

  - sed -i 's/watch:/# watch:/g' Procfile
  - sed -i 's/schedule:/# schedule:/g' Procfile
  - sed -i 's/socketio:/# socketio:/g' Procfile
  - sed -i 's/redis_socketio:/# redis_socketio:/g' Procfile

  - bench get-app erpnext $TRAVIS_BUILD_DIR
  - bench start &
  - bench --site test_site reinstall --yes

after_script:
  - pip install python-coveralls
  - coveralls -b apps/erpnext -d ../../sites/.coverage
