language: php

services:
    - rabbitmq
    - redis

# used for HHVM
addons:
    apt:
        packages:
            - tidy

# cache vendor dirs
cache:
    apt: true
    directories:
        - vendor
        - $HOME/.composer/cache
        - node_modules
        - $HOME/.npm
        - $HOME/.yarn-cache

php:
    - 5.6
    - 7.0
    - 7.1
    - 7.2
    - nightly

node_js:
    - "5"

env:
    - DB=mysql
    - DB=pgsql
    - DB=sqlite

matrix:
    fast_finish: true
    include:
        - php: 7.0
          env: CS_FIXER=run VALIDATE_TRANSLATION_FILE=run ASSETS=build DB=sqlite
    allow_failures:
        - php: nightly

# exclude v1 branches
branches:
    except:
        - legacy

before_install:
    - if [[ $TRAVIS_REPO_SLUG = wallabag/wallabag ]]; then cp .composer-auth.json ~/.composer/auth.json; fi;

install:
    - if [[ $ASSETS = build ]]; then source ~/.nvm/nvm.sh && nvm install 6.10; fi;
    - if [[ $ASSETS = build ]]; then npm install -g yarn@latest; fi;
    - if [[ $ASSETS = build ]]; then yarn install; fi;

before_script:
    - PHP=$TRAVIS_PHP_VERSION
    - if [[ ! $PHP = hhvm* ]]; then echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi;
    # xdebug isn't enable for PHP 7.1
    - if [[ ! $PHP = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi
    - composer self-update --no-progress
    - if [[ $DB = pgsql ]]; then psql -c 'create database wallabag_test;' -U postgres; fi;
    # increase swap to avoid "proc_open(): fork failed - Cannot allocate memory"
    # this should be removed when no more PHP 5 build will be defined
    - sudo swapon -s
    - sudo fallocate -l 4G /swapfile
    - sudo chmod 600 /swapfile
    - sudo mkswap /swapfile
    - sudo swapon /swapfile
    - sudo swapon -s

script:
    - travis_wait bash composer install -o --no-interaction --no-progress --prefer-dist
    - echo "travis_fold:start:prepare"
    - make prepare DB=$DB
    - echo "travis_fold:end:prepare"

    - echo "travis_fold:start:fixtures"
    - php bin/console doctrine:fixtures:load --no-interaction --env=test
    - echo "travis_fold:end:fixtures"

    - if [[ $VALIDATE_TRANSLATION_FILE = '' ]]; then ./bin/simple-phpunit -v ; fi;
    - if [[ $CS_FIXER = run ]]; then php bin/php-cs-fixer fix --verbose --dry-run ; fi;
    - if [[ $VALIDATE_TRANSLATION_FILE = run ]]; then php bin/console lint:yaml src/Wallabag/CoreBundle/Resources/translations -v ; fi;
    - if [[ $VALIDATE_TRANSLATION_FILE = run ]]; then php bin/console lint:yaml app/Resources/CraueConfigBundle/translations -v ; fi;
    - if [[ $VALIDATE_TRANSLATION_FILE = run ]]; then php bin/console lint:yaml src/Wallabag/UserBundle/Resources/translations -v ; fi;
    - if [[ $ASSETS = build ]]; then yarn run build:prod; fi;
