dist: bionic
language: php
php:
  - 7.2
  - 7.3
  - 7.4

services:
  - mysql
  - postgresql

env:
  global:
  - CORE_BRANCH=stable19
  - DB=mysql
  - LINT=false

matrix:
  include:
    - php: 7.2
      env: "DB=sqlite"
    - php: 7.3
      env: "DB=sqlite"
    - php: 7.4
      env: "DB=sqlite"
    - php: 7.3
      env: "DB=pgsql"
    - php: 7.4
      env: "DB=pgsql"
    - php: 7.3
      env: "LINT=true"
    - php: 7.3
      env: "CORE_BRANCH=stable18"
    - php: 7.4
      env: "CORE_BRANCH=master"
    - php: nightly
      env: "DB=sqlite"
  fast_finish: true
  allow_failures:
    - php: nightly
    - php: 7.4
      env: "CORE_BRANCH=master"

cache:
  yarn: true
  directories:
    - "$HOME/core/apps/bbb/node_modules"
    - "$HOME/.composer/cache/files"
    - "$HOME/.npm"

#before_script: phpenv global 7.3

before_install:
  - php --info

  # Set up DB
  - if [[ "$DB" == 'pgsql' ]]; then createuser -U travis -s oc_autotest; fi
  - if [[ "$DB" == 'mysql' ]]; then mysql -u root -e 'create database oc_autotest;'; fi
  - if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"; fi
  - if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "GRANT ALL ON oc_autotest.* TO 'oc_autotest'@'localhost';"; fi

  - composer self-update
  - yarn install
  - yarn composer:install:dev
  - cd ..
  - git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b $CORE_BRANCH core
  - mv cloud_bbb core/apps/bbb

before_script:
  # Set up core
  - php -f core/occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database $DB --database-pass=''

  # Set up app
  - php -f core/occ app:enable bbb
  # Enable app twice to check occ errors of registered commands
  - php -f core/occ app:enable bbb

  - cd core/apps/bbb

script:
  - php -v
  - yarn test
  - if [[ "$LINT" = 'true' ]]; then yarn lint; fi
  - if [[ "$LINT" = 'true' ]]; then yarn commitlint-travis; fi
