version: 1.0.0+{build}

image:
  - Ubuntu

services:
  - docker

configuration: Release

platform: x64

environment:
  global:
    docker_image: infactum/tg2sip-builder

  matrix:
    - target_name: Ubuntu Bionic
      docker_tag: bionic

    - target_name: CentOS 7
      docker_tag: centos7

    - target_name: AppImage
      docker_tag: centos6

init:
  - sh: |
      docker pull "$docker_image":"$docker_tag"

build_script:
  - sh: >- 
      if [ "$target_name" != "AppImage" ] ; then
      mkdir build;
      docker run --rm -v "$(pwd)":/src "$docker_image":"$docker_tag" /bin/bash -c "
        mkdir build && cd build;
        export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig && cmake -DCMAKE_BUILD_TYPE=Release /src;
        cmake --build .;
        chmod +x tg2sip;
        chmod +x gen_db;
        cp tg2sip /src/build;
        cp gen_db /src/build;"
      7z a tg2sip.zip ./build/tg2sip ./build/gen_db ./settings.ini;
      fi;

  - sh: >-
      if [ "$target_name" = "AppImage" ] ; then
      mkdir build;
      docker run --rm -v "$(pwd)":/src "$docker_image":"$docker_tag" /bin/bash -c "
        mkdir build && cd build;
        export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig && cmake -DCMAKE_BUILD_TYPE=Release /src;
        cmake --build .;
        chmod +x tg2sip;
        chmod +x gen_db;
        linuxdeploy --appdir /src/build/tg2sip -e tg2sip;
        linuxdeploy --appdir /src/build/gen_db -e gen_db;"
      wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O appimagetool.AppImage;
      chmod +x appimagetool.AppImage;
      wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage -O linuxdeploy.AppImage;
      chmod +x linuxdeploy.AppImage;
      sudo chown -R "$(id -u)":"$(id -g)" ./build;
      ./linuxdeploy.AppImage --appdir ./build/tg2sip -d ./buildenv/tg2sip.desktop -i ./buildenv/icon.svg;
      ./linuxdeploy.AppImage --appdir ./build/gen_db -d ./buildenv/gen_db.desktop -i ./buildenv/icon.svg;
      ./appimagetool.AppImage ./build/tg2sip;
      ./appimagetool.AppImage ./build/gen_db;
      7z a tg2sip.zip ./tg2sip-x86_64.AppImage ./gen_db-x86_64.AppImage ./settings.ini;
      fi;

after_build:
  - sh: >-
      if [ "$target_name" != "AppImage" ] ; then
        appveyor PushArtifact tg2sip.zip -FileName tg2sip_"$docker_tag".zip -DeploymentName "TG2SIP $target_name"
      else
        appveyor PushArtifact tg2sip.zip -FileName tg2sip.zip -DeploymentName "TG2SIP AppImage"
      fi