image: eriksencosta/php-dev

cache:
  paths:
  - .composercache

stages:
  - test
  - build
  - deploy

test:5.3:
  stage: test
  before_script:
    - composer config cache-files-dir .composercache
  script:
    - . build-tools/prepare-env.sh 5.3
    - phpunit --bootstrap vendor/autoload.php --no-configuration test/

test:5.4:
  stage: test
  before_script:
    - composer config cache-files-dir .composercache
  script:
    - . build-tools/prepare-env.sh 5.4
    - phpunit --bootstrap vendor/autoload.php --no-configuration test/

test:5.5:
  stage: test
  before_script:
    - composer config cache-files-dir .composercache
  script:
    - . build-tools/prepare-env.sh 5.5
    - phpunit --bootstrap vendor/autoload.php --no-configuration test/

test:5.6:
  stage: test
  before_script:
    - composer config cache-files-dir .composercache
  script:
    - . build-tools/prepare-env.sh 5.6
    - phpunit --bootstrap vendor/autoload.php --no-configuration test/

build:
  stage: build
  before_script:
    - composer config cache-files-dir .composercache
  script:
    - . build-tools/prepare-env.sh 5.6
    - php build-tools/phar.php
  only:
    - master
    - develop
    - tags
  artifacts:
      paths:
        - target

deploy:packagist:
  stage: deploy
  script:
    - curl -XPOST -H'content-type:application/json' 'https://packagist.org/api/update-package?username='$PACKAGIST_USERNAME'&apiToken='$PACKAGIST_API_KEY -d'{"repository":{"url":"'$PACKAGIST_URL'"}}'
  only:
    - master
    - develop
    - tags

pages:
  image: node:8.9.0
  before_script:
    - npm install gitbook-cli -g -q # install gitbook
    - gitbook fetch latest # fetch latest stable version
  script:
    - gitbook build . public
  artifacts:
    paths:
      - public
    expire_in: 15m
  only:
    - master
