stages:
  - test
  - perf
  - cleanup

variables:
  GITLAB_MAKE: "make -f .gitlab.mk"

# Jobs templates

.release_only_template: &release_only_definition
  only:
    - master
    - /^.*-full-ci$/

.deploy_only_template: &deploy_only_definition
  only:
    - master
  except:
    - schedules
    - external_pull_requests
    - merge_requests

.pack_only_template: &pack_only_definition
  only:
    - schedules
    - external_pull_requests
    - merge_requests
    - /^.*-full-ci$/

.perf_only_template: &perf_only_definition
  only:
    - master
    - /^.*-perf$/
  variables: &perf_vars_definition
    IMAGE_PERF: "${CI_REGISTRY}/${CI_PROJECT_PATH}/perf/ubuntu-bionic:perf_master"
    IMAGE_PERF_BUILT: "${CI_REGISTRY}/${CI_PROJECT_PATH}/perf_tmp/ubuntu-bionic:perf_${CI_COMMIT_SHORT_SHA}"

.docker_test_template: &docker_test_definition
  image: "${CI_REGISTRY}/${CI_PROJECT_PATH}/testing/debian-stretch:latest"
  stage: test
  tags:
    - docker_test

.docker_test_clang8_template: &docker_test_clang8_definition
  image: "${CI_REGISTRY}/${CI_PROJECT_PATH}/testing/debian-buster:latest"
  stage: test
  tags:
    - docker_test

.pack_template: &pack_definition
  <<: *pack_only_definition
  stage: test
  tags:
    - deploy
  script:
    - ${GITLAB_MAKE} package

.pack_test_template: &pack_test_definition
  <<: *pack_only_definition
  stage: test
  tags:
    - deploy_test
  script:
    - ${GITLAB_MAKE} package

.deploy_template: &deploy_definition
  <<: *deploy_only_definition
  stage: test
  tags:
    - deploy
  script:
    - ${GITLAB_MAKE} deploy

.deploy_test_template: &deploy_test_definition
  <<: *deploy_only_definition
  stage: test
  tags:
    - deploy_test
  script:
    - ${GITLAB_MAKE} deploy

.vbox_template: &vbox_definition
  stage: test
  before_script:
    - ${GITLAB_MAKE} vms_start
  after_script:
    - ${GITLAB_MAKE} vms_shutdown

.perf_docker_test_template: &perf_docker_test_definition
  <<: *perf_only_definition
  image: ${IMAGE_PERF_BUILT}
  stage: perf
  tags:
    - docker_perf
  script:
    - ${GITLAB_MAKE} perf_run

# Tests

release:
  <<: *docker_test_definition
  script:
    - ${GITLAB_MAKE} test_debian_no_deps

debug:
  <<: *docker_test_definition
  script:
    - ${GITLAB_MAKE} test_coverage_debian_no_deps

release_clang:
  <<: *docker_test_definition
  variables:
    CC: clang
    CXX: clang++
  script:
    - ${GITLAB_MAKE} test_debian_no_deps

release_lto:
  <<: *release_only_definition
  <<: *docker_test_clang8_definition
  variables:
    CMAKE_EXTRA_PARAMS: -DENABLE_LTO=ON
  script:
    - ${GITLAB_MAKE} test_debian_no_deps

release_lto_clang8:
  <<: *release_only_definition
  <<: *docker_test_clang8_definition
  variables:
    CC: clang-8
    CXX: clang++-8
    CMAKE_EXTRA_PARAMS: -DENABLE_LTO=ON
  script:
    - ${GITLAB_MAKE} test_debian_no_deps

release_asan_clang8:
  <<: *docker_test_clang8_definition
  script:
    - ${GITLAB_MAKE} test_asan_debian_no_deps

osx_13_release:
  <<: *release_only_definition
  <<: *vbox_definition
  tags:
    - vms_osx_13
  variables:
    VMS_NAME: 'osx_13'
    VMS_USER: 'tarantool'
    VMS_PORT: '2212'
  script:
    - ${GITLAB_MAKE} vms_test_osx

osx_14_release:
  <<: *vbox_definition
  tags:
    - vms_osx_14
  variables:
    VMS_NAME: 'osx_14'
    VMS_USER: 'tarantool'
    VMS_PORT: '2222'
  script:
    - ${GITLAB_MAKE} vms_test_osx

osx_14_release_lto:
  <<: *release_only_definition
  <<: *vbox_definition
  tags:
    - vms_osx_14
  variables:
    EXTRA_ENV: "export CMAKE_EXTRA_PARAMS=-DENABLE_LTO=ON ;"
    VMS_NAME: 'osx_14'
    VMS_USER: 'tarantool'
    VMS_PORT: '2222'
  script:
    - ${GITLAB_MAKE} vms_test_osx

freebsd_12_release:
  <<: *vbox_definition
  tags:
    - vms_freebsd_12
  variables:
    VMS_NAME: 'freebsd_12'
    VMS_USER: 'vagrant'
    VMS_PORT: '2232'
    MAKE: 'gmake'
  script:
    - ${GITLAB_MAKE} vms_test_freebsd

# ####
# Perf
# ####

# Pre-testing part

perf_bootstrap:
  <<: *perf_only_definition
  stage: test
  tags:
    - perf
  script:
    - ${GITLAB_MAKE} perf_prepare

# Testing part

perf_sysbench:
  <<: *perf_docker_test_definition
  variables:
    <<: *perf_vars_definition
    BENCH: 'sysbench'

perf_tpcc:
  <<: *perf_docker_test_definition
  variables:
    <<: *perf_vars_definition
    BENCH: 'tpcc'

perf_ycsb_hash:
  <<: *perf_docker_test_definition
  variables:
    <<: *perf_vars_definition
    BENCH: 'ycsb'
    ARG: 'hash'

perf_ycsb_tree:
  <<: *perf_docker_test_definition
  variables:
    <<: *perf_vars_definition
    BENCH: 'ycsb'
    ARG: 'tree'

perf_nosqlbench_hash:
  <<: *perf_docker_test_definition
  variables:
    <<: *perf_vars_definition
    BENCH: 'nosqlbench'
    ARG: 'hash'

perf_nosqlbench_tree:
  <<: *perf_docker_test_definition
  variables:
    <<: *perf_vars_definition
    BENCH: 'nosqlbench'
    ARG: 'tree'

perf_cbench:
  <<: *perf_docker_test_definition
  variables:
    <<: *perf_vars_definition
    BENCH: 'cbench'

perf_linkbench_ssd:
  <<: *perf_docker_test_definition
  tags:
    - docker_perf_ssd
  variables:
    <<: *perf_vars_definition
    BENCH: 'linkbench'

# Post-testing part

remove_images:
  <<: *perf_only_definition
  stage: cleanup
  when: always
  tags:
    - perf
  script:
    - ${GITLAB_MAKE} perf_cleanup

# Packs

centos_6:
  <<: *pack_definition
  variables:
    OS: 'el'
    DIST: '6'

centos_7:
  <<: *pack_test_definition
  variables:
    OS: 'el'
    DIST: '7'

centos_8:
  <<: *pack_test_definition
  variables:
    OS: 'el'
    DIST: '8'

fedora_28:
  <<: *pack_test_definition
  variables:
    OS: 'fedora'
    DIST: '28'

fedora_29:
  <<: *pack_test_definition
  variables:
    OS: 'fedora'
    DIST: '29'

fedora_30:
  <<: *pack_test_definition
  variables:
    OS: 'fedora'
    DIST: '30'

fedora_31:
  <<: *pack_test_definition
  variables:
    OS: 'fedora'
    DIST: '31'

ubuntu_14_04:
  <<: *pack_definition
  variables:
    OS: 'ubuntu'
    DIST: 'trusty'

ubuntu_16_04:
  <<: *pack_definition
  variables:
    OS: 'ubuntu'
    DIST: 'xenial'

ubuntu_18_04:
  <<: *pack_definition
  variables:
    OS: 'ubuntu'
    DIST: 'bionic'

ubuntu_19_04:
  <<: *pack_definition
  variables:
    OS: 'ubuntu'
    DIST: 'disco'

ubuntu_19_10:
  <<: *pack_definition
  variables:
    OS: 'ubuntu'
    DIST: 'eoan'

debian_8:
  <<: *pack_definition
  variables:
    OS: 'debian'
    DIST: 'jessie'

debian_9:
  <<: *pack_definition
  variables:
    OS: 'debian'
    DIST: 'stretch'

debian_10:
  <<: *pack_definition
  variables:
    OS: 'debian'
    DIST: 'buster'

# Deploy

centos_6_deploy:
  <<: *deploy_definition
  variables:
    OS: 'el'
    DIST: '6'

centos_7_deploy:
  <<: *deploy_test_definition
  variables:
    OS: 'el'
    DIST: '7'

centos_8_deploy:
  <<: *deploy_test_definition
  variables:
    OS: 'el'
    DIST: '8'

fedora_28_deploy:
  <<: *deploy_test_definition
  variables:
    OS: 'fedora'
    DIST: '28'

fedora_29_deploy:
  <<: *deploy_test_definition
  variables:
    OS: 'fedora'
    DIST: '29'

fedora_30_deploy:
  <<: *deploy_test_definition
  variables:
    OS: 'fedora'
    DIST: '30'

fedora_31_deploy:
  <<: *deploy_test_definition
  variables:
    OS: 'fedora'
    DIST: '31'

ubuntu_14_04_deploy:
  <<: *deploy_definition
  variables:
    OS: 'ubuntu'
    DIST: 'trusty'

ubuntu_16_04_deploy:
  <<: *deploy_definition
  variables:
    OS: 'ubuntu'
    DIST: 'xenial'

ubuntu_18_04_deploy:
  <<: *deploy_definition
  variables:
    OS: 'ubuntu'
    DIST: 'bionic'

ubuntu_19_04_deploy:
  <<: *deploy_definition
  variables:
    OS: 'ubuntu'
    DIST: 'disco'

ubuntu_19_10_deploy:
  <<: *deploy_definition
  variables:
    OS: 'ubuntu'
    DIST: 'eoan'

debian_8_deploy:
  <<: *deploy_definition
  variables:
    OS: 'debian'
    DIST: 'jessie'

debian_9_deploy:
  <<: *deploy_definition
  variables:
    OS: 'debian'
    DIST: 'stretch'

debian_10_deploy:
  <<: *deploy_definition
  variables:
    OS: 'debian'
    DIST: 'buster'

static_build:
  <<: *deploy_test_definition
  variables:
    RUN_TESTS: 'ON'
  script:
    - ${GITLAB_MAKE} static_build
