---
stages:
  - build

.artifacts: &artifacts
  artifacts:
    paths:
      - build/

.cache: &cache
  cache:
    key: "$CI_BUILD_NAME"
    paths:
      - cache/

.branches: &branches
  only:
    - master

.tags: &tags
  tags:
    - linux
    - docker


#================================ DEBIAN-BASED ================================

.build_rc_package_deb: &build_rc_package_deb
  stage: build
  script:
    - mkdir -p build
    - cd build
    - cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR=DEB
    - make package -j2

.build_debug_package_deb: &build_debug_package_deb
  stage: build
  script:
    - mkdir -p build
    - cd build
    - cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=Debug -DCPACK_GENERATOR=DEB
    - make package -j2

.deb-artifacts: &artifacts_deb
  artifacts:
    paths:
      - build/*.deb
      - build/CMakeFiles/*.log
    when: always

#----------------------------------- UBUNTU -----------------------------------

.requirements_16xx: &install_requirements_16xx
  before_script:
    - apt-get -o dir::cache::archives="cache" update -qq
    - apt-get -o dir::cache::archives="cache" install -y build-essential g++ cmake git
    - apt-get -o dir::cache::archives="cache" install -y libprotobuf-dev protobuf-compiler
    - apt-get -o dir::cache::archives="cache" install -y qt5-default qttools5-dev qttools5-dev-tools
    - apt-get -o dir::cache::archives="cache" install -y qtmultimedia5-dev libqt5multimedia5-plugins
    - apt-get -o dir::cache::archives="cache" install -y libqt5svg5-dev libqt5sql5-mysql
    - apt-get -o dir::cache::archives="cache" install -y libqt5websockets5-dev

.requirements_17xx: &install_requirements_17xx
  before_script:
    - apt-get -o dir::cache::archives="cache" update -qq
    - apt-get -o dir::cache::archives="cache" install -y build-essential g++ cmake git
    - apt-get -o dir::cache::archives="cache" install -y libprotobuf-dev protobuf-compiler
    - apt-get -o dir::cache::archives="cache" install -y qt5-default qttools5-dev qttools5-dev-tools
    - apt-get -o dir::cache::archives="cache" install -y qtmultimedia5-dev libqt5multimedia5-plugins
    - apt-get -o dir::cache::archives="cache" install -y libqt5svg5-dev libqt5sql5-mysql
    - apt-get -o dir::cache::archives="cache" install -y libqt5websockets5-dev

.build_1604: &1604
  image: ubuntu:16.04
  <<: *tags
  <<: *branches
  <<: *install_requirements_16xx
  <<: *artifacts_deb
  <<: *cache

.build_1710: &1710
  image: ubuntu:17.10
  <<: *tags
  <<: *branches
  <<: *install_requirements_17xx
  <<: *artifacts_deb
  <<: *cache

build_rc_1604:
  <<: *1604
  <<: *build_rc_package_deb
  when: always

build_debug_1604:
  <<: *1604
  <<: *build_debug_package_deb
  when: always

build_rc_1710:
  <<: *1710
  <<: *build_rc_package_deb
  when: always

build_debug_1710:
  <<: *1710
  <<: *build_debug_package_deb
  when: always
  allow_failure: true

#----------------------------------- DEBIAN -----------------------------------

.requirements_stretch: &install_requirements_stretch
  before_script:
    - apt-get -o dir::cache::archives="cache" update -qq
    - apt-get -o dir::cache::archives="cache" install -y build-essential g++ cmake git
    - apt-get -o dir::cache::archives="cache" install -y qt5-default qtbase5-dev-tools
    - apt-get -o dir::cache::archives="cache" install -y qttools5-dev-tools qtmultimedia5-dev
    - apt-get -o dir::cache::archives="cache" install -y libqt5svg5-dev libqt5websockets5-dev
    - apt-get -o dir::cache::archives="cache" install -y libprotobuf-dev protobuf-compiler

.build_stretch: &stretch
  image: debian:stretch
  <<: *tags
  <<: *branches
  <<: *install_requirements_stretch
  <<: *artifacts_deb
  <<: *cache

build_rc_stretch:
  <<: *stretch
  <<: *build_rc_package_deb
  when: always

build_debug_stretch:
  <<: *stretch
  <<: *build_debug_package_deb
  when: always
  allow_failure: true
  
