os: linux
dist: xenial

services:
  - docker
  - xvfb

language: ruby
rvm:
  - 2.7.2
cache:
  bundler: true
  directories:
    - node_modules # NPM and yarn packages

env:
  global:
    - secure: "DkOGGPCrRgV08KGgav3Bl+keZQqb11TINQRVQS2aeMaYR5GW7Rt9zEcZzhUE0JdKVVOvm4Cclft7BO4OyMd6Cq9XnZkOOHY+Yn8Qv923761SKrRgkGUkO8eeVKMawAA8lS53XGrMZWCP2xaLsLQYq8xzinnE3GqstoZJaHLnqVs="

addons:
  postgresql: "10"
  firefox: "latest-esr"

before_install:
  - sudo sed -i '/ExecStart=\/usr\/bin\/dockerd -H fd:\/\//c\ExecStart=\/usr\/bin\/dockerd' /lib/systemd/system/docker.service
  - sudo systemctl daemon-reload
  - "echo '{\"hosts\": [\"tcp://127.0.0.1:2376\", \"unix:///var/run/docker.sock\"], \"iptables\": false}' | sudo tee /etc/docker/daemon.json  > /dev/null"
  - sudo service docker restart
  - sleep 5
  - docker pull openhpi/co_execenv_python
  - docker pull openhpi/co_execenv_java
  - mkdir ~/geckodriver
  - wget -O ~/geckodriver/download.tar.gz https://github.com/mozilla/geckodriver/releases/download/v0.27.0/geckodriver-v0.27.0-linux64.tar.gz
  - tar -xvzf ~/geckodriver/download.tar.gz -C ~/geckodriver/
  - rm ~/geckodriver/download.tar.gz
  - chmod +x ~/geckodriver/geckodriver
  - export PATH=~/geckodriver/:$PATH
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
  - chmod +x ./cc-test-reporter

install:
  - bundle install --jobs=3 --retry=3 --deployment --path=${BUNDLE_PATH:-vendor/bundle}
  - nvm install stable
  - nvm use stable
  - yarn install

before_script:
  - cp .rspec.travis .rspec
  - cp config/action_mailer.yml.travis config/action_mailer.yml
  - cp config/code_ocean.yml.travis config/code_ocean.yml
  - cp config/database.yml.travis config/database.yml
  - cp config/secrets.yml.travis config/secrets.yml
  - cp config/docker.yml.erb.travis config/docker.yml.erb
  - cp config/mnemosyne.yml.travis config/mnemosyne.yml
  - psql --command='CREATE DATABASE travis_ci_test;' --username=postgres
  - bundle exec rake db:schema:load RAILS_ENV=test
  - ./cc-test-reporter before-build

script: bundle exec rspec --color --format documentation --require spec_helper --require rails_helper

after_script:
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
