sudo: required
if: tag IS blank

branches:
  except:
    - weblate
services:
  - docker
before_install:
  - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
  - chmod +x docker-compose
  - sudo mv docker-compose /usr/local/bin

script:
  - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
  - docker run --rm -v $(pwd):/app jekkos/composer composer install
  - docker run --rm -v $(pwd):/app jekkos/composer php bin/install.php translations develop
  - sed -i "s/'\(dev\)'/'$rev'/g" application/config/config.php
  - docker run --rm -it -v $(pwd):/app -w /app opensourcepos/node-grunt-bower
    sh -c "npm install && bower install && grunt package"
  - docker build . --target ospos -t ospos
  - docker-compose -f docker-compose.test.yml up --abort-on-container-exit
env:
  global:
  - DOCKER_COMPOSE_VERSION=1.21.1
  - TAG=$(echo ${TRAVIS_BRANCH} | sed s/feature\\///)
  - date=`date +%Y%m%d%H%M%S` && branch=${TRAVIS_BRANCH} && rev=`git rev-parse --short=6 HEAD` 
after_success:
  - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" && docker tag "ospos:latest"
    "jekkos/opensourcepos:$TAG" && docker push "jekkos/opensourcepos:$TAG"
before_deploy:
  - version=$(grep application_version application/config/config.php | sed "s/.*=\s'\(.*\)';/\1/g")
  - TRAVIS_TAG=$(echo $branch.$version)
  - git tag -f "$branch.$version"
  - sudo mv dist/opensourcepos.zip "dist/opensourcepos.$branch.$version.zip"
deploy:
  provider: releases
  file: "dist/opensourcepos.$branch.$version.zip"
  name: "OpensourcePos $version"
  release_notes_file: WHATS_NEW.txt
  prerelease: true
  skip_cleanup: true

  user: jekkos
  overwrite: true
  api_key:
    secure: Ax25mMRDfHVf/HjRwqxYJe2oMnWC4sc2aKIiUxAOviVJJSCl4GMWhcFlUNnFsDcKIg2ofEGMVD6b9cTBuOwPDvymUDFnLNCCgDWve+vRDdWaTkTipn77Qk4c9UO9VvuzlPSKopChefPHlQ0n1rEmAMiKIXuqjUlNGqybW4FLP4E=
  on:
    all_branches: true

