dist: bionic
os: linux
language: php

addons:
  postgresql: "9.5"
  apt:
    update: true
    packages:
      - libvulkan1
      - libu2f-udev

sudo: required

php:
  - 8.1.0
  - 8.2.0
env:
  - APPLICATION=ojs BRANCH=main TEST=mysql
  - APPLICATION=ojs BRANCH=main TEST=pgsql

install:
  # Prepare OJS/OMP environment
  - git clone -b ${BRANCH} https://github.com/pkp/${APPLICATION} ~/${APPLICATION}
  - cd ~/${APPLICATION}
  - git submodule update --init --recursive
  - source lib/pkp/tools/travis/prepare-tests.sh
  - lib/pkp/tools/travis/prepare-webserver.sh
  # Build/install dependencies
  - lib/pkp/tools/travis/install-composer-dependencies.sh
  - npm i g -npm && npm install && npm run build
  # Install this plugin's source
  - cp -r ${TRAVIS_BUILD_DIR} ~/${APPLICATION}/plugins/generic/pluginTemplate

script:
  # Install data set
  - git clone https://github.com/pkp/datasets
  - cp datasets/${APPLICATION}/${BRANCH}/${TEST}/config.inc.php .
  - cp -rf datasets/${APPLICATION}/${BRANCH}/${TEST}/public/* public/
  - cp -rf datasets/${APPLICATION}/${BRANCH}/${TEST}/files/* files/
  - cat datasets/${APPLICATION}/${BRANCH}/${TEST}/database.sql | ./datasets/tools/dbclient.sh
  - php lib/pkp/tools/installPluginVersion.php plugins/generic/pluginTemplate/version.xml

  # Run Cypress tests
  - $(npm bin)/cypress run --config '{"specPattern":["plugins/generic/pluginTemplate/cypress/tests/functional/*.cy.js"]}'

after_failure:
  - cat error.log
  - sudo apt-get install sharutils
  - tar cz cypress/screenshots | uuencode /dev/stdout
