language: ruby
sudo: false

cache:
  directories:
    - vendor/bundle
    - /tmp/cache/unicode_conformance
    - /tmp/beanstalkd-1.10
    - node_modules
    - $HOME/.nvm

services:
  - memcached
  - redis-server

addons:
  postgresql: 10
  chrome: stable
  apt:
    sources:
      - sourceline: "ppa:mc3man/trusty-media"
      - sourceline: "ppa:ubuntuhandbook1/apps"
      - mysql-5.7-trusty
    packages:
      - ffmpeg
      - mupdf
      - mupdf-tools
      - poppler-utils
      - mysql-server
      - mysql-client
      - postgresql-10
      - postgresql-client-10

bundler_args: --jobs 3 --retry 3
before_install:
  - "rm ${BUNDLE_GEMFILE}.lock"
  - "travis_retry gem update --system"
  - "travis_retry gem install bundler"
  - "[[ -z $encrypted_0fb9444d0374_key && -z $encrypted_0fb9444d0374_iv ]] || openssl aes-256-cbc -K $encrypted_0fb9444d0374_key -iv $encrypted_0fb9444d0374_iv -in activestorage/test/service/configurations.yml.enc -out activestorage/test/service/configurations.yml -d"
  - "[[ $GEM != 'actioncable:integration' ]] || yarn install"
  - "[[ $GEM != 'actionview:ujs' ]] || nvm install node"
  - "[[ $GEM != 'actionview:ujs' ]] || node --version"
  - "[[ $GEM != 'actionview:ujs' ]] || (cd actionview && npm install)"
  - "[[ $GEM != 'railties' ]] || (curl -o- -L https://yarnpkg.com/install.sh | bash)"
  - "[[ $GEM != 'railties' ]] || export PATH=$HOME/.yarn/bin:$PATH"

before_script:
  # Set Sauce Labs username and access key. Obfuscated, purposefully not encrypted.
  # Decodes to e.g. `export VARIABLE=VALUE`
  - $(base64 --decode <<< "ZXhwb3J0IFNBVUNFX0FDQ0VTU19LRVk9YTAzNTM0M2YtZTkyMi00MGIzLWFhM2MtMDZiM2VhNjM1YzQ4")
  - $(base64 --decode <<< "ZXhwb3J0IFNBVUNFX1VTRVJOQU1FPXJ1YnlvbnJhaWxz")

script: 'ci/travis.rb'

env:
  global:
    - "JRUBY_OPTS='--dev -J-Xmx1024M'"
  matrix:
    - "GEM=actionpack,actioncable"
    - "GEM=actionmailer,activemodel,activesupport,actionview,activejob,activestorage,actionmailbox"
    - "GEM=activesupport PRESERVE_TIMEZONES=1"
    - "GEM=activerecord:sqlite3"
    - "GEM=guides"
    - "GEM=actioncable:integration"

rvm:
  - 2.5.3
  - 2.6.0
  - ruby-head

matrix:
  include:
    - rvm: 2.5.3
      env: "GEM=railties"
      sudo: required
      before_install:
        - "rm ${BUNDLE_GEMFILE}.lock"
        - "travis_retry gem update --system"
        - "travis_retry gem install bundler"
        - "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
        - "sudo service postgresql restart 10"
    - rvm: 2.6.0
      env: "GEM=railties"
      sudo: required
      before_install:
        - "rm ${BUNDLE_GEMFILE}.lock"
        - "travis_retry gem update --system"
        - "travis_retry gem install bundler"
        - "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
        - "sudo service postgresql restart 10"
    - rvm: ruby-head
      env: "GEM=railties"
      sudo: required
      before_install:
        - "rm ${BUNDLE_GEMFILE}.lock"
        - "travis_retry gem update --system"
        - "travis_retry gem install bundler"
        - "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
        - "sudo service postgresql restart 10"
    - rvm: 2.5.3
      env: "GEM=actionview:ujs"
    - rvm: 2.5.3
      sudo: required
      env: "GEM=activejob:integration"
      services:
        - memcached
        - redis-server
        - rabbitmq
      before_install:
        - sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
        - "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
        - "sudo service postgresql restart 10"
        - "[ -f /tmp/beanstalkd-1.10/Makefile ] || (curl -L https://github.com/beanstalkd/beanstalkd/archive/v1.10.tar.gz | tar xz -C /tmp)"
        - "pushd /tmp/beanstalkd-1.10 && make && (./beanstalkd &); popd"
    - rvm: 2.6.0
      sudo: required
      env: "GEM=activejob:integration"
      services:
        - memcached
        - redis-server
        - rabbitmq
      before_install:
        - sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
        - "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
        - "sudo service postgresql restart 10"
        - "[ -f /tmp/beanstalkd-1.10/Makefile ] || (curl -L https://github.com/beanstalkd/beanstalkd/archive/v1.10.tar.gz | tar xz -C /tmp)"
        - "pushd /tmp/beanstalkd-1.10 && make && (./beanstalkd &); popd"
    - rvm: ruby-head
      sudo: required
      env: "GEM=activejob:integration"
      services:
        - memcached
        - redis-server
        - rabbitmq
      before_install:
        - sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
        - "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
        - "sudo service postgresql restart 10"
        - "[ -f /tmp/beanstalkd-1.10/Makefile ] || (curl -L https://github.com/beanstalkd/beanstalkd/archive/v1.10.tar.gz | tar xz -C /tmp)"
        - "pushd /tmp/beanstalkd-1.10 && make && (./beanstalkd &); popd"
    - rvm: 2.5.3
      env: "GEM=activerecord:mysql2"
      sudo: required
      before_install:
        - "sudo mysql -e \"use mysql; update user set authentication_string='' where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;\""
        - "sudo mysql_upgrade"
        - "sudo service mysql restart"
    - rvm: 2.6.0
      env: "GEM=activerecord:mysql2"
      sudo: required
      before_install:
        - "sudo mysql -e \"use mysql; update user set authentication_string='' where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;\""
        - "sudo mysql_upgrade"
        - "sudo service mysql restart"
    - rvm: ruby-head
      env: "GEM=activerecord:mysql2"
      sudo: required
      before_install:
        - "sudo mysql -e \"use mysql; update user set authentication_string='' where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;\""
        - "sudo mysql_upgrade"
        - "sudo service mysql restart"
    - rvm: 2.5.3
      env:
        - "GEM=activerecord:mysql2 MYSQL=mariadb"
      addons:
        mariadb: 10.3
    - rvm: 2.5.3
      env:
        - "GEM=activerecord:sqlite3_mem"
    - rvm: 2.5.3
      env: "GEM=activerecord:postgresql"
      sudo: required
      before_install:
        - "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
        - "sudo service postgresql restart 10"
    - rvm: 2.6.0
      env: "GEM=activerecord:postgresql"
      sudo: required
      before_install:
        - "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
        - "sudo service postgresql restart 10"
    - rvm: ruby-head
      env: "GEM=activerecord:postgresql"
      sudo: required
      before_install:
        - "sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/10/main/postgresql.conf"
        - "sudo service postgresql restart 10"
    - rvm: jruby-head
      jdk: oraclejdk8
      env:
        - "GEM=actionpack"
    - rvm: jruby-head
      jdk: oraclejdk8
      env:
        - "GEM=actionmailer,activemodel,activejob"
  allow_failures:
    - rvm: ruby-head
    - rvm: jruby-head
    - env: "GEM=actioncable:integration"
  fast_finish: true

notifications:
  email: false
  irc:
    on_success: change
    on_failure: always
    channels:
      # "irc.freenode.org#rails-contrib"
      - secure: "QFKSOK7xQiWWqTzYfYm0XWoW7idzuxT57MBW9i9EASyRLEPuDwZEubKRP40Y7wPx7ylQd9lp6kJheeLnrDvvTjFbW3sWv9GDRl4WlOU8sG/Kv7MXAASXlDqzyJxxXTtzLeXz2iwY296kOBuKxKxl923eTvEGeocwH02QGo14LpQ="
  campfire:
    on_success: change
    on_failure: always
    rooms:
      - secure: "YA1alef1ESHWGFNVwvmVGCkMe4cUy4j+UcNvMUESraceiAfVyRMAovlQBGs6\n9kBRm7DHYBUXYC2ABQoJbQRLDr/1B5JPf/M8+Qd7BKu8tcDC03U01SMHFLpO\naOs/HLXcDxtnnpL07tGVsm0zhMc5N8tq4/L3SHxK7Vi+TacwQzI="
