language: php

sudo: required

php:
  - 7.2

env:
  matrix:
    - DB_DSN="mysql:host=127.0.0.1;port=8081;dbname=ulogger;charset=utf8"
    - DB_DSN="pgsql:host=127.0.0.1;port=8081;dbname=ulogger"
    - DB_DSN="sqlite:/tmp/data/sqlite/ulogger.db"
  global:
    - DB_USER=ulogger
    - DB_PASS=secret2
    - ULOGGER_URL="http://127.0.0.1:8080"
    - secure: "fajUnR8y0+EkMLHTpDpqEsNc2UWSNQchy9Vw6bP+AVEdLnU2tdc9ZTrWfHx+vQdvo6xd/eY6TJm4cWtesG8inFhZHSzPYeeWX8xDto+fPohjTBJggvkGmhO6xYidjwTL2niKsHOVPh0ja55eCzp/DYWX/jVUNWTFsFiLwOlrZrhhoZs3JNldiPOUAgroR5SvlW1TZ1MgWO0ZLXpjpRhG3w42pRM75pzGpfwnjeA6BYCO8j/NXCiuCo9YTTGR/zM5yfYuTIxviIVcRw2Y6SQrh/nzQw3bCB7y9PvtDt/eNAzJVO8GQOQeN7cgY4kU/NMMlIxwL1nUDyaZj1+KxZj3BsG/pPxJblAE28yDdFlpTeolHuFDZpOXvbD8EnUYjk+NXUDe73tYPZT/iiojMBJ4ja+SCnq8VYvATjOHiAqDmlrrEWWwBC+i2laFSVBMJROvg+Ga85vmyV6/nvSd0fRJzrGLyeyGqSBwbGk2lS8HXPcDc5Bfn6v9sP0Sks7xXvW9A6zc262GRcSZqlvmUpbp7VteJigFNv3t3vjJRNlspvpzpPqHGKDJ3UCgt2i7+ve8zqFfevDUiDBKkMEPhIQdXPtqhzHMq4GXMDpGwq9DWcR0m/ZQISfS2K1ONnpv+4ShkGaFFk7o435GcIkitMAxRvpcA4m92l0POuqAbrXPaUU="

services:
  - docker

before_install:
  - echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
  - |
    case "$DB_DSN" in
      mysql*)
        docker build -t ulogger --build-arg DB_DRIVER=mysql .
        docker run -d --name ulogger -p 8080:80 -p 8081:3306 --expose 3306 -e ULOGGER_ENABLE_SETUP=1 ulogger
        ;;
      pgsql*)
        docker build -t ulogger --build-arg DB_DRIVER=pgsql .
        docker run -d --name ulogger -p 8080:80 -p 8081:5432 --expose 5432 -e ULOGGER_ENABLE_SETUP=1 ulogger
        ;;
      sqlite*)
        sudo apt-get update -qq
        sudo apt-get install sqlite3
        mkdir -p /tmp/data/sqlite
        sqlite3 -init scripts/ulogger.sqlite /tmp/data/sqlite/ulogger.db .exit
        sudo chown -R travis:travis /tmp/data
        sudo chmod -R 777 /tmp/data
        docker build -t ulogger --build-arg DB_DRIVER=sqlite .
        docker run -d --name ulogger -p 8080:80 -v /tmp/data:/data -e ULOGGER_ENABLE_SETUP=1 ulogger
        ;;
    esac
  - composer install
  - until netstat -atn 2>/dev/null | grep '8080.*LISTEN'; do sleep 1; done

after_success:
- |
  if [ ! -z "$TRANSIFEX_PASSWORD" ]; then
    pip install --user virtualenv
    virtualenv ~/env
    source ~/env/bin/activate
    pip install transifex-client
    echo -e "[https://www.transifex.com]\nhostname = https://www.transifex.com\nusername = api\npassword = ${TRANSIFEX_PASSWORD}\n" > ~/.transifexrc
    tx push -s --no-interactive
  fi


script:
  - ./vendor/bin/phpunit  -c .tests/phpunit.xml

addons:
  coverity_scan:
    project:
      name: "bfabiszewski/ulogger-server"
      description: "Build submitted via Travis CI"
    notification_email: scan.coverity@fabiszewski.net
    build_command_prepend: ""
    build_command: "--no-command --fs-capture-search ./ --fs-capture-search-exclude-regex vendor/ --fs-capture-search-exclude-regex .tests/ --fs-capture-search-exclude-regex config.php --fs-capture-search-exclude-regex .docker/"
    branch_pattern: master
