language: cpp
matrix:
    include:
        - os: linux
          env: WANT_KDE=NO
          compiler: gcc
        - os: linux
          env: DEBUILD=YES
          compiler: gcc
        - os: osx
          compiler: clang
        - stage: deploy
          os: linux
          before_install:
          after_success:
          install:
              - |
                  if [[ "$TRAVIS_REPO_SLUG" == "kvirc/KVIrc" && "$TRAVIS_PULL_REQUEST" == "false" && "$TRAVIS_BRANCH" == "master" ]]; then
                    openssl aes-256-cbc -k "$KEY_SSH_GITHUB" -in .travis-github.ssh.enc -out ~/kvirc-github-key -d
                  fi
              - export KEY_SSH_GITHUB=no KEY_SSH_ARTIFACTS=no
              - sudo apt-get update
                # for ./.travis-coverity-scan.py
              - sudo apt-get install -y python3-yaml
          script:
              - |
                    if [ "$TRAVIS_REPO_SLUG" == "kvirc/KVIrc" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
                        echo "All builds passed!"
                        mkdir -p ~/.ssh
                        chmod 0600 ~/kvirc-github-key
                        cp .travis.ssh ~/.ssh/config
                        git config --global user.email "kvirc-travis@users.noreply.github.com"
                        git config --global user.name "kvirc-travis"
                        ./.travis-coverity-scan.py
                    else
                        echo "Not master"
                    fi


sudo: required
git:
    depth: 9999999
dist: xenial
before_install:
    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then cat /proc/cpuinfo /proc/meminfo; fi
    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then lsb_release -a; fi
    - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sw_vers; fi
    - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sysctl -a | grep cpu; fi
    - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sysctl -a | grep mem; fi
    - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export GPG_KEYS="409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB"; fi
    - |
        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
            ( gpg --keyserver pool.sks-keyservers.net --recv-keys $GPG_KEYS \
            || gpg --keyserver pgp.mit.edu --recv-keys $GPG_KEYS \
            || gpg --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys $GPG_KEYS \
            || gpg --keyserver keyserver.pgp.com --recv-keys $GPG_KEYS );
        fi
    - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then rvm get head; fi
    - |
        if [[ "$TRAVIS_REPO_SLUG" == "kvirc/KVIrc" && "$TRAVIS_PULL_REQUEST" == "false" && "$TRAVIS_BRANCH" == "master" ]]; then
          openssl aes-256-cbc -k "$KEY_SSH_ARTIFACTS" -in .travis-artifacts.ssh.enc -out ~/kvirc-artifacts-key -d
        fi
    - export KEY_SSH_GITHUB=no KEY_SSH_ARTIFACTS=no
    - pwd
install:
    - CMAKE_ARGS=""
    - |
        if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
            sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test # for gcc-7
            sudo apt-get update
            sudo apt-get install -y libperl-dev libenchant-dev qtmultimedia5-dev libqt5webkit5-dev libqt5svg5-dev libqt5x11extras5-dev libphonon4qt5-dev libphonon4qt5experimental-dev gcc-7 g++-7
            sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90
            sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 90

            if [ -z "$DEBUILD" ]
            then
              CMAKE_ARGS="$CMAKE_ARGS -DWANT_KDE=$WANT_KDE"
              if [[ "$WANT_KDE" == "YES" ]]; then
                sudo apt-get install -y kdelibs5-dev
              fi
            else
              sudo apt-get install -y devscripts debhelper zlib1g-dev libx11-dev libxrender-dev libssl-dev qttools5-dev-tools qttools5-dev pkg-config libxss-dev python-dev dput gnupg libdistro-info-perl fakeroot
            fi
        fi
    - |
        if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
          brew update
          brew install qt5 enchant openssl
          # want cmake newer than by default in travis osx
          brew upgrade cmake
          CMAKE_ARGS="$CMAKE_ARGS -DOPENSSL_ROOT_DIR=$(brew --prefix openssl)"
          export CMAKE_FRAMEWORK_PATH="$CMAKE_FRAMEWORK_PATH:$(brew --prefix qt5)"
        fi
script:
    - |
        if [ -z "$DEBUILD" ]
            then
            mkdir build
            cd build
            cmake $CMAKE_ARGS .. || exit 1
            make -j3  || exit 1
            if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo make install; fi
            if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then make install; fi
            ls -l
            cd ..
        else
            cd dist
            export DEB_BUILD_OPTIONS="parallel=3"
            bash build_debian.sh  || exit 1
            cd build && sudo dpkg -i *.deb
            ls -l
            cd ../..
        fi
after_success:
    - |
          if [ ! -z "$DEBUILD" ] && [ "$TRAVIS_REPO_SLUG" == "kvirc/KVIrc" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
              cd dist
              bash build_debian.sh -p || exit 1
          fi

    - |
          if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
              npm update -g npm
              npm install -g appdmg
              appdmg -v dist/osx/osx_dmg.json KVIrc.dmg
          fi
    - |
          if [[ "$TRAVIS_OS_NAME" == "osx" && "$TRAVIS_REPO_SLUG" == "kvirc/KVIrc" && "$TRAVIS_PULL_REQUEST" == "false" && "$TRAVIS_BRANCH" == "master" ]]; then
              mkdir -p ~/.ssh
              chmod 0600 ~/kvirc-artifacts-key
              cp .travis.ssh ~/.ssh/config

              kvi_version="$(grep -i "^set(VERSION_RELEASE .*)$" CMakeLists.txt | egrep -o '[0-9\.]' | tr -d '\n')";
              git_desc="$(git describe)";
              dmg_name="KVIrc-${kvi_version}-dev-${git_desc}.dmg"
              python .travis-gen-latest-json.py "${dmg_name}" KVIrc.dmg > latest
              echo -e "put KVIrc.dmg x/${dmg_name}\nput latest x/latest-macos" | sftp artifacts
          fi
env:
  global:
  # These 2 lines are: $GPGPASS, $AESPASS (used in build_debian.sh)
  - secure: iFr+Hn6PBDqciGSi8BF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