#
# Travis CI config file
#

language: php
php:
  - '7.4'
  - '7.3'
  - '7.2'

#env:
#  - DB=mysql
#  - DB=mariadb

cache:
  # Cache lives for 10 min
  # Default of 3m might not be long enough for all the runs
  timeout: 600
  directories:
  - "$HOME/.composer/cache"
  - "$HOME/.npm"

services:
- mysql

#addons:
#  mariadb: '10.2'

install:
  - php --version
  - mysql --version
  - composer install --dev --no-interaction --verbose
  - npm i tar-to-zip -g
  - cp .travis/env.travis.php env.php
  - cp .travis/phpunit.travis.xml phpunit.xml

before_script:
  - php artisan database:create --reset
  - php artisan migrate:refresh --seed

script:
  - vendor/bin/php-cs-fixer fix --config=.php_cs -v --dry-run --diff --using-cache=no
  - vendor/bin/phpunit --debug --verbose

after_failure:
  - cat storage/logs/*.log

# Refer to: https://github.com/doctrine/dbal/blob/master/.travis.yml#L39
jobs:
  include:
    # Different test stages
#    - stage: Test
#      name: PHP 7.2 + MySQL 5.7
#      php: 7.2
#      env: DB=mysql
#      services:
#        - mysql
#    - stage: Test
#      name: PHP 7.3 + MySQL 5.7
#      php: 7.3
#      env: DB=mysql
#      services:
#        - mysql
#    - stage: Test
#      name: PHP 7.4 + MySQL 5.7
#      php: 7.4
#      env: DB=mysql
#      services:
#        - mysql
#    - stage: Test
#      name: PHP 7.2 + MariaDB 10.1
#      php: 7.2
#      env: DB=mariadb
#      addons:
#        mariadb: '10.1'
#    - stage: Test
#      name: PHP 7.3 + MariaDB 10.1
#      php: 7.3
#      env: DB=mariadb
#      addons:
#        mariadb: '10.1'
#    - stage: Test
#      name: PHP 7.4 + MariaDB 10.1
#      php: 7.4
#      env: DB=mariadb MARIADB_VERSION=10.1
#      addons:
#        mariadb: '10.1'
#    - stage: Test
#      name: PHP 7.2 + MariaDB 10.2
#      php: 7.2
#      env: DB=mariadb
#      addons:
#        mariadb: '10.2'
#    - stage: Test
#      name: PHP 7.3 + MariaDB 10.3
#      php: 7.3
#      env: DB=mariadb
#      addons:
#        mariadb: '10.2'
#    - stage: Test
#      name: PHP 7.4 + MariaDB 10.2
#      php: 7.4
#      env: DB=mariadb
#      addons:
#        mariadb: '10.2'
#    - stage: Test
#      name: PHP 7.2 + MariaDB 10.3
#      php: 7.2
#      env: DB=mariadb
#      addons:
#        mariadb: '10.3'
#    - stage: Test
#      name: PHP 7.3 + MariaDB 10.3
#      php: 7.3
#      env: DB=mariadb
#      addons:
#        mariadb: '10.3'
#    - stage: Test
#      name: PHP 7.4 + MariaDB 10.3
#      php: 7.4
#      env: DB=mariadb
#      addons:
#        mariadb: '10.3'

    # Just packages up a release
    - stage: package
      script: skip
      before_deploy:
        - curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/6b10798/install | bash

      # Configure the conditional deployment
      # https://docs.travis-ci.com/user/deployment/#examples-of-conditional-deployment
      deploy:
        - provider: script
          skip_cleanup: true
          script: ./.travis/deploy_script.sh
          on:
            all_branches: true
            repo: nabeelio/phpvms
            php: '7.4'
            tags: false

    # RELEASE STAGE
    # Only runs when there's a tag applied to this release (tag should be the version)
    # This uses Github Releases and posts it there (provider: releases)
    # https://docs.travis-ci.com/user/deployment/releases
    - stage: release
      script: skip
      before_deploy:
        - curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/6b10798/install | bash
        - ./.travis/deploy_script.sh
      deploy:
        provider: releases
        skip_cleanup: true
        api_key: $GITHUB_TOKEN
        file_glob: true
        file: build/*
        on:
          tags: true
          repo: nabeelio/phpvms
          php: '7.4'
