variables:
  GIT_STRATEGY: "clone"
  INSTALL_PREFIX: "/home/mesasoft/tfe"

stages:
- build
- package
- deploy

.build_by_travis:
  before_script:
  - mkdir -p /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_NAMESPACE/
  - ln -s $CI_PROJECT_DIR /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_PATH
  - cd /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_PATH
  script:
  - chmod +x ./ci/travis.sh
  - ./ci/travis.sh

.deploy_to_package_server:
  script:
  - cp build/*.rpm $RPM_REPO_PATH
  - createrepo --update $RPM_REPO_PATH
  - rm -rf build

build_debug:
  stage: build
  variables:
    BUILD_TYPE: Debug
  extends: .build_by_travis
  except:
    - tags

build_release:
  stage: build
  variables:
    BUILD_TYPE: RelWithDebInfo
  extends: .build_by_travis
  except:
    - tags

package_debug:
  stage: package
  variables:
    BUILD_TYPE: Debug
    PACKAGE: 1
  extends: .build_by_travis
  artifacts:
    name: "tfe-install-$CI_COMMIT_REF_NAME-debug"
    paths:
    - build/*.rpm
  only:
    - tags

package_release:
  stage: package
  variables:
    BUILD_TYPE: RelWithDebInfo
    PACKAGE: 1
  extends: .build_by_travis
  artifacts:
    name: "tfe-install-$CI_COMMIT_REF_NAME-release"
    paths:
    - build/*.rpm
  only:
    - tags

deploy_debug:
  stage: deploy
  tags:
    - package-server
  dependencies:
    - package_debug
  variables:
    GIT_STRATEGY: "none"
    RPM_REPO_PATH: "/data/ci/repos/tango"
  extends: .deploy_to_package_server
  only:
    - tags

deploy_release:
  stage: deploy
  tags:
  - package-server
  dependencies:
  - package_release
  variables:
    GIT_STRATEGY: "none"
    RPM_REPO_PATH: "/data/ci/repos/tango"
  extends: .deploy_to_package_server
  only:
    - tags
