clone:
  git:
    image: registry.fpfis.eu/drone-plugins/git:next
    when:
      event: [ push, pull_request, tag ]
  git:
    image: registry.fpfis.eu/drone-plugins/git
    when:
      event: [ deployment ]

workspace:
  base: /test
  path: oe_whitelabel

services:
  web:
    image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
    environment:
      - DOCUMENT_ROOT=/test/oe_whitelabel
  mysql:
    image: registry.fpfis.eu/fpfis/sql:percona-5.7
    command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_DATABASE=drupal
  sparql:
    image: registry.fpfis.eu/openeuropa/triple-store-dev
    pull: true
    environment:
      - SPARQL_UPDATE=true
      - DBA_PASSWORD=dba
  selenium:
    image: registry.fpfis.eu/fpfis/selenium:standalone-chrome-3.141.59-oxygen
    environment:
      - DISPLAY=:99
      - SE_OPTS=-debug
      - DISPLAY=:99
      - SCREEN_WIDTH=1280
      - SCREEN_HEIGHT=800
      - NODE_MAX_INSTANCES=5
      - NODE_MAX_SESSION=5

pipeline:
  npm-build:
    group: prepare
    image: registry.fpfis.eu/fpfis/node:14
    commands:
      - npm install --unsafe-perm
      - NODE_ENV=production npm run production

  composer-install-highest:
    group: post-prepare
    image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
    volumes:
      - /cache:/cache
    commands:
      - composer self-update --2
      - composer install --ansi --no-progress
    when:
      matrix:
        COMPOSER_BOUNDARY: highest

  composer-update-lowest:
    group: post-prepare
    image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
    volumes:
      - /cache:/cache
    commands:
      - composer self-update --2
      - composer update --prefer-lowest --prefer-stable --ansi --no-progress
    when:
      event:
        exclude: tag
      matrix:
        COMPOSER_BOUNDARY: lowest

  site-install:
    image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
    commands:
      - while ! mysqladmin ping -h mysql --silent; do sleep 1; done
      - ./vendor/bin/run drupal:site-install
    when:
      event:
        exclude: tag

  grumphp:
    group: test
    image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
    commands:
      - ./vendor/bin/grumphp run
    when:
      event:
        exclude: tag

  phpunit:
    group: test
    image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
    commands:
      - ./vendor/bin/phpunit
    when:
      event:
        exclude: tag

  before-release:
    image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
    commands:
      - git config --global --add safe.directory /test/oe_whitelabel
      - apt-get update
      - apt-get install zip
      - ./vendor/bin/run release:create-archive --tag=${DRONE_TAG}
      - ./vendor/bin/run release:create-archive --tag=${DRONE_TAG} --zip
    when:
      event: tag
      matrix:
        COMPOSER_BOUNDARY: highest
        PHP_VERSION: 7.4

  github-release:
    image: registry.fpfis.eu/drone-plugins/github-release
    secrets: [ github_token ]
    files:
      - oe_whitelabel-${DRONE_TAG}.tar.gz
      - oe_whitelabel-${DRONE_TAG}.zip
    when:
      event: tag
      matrix:
        COMPOSER_BOUNDARY: highest
        PHP_VERSION: 7.4

matrix:
  COMPOSER_BOUNDARY:
    - lowest
    - highest
  PHP_VERSION:
    - 7.4
    - 8.0
