kind: pipeline
type: docker
name: Check messages.po

steps:
  - name: Run default Xgettext
    image: friendicaci/transifex
    commands:
      - ./bin/run_xgettext.sh

  - name: Check default
    image: friendicaci/transifex
    commands:
      - /check-messages.sh
---
kind: pipeline
type: docker
name: php7.3-lint

steps:
  - name: Test
    image: php:7.3
    commands:
      - ./bin/composer.phar run lint
---
kind: pipeline
type: docker
name: php7.4-lint

steps:
  - name: Test
    image: php:7.4
    commands:
      - ./bin/composer.phar run lint
---
kind: pipeline
type: docker
name: php8.0-lint

steps:
  - name: Test
    image: php:8.0
    commands:
      - ./bin/composer.phar run lint
---
kind: pipeline
type: docker
name: php-cs check

trigger:
  event:
    - pull_request

steps:
  - name: Restore cache
    image: meltwater/drone-cache:dev
    settings:
      backend: "filesystem"
      restore: true
      cache_key: '{{ .Repo.Name }}_phpcs_{{ arch }}_{{ os }}'
      archive_format: "gzip"
      mount:
        - '.composer'
    volumes:
      - name: cache
        path: /tmp/cache
  - name: Install dependencies
    image: composer
    commands:
      - export COMPOSER_HOME=.composer
      - ./bin/composer.phar run cs:install
  - name: Rebuild cache
    image: meltwater/drone-cache:dev
    settings:
      backend: "filesystem"
      rebuild: true
      cache_key: '{{ .Repo.Name }}_phpcs_{{ arch }}_{{ os }}'
      archive_format: "gzip"
      mount:
        - '.composer'
    volumes:
      - name: cache
        path: /tmp/cache
  - name: Run coding standards check
    image: friendicaci/php-cs
    commands:
      - export CHANGED_FILES="$(git diff --name-status ${DRONE_COMMIT_BEFORE}..${DRONE_COMMIT_AFTER} | grep ^A | cut -f2)"
      - /check-php-cs.sh

volumes:
  - name: cache
    host:
      path: /tmp/drone-cache
---
kind: pipeline
type: docker
name: php7.3-mariadb

steps:
  - name: Restore cache
    image: meltwater/drone-cache:dev
    settings:
      backend: "filesystem"
      restore: true
      cache_key: '{{ .Repo.Name }}_php73_{{ arch }}_{{ os }}'
      archive_format: "gzip"
      mount:
        - '.composer'
    volumes:
      - name: cache
        path: /tmp/cache
  - name: Composer install
    image: friendicaci/php7.3:php7.3.28
    commands:
      - export COMPOSER_HOME=.composer
      - ./bin/composer.phar validate
      - ./bin/composer.phar install --prefer-dist
  - name: Rebuild cache
    image: meltwater/drone-cache:dev
    settings:
      backend: "filesystem"
      rebuild: true
      cache_key: '{{ .Repo.Name }}_php73_{{ arch }}_{{ os }}'
      archive_format: "gzip"
      mount:
        - '.composer'
    volumes:
      - name: cache
        path: /tmp/cache
  - name: Test Friendica
    image: friendicaci/php7.3:php7.3.28
    environment:
      MYSQL_HOST: "mariadb"
      MYSQL_PORT: 3306
      MYSQL_DATABASE: "test"
      MYSQL_PASSWORD: "test"
      MYSQL_USER: "test"
      REDIS_HOST: "redis"
      MEMCACHED_HOST: "memcached"
      MEMCACHE_HOST: "memcached"
    commands:
      - cp config/local-sample.config.php config/local.config.php
      - if ! bin/wait-for-connection $MYSQL_HOST $MYSQL_PORT 300; then echo "[ERROR] Waited 300 seconds, no response" >&2; exit 1; fi
      - mysql -h$MYSQL_HOST -P$MYSQL_PORT -p$MYSQL_PASSWORD -u$MYSQL_USER $MYSQL_DATABASE < database.sql
      - phpunit --configuration tests/phpunit.xml

services:
  - name: mariadb
    image: mariadb:latest
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "true"
      MYSQL_DATABASE: "test"
      MYSQL_PASSWORD: "test"
      MYSQL_USER: "test"
    tmpfs:
      - /var/lib/mysql

  - name: memcached
    image: memcached

  - name: redis
    image: redis

volumes:
  - name: cache
    host:
      path: /tmp/drone-cache
---
kind: pipeline
type: docker
name: php7.4-mariadb

steps:
  - name: Restore cache
    image: meltwater/drone-cache:dev
    settings:
      backend: "filesystem"
      restore: true
      cache_key: '{{ .Repo.Name }}_php74_{{ arch }}_{{ os }}'
      archive_format: "gzip"
      mount:
        - '.composer'
    volumes:
      - name: cache
        path: /tmp/cache
  - name: Composer install
    image: friendicaci/php7.4:php7.4.18
    commands:
      - export COMPOSER_HOME=.composer
      - ./bin/composer.phar validate
      - ./bin/composer.phar install --prefer-dist
  - name: Rebuild cache
    image: meltwater/drone-cache:dev
    settings:
      backend: "filesystem"
      rebuild: true
      cache_key: '{{ .Repo.Name }}_php74_{{ arch }}_{{ os }}'
      archive_format: "gzip"
      mount:
        - '.composer'
    volumes:
      - name: cache
        path: /tmp/cache
  - name: Test Friendica
    image: friendicaci/php7.4:php7.4.18
    environment:
      MYSQL_HOST: "mariadb"
      MYSQL_PORT: 3306
      MYSQL_DATABASE: "test"
      MYSQL_PASSWORD: "test"
      MYSQL_USER: "test"
      REDIS_HOST: "redis"
      MEMCACHED_HOST: "memcached"
      MEMCACHE_HOST: "memcached"
      XDEBUG_MODE: "coverage"
    commands:
      - phpenmod xdebug
      - cp config/local-sample.config.php config/local.config.php
      - if ! bin/wait-for-connection $MYSQL_HOST $MYSQL_PORT 300; then echo "[ERROR] Waited 300 seconds, no response" >&2; exit 1; fi
      - mysql -h$MYSQL_HOST -P$MYSQL_PORT -p$MYSQL_PASSWORD -u$MYSQL_USER $MYSQL_DATABASE < database.sql
      - phpunit --configuration tests/phpunit.xml --coverage-clover clover.xml
  - name: Codecov
    image: plugins/codecov
    when:
      repo:
        - friendica/friendica
    settings:
      token:
        from_secret: codecov-token
      files:
        - clover.xml

services:
  - name: mariadb
    image: mariadb:latest
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "true"
      MYSQL_DATABASE: "test"
      MYSQL_PASSWORD: "test"
      MYSQL_USER: "test"
    tmpfs:
      - /var/lib/mysql

  - name: memcached
    image: memcached

  - name: redis
    image: redis

volumes:
  - name: cache
    host:
      path: /tmp/drone-cache
---
kind: pipeline
type: docker
name: php8.0-mariadb

steps:
  - name: Restore cache
    image: meltwater/drone-cache:dev
    settings:
      backend: "filesystem"
      restore: true
      cache_key: '{{ .Repo.Name }}_php80_{{ arch }}_{{ os }}'
      archive_format: "gzip"
      mount:
        - '.composer'
    volumes:
      - name: cache
        path: /tmp/cache
  - name: Composer install
    image: friendicaci/php8.0:php8.0.5
    commands:
      - export COMPOSER_HOME=.composer
      - ./bin/composer.phar validate
      - ./bin/composer.phar install --prefer-dist
  - name: Rebuild cache
    image: meltwater/drone-cache:dev
    settings:
      backend: "filesystem"
      rebuild: true
      cache_key: '{{ .Repo.Name }}_php80_{{ arch }}_{{ os }}'
      archive_format: "gzip"
      mount:
        - '.composer'
    volumes:
      - name: cache
        path: /tmp/cache
  - name: Test Friendica
    image: friendicaci/php8.0:php8.0.5
    environment:
      MYSQL_HOST: "mariadb"
      MYSQL_PORT: 3306
      MYSQL_DATABASE: "test"
      MYSQL_PASSWORD: "test"
      MYSQL_USER: "test"
      REDIS_HOST: "redis"
      MEMCACHED_HOST: "memcached"
      MEMCACHE_HOST: "memcached"
    commands:
      - cp config/local-sample.config.php config/local.config.php
      - if ! bin/wait-for-connection $MYSQL_HOST $MYSQL_PORT 300; then echo "[ERROR] Waited 300 seconds, no response" >&2; exit 1; fi
      - mysql -h$MYSQL_HOST -P$MYSQL_PORT -p$MYSQL_PASSWORD -u$MYSQL_USER $MYSQL_DATABASE < database.sql
      - phpunit --configuration tests/phpunit.xml

services:
  - name: mariadb
    image: mariadb:latest
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "true"
      MYSQL_DATABASE: "test"
      MYSQL_PASSWORD: "test"
      MYSQL_USER: "test"
    tmpfs:
      - /var/lib/mysql

  - name: memcached
    image: memcached

  - name: redis
    image: redis

volumes:
  - name: cache
    host:
      path: /tmp/drone-cache