dist: xenial
sudo: false
notifications:
  email:
    - me+tv@zammad.com
env:
  - DB=mysql
  - DB=postgresql
addons:
  postgresql: "9.4"
  apt:
    packages:
      - autoconf
      - automake
      - autotools-dev
      - bison
      - build-essential
      - curl
      - git-core
      - libffi-dev
      - libgdbm-dev
      - libgmp-dev
      - libmysqlclient-dev
      - libncurses5-dev
      - libreadline-dev
      - libsqlite3-dev
      - libssl-dev
      - libtool
      - libxml2-dev
      - libxslt1-dev
      - libyaml-0-2
      - libyaml-dev
      - mysql-client-5.7
      - mysql-client-core-5.7
      - mysql-server-5.7
      - patch
      - pkg-config
      - postfix
      - sqlite3
      - zlib1g-dev
services:
  - postgresql
  - mysql
language: ruby
rvm:
  - 2.4.4
before_install:
  - gem update --system # Due to: https://github.com/travis-ci/travis-ci/issues/8978
  - git fetch --unshallow
  - if [ "${DB}" = "mysql" ]; then mysql -u root -e "CREATE USER 'some_user'@'localhost' IDENTIFIED BY 'some_pass';"; fi
  - if [ "${DB}" = "mysql" ]; then mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'some_user'@'localhost';"; fi
  - if [ "${DB}" = "mysql" ]; then cp contrib/travis-ci.org/database.yml.test-mysql config/database.yml; fi
  - if [ "${DB}" = "postgresql" ]; then psql -c 'create database zammad_test;' -U postgres; fi
  - if [ "${DB}" = "postgresql" ]; then cp contrib/travis-ci.org/database.yml.test-postgresql config/database.yml; fi
  - export RAILS_ENV=test
  - export ZAMMAD_VERSION=$(git describe --tags | sed -e 's/-[a-z0-9]\{8,\}.*//g')
install:
  - if [ "${DB}" = "mysql" ]; then bundle install --without postgres; fi
  - if [ "${DB}" = "postgresql" ]; then bundle install; fi
script:
  - bundle exec rubocop
  - rake db:create
  - rake db:migrate
  - rake db:seed
  - bundle exec rspec -t ~type:system
  - bundle exec rake db:environment:set RAILS_ENV=test
  - rake db:reset
  - rake test:units
  - ruby -I test/ test/integration/object_manager_test.rb
  - ruby -I test/ test/integration/package_test.rb
after_success:
  - if [ "${DB}" = "mysql" ]; then contrib/travis-ci.org/trigger_docker_image_build.sh; fi
  - if [ "${DB}" = "mysql" ]; then contrib/travis-ci.org/trigger_docker_image_compose_build.sh; fi
  - if [ "${DB}" = "mysql" ]; then contrib/travis-ci.org/trigger_docker_image_univention_build.sh; fi
