language: c

before_install:
    # Android jobs are triggered from cron and overwrite `before_script` part
    - if [[ "$OPENRCT2_ANDROID" == "true" ]] ; then echo before_install not needed for Android jobs ; exit 0 ; fi
    - if [[ "z$OPENRCT2_ORG_TOKEN" != "z" && "$TRAVIS_PULL_REQUEST" == "false" && ("${TRAVIS_BRANCH}" =~ ^(develop|push/) || "z${TRAVIS_TAG}" != "z") ]] ; then
      echo "This build will get pushed!" ; echo "tag = ${TRAVIS_TAG}" ; echo "branch = ${TRAVIS_BRANCH}" ;
      fi
    - if [[ $TRAVIS_REPO_SLUG == "OpenRCT2/OpenRCT2" ]] && [[ $TRAVIS_PULL_REQUEST != "false" ]] && [[ $TRAVIS_BRANCH == "master" ]]; then echo "Pull requests to master branch are not allowed!" ; exit 1 ; fi
    - if [[ $TRAVIS_OS_NAME == "linux" ]]; then bash scripts/linux/install.sh; export OPENRCT_MAKE_OPTS="-k 10 all openrct2-cli" ; fi
    - if [[ $TRAVIS_OS_NAME == "osx" ]]; then sudo gem install xcpretty-travis-formatter; fi

sudo: required
dist: trusty
env:
    global:
        - OPENRCT2_VERSION="0.1.3"

matrix:
    include:
        - os: linux
          if: type != cron
          services:
            - docker
          env:
            - OPENRCT2_CMAKE_OPTS="-G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=OpenRCT2 -DPORTABLE=ON -DDISABLE_RCT2_TESTS=on -DCMAKE_CXX_FLAGS=\"-static-libstdc++ -static-libgcc -Wl,--compress-debug-sections=zlib\"" TARGET=ubuntu_amd64
            - secure: "S3u2VCE2Vy8KNXoeh+DhnzjCmgTX0r95uEZrXDU+IKANOOCKn7Dg4OFDZE3LY/i1y2/EUDpnR5yLC38Ks795EUP/sv/OoMl4tjQ20yERjqWh+gcIRrgx7SdVabuAh3t4aBdaLD4Pfnj5avxeCt6rL7yGnj0wdbrbJSBZPsgSnuQ="
          after_success:
            # Android jobs are triggered from cron and overwrite `after_sucess` part
            - if [[ "$TRAVIS_EVENT_TYPE" == "cron" ]] ; then exit 0 ; fi
            - sudo chown -R $USER build
            - cd build
              # make install is done inside docker
            - mv OpenRCT2/bin/openrct2 OpenRCT2/ && mv OpenRCT2/bin/openrct2-cli OpenRCT2/ && mv OpenRCT2/bin/libopenrct2.so OpenRCT2/ && mv OpenRCT2/share/openrct2 OpenRCT2/data && mv OpenRCT2/share/doc/openrct2 OpenRCT2/doc && mv OpenRCT2/bin/libdiscord-rpc.so OpenRCT2/
            - rm -rf OpenRCT2/bin OpenRCT2/share # remove empty dirs
            - tar cvzf openrct2-linux.tar.gz OpenRCT2/
            - if [[ "z${TRAVIS_TAG}" != "z" ]] ; then
              export PUSH_BRANCH=master ;
              else export PUSH_BRANCH=$TRAVIS_BRANCH ; export FILENAME_PART=-${TRAVIS_BRANCH}-$(git rev-parse --short HEAD) ;
              fi
            - if [[ "z$OPENRCT2_ORG_TOKEN" != "z" && "$TRAVIS_PULL_REQUEST" == "false" && ("${TRAVIS_BRANCH}" =~ ^(develop|push/) || "z${TRAVIS_TAG}" != "z") ]] ; then
              curl -o - -v --form "key=$OPENRCT2_ORG_TOKEN" --form "fileName=OpenRCT2-${OPENRCT2_VERSION}${FILENAME_PART}-linux-x86_64.tar.gz" --form "version=${OPENRCT2_VERSION}" --form "gitHash=$TRAVIS_COMMIT" --form "gitBranch=$PUSH_BRANCH" --form "flavourId=9" --form "file=@openrct2-linux.tar.gz" "https://openrct2.org/altapi/?command=push-build";
              else curl --progress-bar --upload-file openrct2-linux.tar.gz https://transfer.sh/openrct2-linux-x86_64.tar.gz -o link && cat link;
              fi
        - os: linux
          if: type != cron
          services:
            - docker
          env:
            - OPENRCT2_CMAKE_OPTS="-G Ninja -DFORCE32=ON -DBUILD_SHARED_LIBS=off -DCMAKE_INSTALL_PREFIX=OpenRCT2 -DDISABLE_RCT2_TESTS=on -DCMAKE_CXX_FLAGS=\"-static-libstdc++ -static-libgcc -Wl,--compress-debug-sections=zlib\"" TARGET=ubuntu_i686
            - secure: "S3u2VCE2Vy8KNXoeh+DhnzjCmgTX0r95uEZrXDU+IKANOOCKn7Dg4OFDZE3LY/i1y2/EUDpnR5yLC38Ks795EUP/sv/OoMl4tjQ20yERjqWh+gcIRrgx7SdVabuAh3t4aBdaLD4Pfnj5avxeCt6rL7yGnj0wdbrbJSBZPsgSnuQ="
          after_success:
            # Android jobs are triggered from cron and overwrite `after_sucess` part
            - if [[ "$TRAVIS_EVENT_TYPE" == "cron" ]] ; then exit 0 ; fi
            - sudo chown -R $USER build
            - cd build
              # make install is done inside docker
            - mv OpenRCT2/bin/openrct2 OpenRCT2/ && mv OpenRCT2/share/openrct2 OpenRCT2/data && mv OpenRCT2/share/doc/openrct2 OpenRCT2/doc
            - rm -rf OpenRCT2/bin OpenRCT2/share # remove empty dirs
            - tar cvzf openrct2-linux.tar.gz OpenRCT2/
            - if [[ "z${TRAVIS_TAG}" != "z" ]] ; then
              export PUSH_BRANCH=master ;
              else export PUSH_BRANCH=$TRAVIS_BRANCH ; export FILENAME_PART=-${TRAVIS_BRANCH}-$(git rev-parse --short HEAD) ;
              fi
            - if [[ "z$OPENRCT2_ORG_TOKEN" != "z" && "$TRAVIS_PULL_REQUEST" == "false" && ("${TRAVIS_BRANCH}" =~ ^(develop|push/) || "z${TRAVIS_TAG}" != "z") ]] ; then
              curl -o - -v --form "key=$OPENRCT2_ORG_TOKEN" --form "fileName=OpenRCT2-${OPENRCT2_VERSION}${FILENAME_PART}-linux-i686.tar.gz" --form "version=${OPENRCT2_VERSION}" --form "gitHash=$TRAVIS_COMMIT" --form "gitBranch=$PUSH_BRANCH" --form "flavourId=4" --form "file=@openrct2-linux.tar.gz" "https://openrct2.org/altapi/?command=push-build";
              else curl --progress-bar --upload-file openrct2-linux.tar.gz https://transfer.sh/openrct2-linux-i686.tar.gz -o link && cat link;
              fi
        - os: linux
          if: type != cron
          env: OPENRCT2_CMAKE_OPTS="-G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBUILD_SHARED_LIBS=ON -DDISABLE_RCT2_TESTS=on" TARGET=ubuntu_amd64
        - os: linux
          if: type != cron
          env: OPENRCT2_CMAKE_OPTS="-G Ninja -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt -DFORCE32=on -DBUILD_SHARED_LIBS=ON -DDISABLE_RCT2_TESTS=on" TARGET=windows
        - os: linux
          if: type != cron
          env: TARGET=docker64 OPENRCT2_CMAKE_OPTS="-G Ninja -DDISABLE_TTF=ON -DCMAKE_BUILD_TYPE=release -DBUILD_SHARED_LIBS=ON -DDISABLE_RCT2_TESTS=on"
          services:
            - docker
        - os: linux
          if: type != cron
          env: OPENRCT2_CMAKE_OPTS="-G Ninja -DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DBUILD_SHARED_LIBS=ON -DDISABLE_RCT2_TESTS=on" TARGET=docker64
          services:
            - docker
        - os: linux
          if: type != cron
          env: OPENRCT2_CMAKE_OPTS="-G Ninja -DDISABLE_OPENGL=ON -DBUILD_SHARED_LIBS=ON -DDISABLE_RCT2_TESTS=on" TARGET=docker64
          services:
            - docker
        - os: osx
          if: type != cron
          osx_image: xcode8.3
          env:
            - secure: "OXn/i72FxW/oh6RGlaN+gHSbkt1ToFe36etaiDOsJQznt6fe9CpFdnE8U1XBHlGokcEjbGNErRU7CFDKYHQuGrPZyHXwgqG2/0emIqFaFt5ti5ypyYKf5qH9x1LLLfdZxDyHkxXdlJ7Etxbp3G7qrV8CGRQiYRNHm1f98AmuufE="
          after_success:
            # Android jobs are triggered from cron and overwrite `after_sucess` part
            - if [[ "$TRAVIS_EVENT_TYPE" == "cron" ]] ; then exit 0 ; fi
            - cd build/Release
            - zip -r openrct2-macos.zip OpenRCT2.app
            - if [[ "z${TRAVIS_TAG}" != "z" ]] ; then
              export PUSH_BRANCH=master ;
              else export PUSH_BRANCH=$TRAVIS_BRANCH ; export FILENAME_PART=-${TRAVIS_BRANCH}-$(git rev-parse --short HEAD) ;
              fi
            - if [[ "z$OPENRCT2_ORG_TOKEN" != "z" && "$TRAVIS_PULL_REQUEST" == "false" && ("${TRAVIS_BRANCH}" =~ ^(develop|push/) || "z${TRAVIS_TAG}" != "z") ]] ; then
              curl -o - -v --form "key=$OPENRCT2_ORG_TOKEN" --form "fileName=OpenRCT2-${OPENRCT2_VERSION}${FILENAME_PART}-macos.zip" --form "version=${OPENRCT2_VERSION}" --form "gitHash=$TRAVIS_COMMIT" --form "gitBranch=$PUSH_BRANCH" --form "flavourId=3" --form "file=@openrct2-macos.zip" "https://openrct2.org/altapi/?command=push-build"; else
              curl --progress-bar --upload-file openrct2-macos.zip https://transfer.sh/openrct2-macos.zip -o link && cat link;
              fi
        - os: linux
          if: type = cron OR branch = master OR branch =~ ^android
          language: android
          dist: precise
          before_install: []
          env:
            - secure: "S3u2VCE2Vy8KNXoeh+DhnzjCmgTX0r95uEZrXDU+IKANOOCKn7Dg4OFDZE3LY/i1y2/EUDpnR5yLC38Ks795EUP/sv/OoMl4tjQ20yERjqWh+gcIRrgx7SdVabuAh3t4aBdaLD4Pfnj5avxeCt6rL7yGnj0wdbrbJSBZPsgSnuQ="
            - OPENRCT2_ANDROID="true"
          addons:
            apt:
              sources:
                - ubuntu-toolchain-r-test
              packages:
              - libstdc++6-4.7-dev
          android:
            components:
              - build-tools-25.0.2
          jdk: oraclejdk8
          before_script:
            # Only run Android jobs when triggered from cron or on tag, otherwise skip
            - if [[ "$OPENRCT2_ANDROID" != "true" ]] && [[ "z${TRAVIS_TAG}" == "z" ]] ; then exit 0 ; fi
            - pushd ~
            - wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
            - unzip -qo sdk-tools-linux-3859397.zip
            - rm -Rf "$ANDROID_HOME/tools"
            - mv tools "$ANDROID_HOME/tools"
            - popd
            - 'echo "count=0" >  ~/.android/repositories.cfg'
            - '"$ANDROID_HOME/tools/bin/sdkmanager" --list'
            - 'echo y | "$ANDROID_HOME/tools/bin/sdkmanager" platform-tools'
            - 'echo y | "$ANDROID_HOME/tools/bin/sdkmanager" "platforms;android-25"'
            - 'echo y | "$ANDROID_HOME/tools/bin/sdkmanager" "cmake;3.6.4111459"'
            - '"$ANDROID_HOME/tools/bin/sdkmanager" ndk-bundle'
            - '"$ANDROID_HOME/tools/bin/sdkmanager" --list'
            - 'export ANDROID_NDK_HOME="$ANDROID_HOME/ndk-bundle"'
            - 'cd src/openrct2-android'
            - TERM=dumb # Makes Gradle use 'boring' output
          script:
            # Only run Android jobs when triggered from cron or on tag, otherwise skip
            - if [[ "$OPENRCT2_ANDROID" != "true" ]] && [[ "z${TRAVIS_TAG}" == "z" ]] ; then exit 0 ; fi
            - './gradlew app:assemblePR'
          after_success:
            # Only run Android jobs when triggered from cron or on tag, otherwise skip
            - if [[ "$OPENRCT2_ANDROID" != "true" ]] && [[ "z${TRAVIS_TAG}" == "z" ]] ; then exit 0 ; fi
            - curl --progress-bar --upload-file app/build/outputs/apk/app-arm-pr.apk https://transfer.sh/openrct2-android-arm.apk -o link && cat link
            - curl --progress-bar --upload-file app/build/outputs/apk/app-x86-pr.apk https://transfer.sh/openrct2-android-x86.apk -o link && cat link
            - if [[ "z${TRAVIS_TAG}" != "z" ]] ; then
              export PUSH_BRANCH=master ;
              else export PUSH_BRANCH=$TRAVIS_BRANCH ; export FILENAME_PART=-${TRAVIS_BRANCH}-$(git rev-parse --short HEAD) ;
              fi
            - if [[ "z$OPENRCT2_ORG_TOKEN" != "z" && "$TRAVIS_PULL_REQUEST" == "false" && ("${TRAVIS_BRANCH}" =~ ^(develop|push/) || "z${TRAVIS_TAG}" != "z") ]] ; then
              curl -o - -v --form "key=$OPENRCT2_ORG_TOKEN" --form "fileName=OpenRCT2-${OPENRCT2_VERSION}${FILENAME_PART}-android-arm.apk" --form "version=${OPENRCT2_VERSION}" --form "gitHash=$TRAVIS_COMMIT" --form "gitBranch=$PUSH_BRANCH" --form "flavourId=11" --form "file=@app/build/outputs/apk/app-arm-pr.apk" "https://openrct2.org/altapi/?command=push-build";
              fi
            - if [[ "z$OPENRCT2_ORG_TOKEN" != "z" && "$TRAVIS_PULL_REQUEST" == "false" && ("${TRAVIS_BRANCH}" =~ ^(develop|push/) || "z${TRAVIS_TAG}" != "z") ]] ; then
              curl -o - -v --form "key=$OPENRCT2_ORG_TOKEN" --form "fileName=OpenRCT2-${OPENRCT2_VERSION}${FILENAME_PART}-android-x86.apk" --form "version=${OPENRCT2_VERSION}" --form "gitHash=$TRAVIS_COMMIT" --form "gitBranch=$PUSH_BRANCH" --form "flavourId=12" --form "file=@app/build/outputs/apk/app-x86-pr.apk" "https://openrct2.org/altapi/?command=push-build";
              fi
        # Following entries used to be included in testing, but they only proved useful while changing things in CMake setup.
        # They are meant to be used when there are changes to CMakeLists.txt
        # - os: linux
        #   env: OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8"
        # - os: linux
        #   env: OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++"
        # - os: linux
        #   env: OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=OFF -DDISABLE_HTTP_TWITCH=ON -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8"
        # - os: linux
        #   env: OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=OFF -DDISABLE_HTTP_TWITCH=OFF -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8"
        # - os: linux
        #   env: OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows
        # - os: linux
        #   env: OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows
        # - os: linux
        #   env: OPENRCT2_CMAKE_OPTS="-DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows

script:
    # Android jobs are triggered from cron and overwrite `script` part
    - if [[ "$OPENRCT2_ANDROID" == "true" ]] ; then exit 0 ; fi
    - if [[ $TRAVIS_OS_NAME == "linux" ]]; then bash scripts/linux/build.sh ; fi
    - if [[ $TRAVIS_OS_NAME == "osx" ]]; then set -o pipefail && xcodebuild | xcpretty -f `xcpretty-travis-formatter`; fi

notifications:
    on_failure: change
    on_success: change

cache:
    directories:
        - .cache
    apt: true
