sudo: required
language: node_js
node_js: '8'

matrix:
  include:
    - os: osx
      osx_image: xcode9.0
      env:
        - ELECTRON_CACHE=$HOME/.cache/electron
        - ELECTRON_BUILDER_CACHE=$HOME/.cache/electron-builder
      install:
        - brew update
        - brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
        - brew install yarn
      addons:
        chrome: stable
    - os: linux
      dist: trusty
      language: generic
      services:
       - docker
      before_install:
        - export CHROME_BIN=chromium-browser
        - export DISPLAY=:99.0
        - sh -e /etc/init.d/xvfb start

addons:
  ssh_known_hosts:
    - the-front-end.de
    - frs.sourceforge.net
  apt:
    packages:
      - sshpass

cache:
  yarn: true
  directories:
  - node_modules
  - $HOME/.cache/electron
  - $HOME/.cache/electron-builder


before_script:
  - 'yarn global add bower gulp'
  - 'bower install'

# fixing travis; see: https://github.com/electron-userland/electron-builder/issues/2450#issuecomment-424972273
script:
  - |
    if [ "$TRAVIS_OS_NAME" == "linux" ]; then
      echo '____RUNNING DOCKER____'
      docker run $ENVS --rm \
        $(env | \
        grep -Eo '^[^\s=]*(DEBUG|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS|APPVEYOR_|CSC_|_TOKEN|_KEY|AWS_|STRIP|BUILD_)[^\s=]*' | \
        sed '/^$/d;s/^/-e /' | \
        paste -sd ' ' \
        ) \
        -v ${PWD}:/project \
        -v ~/.cache/electron:/root/.cache/electron \
        -v ~/.cache/electron-builder:/root/.cache/electron-builder \
        electronuserland/builder:wine-chrome \
        /bin/bash -c "echo '____DOCKER_INNER_START____' && ls -l && yarn global add bower gulp && yarn --link-duplicates --pure-lockfile && yarn run distLinuxAndWindows && ls -l ./dist"
    else
      yarn install && yarn add 7zip-bin-mac && yarn run pub
    fi

after_success:
  - 'echo "DIST-RESULT:"'
  - 'ls -l ./dist'
  - |
    if [ -n "$TRAVIS_TAG" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
      sshpass -p "$DEPLOY_PASS" rsync -avz ./app/ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/app
      openssl aes-256-cbc -K $encrypted_c04542ca1075_key -iv $encrypted_c04542ca1075_iv -in .snapcraft/travis_snapcraft.cfg -out .snapcraft/snapcraft.cfg -d
      docker run -v $(pwd):$(pwd) -t snapcore/snapcraft sh -c "apt update -qq && cd $(pwd) && snapcraft push ./dist/*.snap --release stable"
    fi
  - |
    if [ -n "$TRAVIS_TAG" ]; then
      echo "UPLOADING BINARIES:"
      rename "s/[0-9]+\.[0-9]+\.[0-9]+/latest/" ./dist/super*
      rename "s/\s+/_/g" ./dist/super*
      echo "RENAMED-DIST-RESULT:"
      ls -l ./dist
      sshpass -p "$DEPLOY_PASS" rsync -avz ./app/ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/app
      sshpass -p "$DEPLOY_PASS" scp dist/super* $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/downloads'
    fi
  - |
    if [ -n "$TRAVIS_TAG" ] && [ "$TRAVIS_OS_NAME" == "osx" ]; then
      brew update
      brew install vitorgalvao/tiny-scripts/cask-repair
      openssl aes-256-cbc -K $encrypted_c04542ca1075_key -iv $encrypted_c04542ca1075_iv -in build/hub.enc -out ~/.config/hub -d
      cask-repair -b -v $TRAVIS_TAG superproductivity
    fi

#  - 'sshpass -p "$SFG_DEPLOY_PASS" scp dist/superProductivity* $SFG_DEPLOY_USER@$SFG_DEPLOY_HOST:$SFG_DEPLOY_PATH/downloads'
#  - 'sshpass -p "$SFG_DEPLOY_PASS" scp dist/superproductivity* $SFG_DEPLOY_USER@$SFG_DEPLOY_HOST:$SFG_DEPLOY_PATH/downloads'
