stages:
  - prepare
  - build
  - unit_test
#  - integration_test

#
# PREPARE STAGE
#

prepare_RAServices:
  stage: prepare
  script:
    - docker build -t ci_raservices -f SubSystems/RAServices/Dockerfile .

#
# BUILD STAGE
#

build_RAServices:
  stage: build
  image: ci_raservices:latest
  script:
    - PACKAGE=RAServices
    - echo "Building $PACKAGE..."
    - mkdir install
    - mkdir -p build/gnucxx11_opt
    - cd build/gnucxx11_opt
    - cmake -DBUILD_PACKAGES=$PACKAGE -DCASACORE_ROOT_DIR=/opt/casacore/ -DCASAREST_ROOT_DIR=/opt/casarest/ -DCMAKE_INSTALL_PREFIX=/opt/lofar -DUSE_LOG4CPLUS=false ../..
    - make
    - make DESTDIR=../../install install
    - cd ../../install/opt/lofar
    - tar --ignore-failed-read --exclude=include -czf ../../RAServices_$CI_COMMIT_SHORT_SHA.ztar *
  dependencies:
    - prepare_RAServices
  artifacts:
    expire_in: 6 hours
    paths:
      - build/gnucxx11_opt
      - install/*.ztar

#
# UNIT TEST STAGE
#

unit_test_RAServices:
  stage: unit_test
  image: ci_raservices:latest
  script:
    - PACKAGE=RAServices
    - echo "Testing $PACKAGE..."
    - cd build/gnucxx11_opt
    - SKIP_INTEGRATION_TESTS=true ctest
  dependencies:
    - build_RAServices
  artifacts:
    name: unit-test-report
    when: always
    paths:
      - build/gnucxx11_opt/Testing/Temporary/LastTest.log

#
# INTEGRATION TEST STAGE
#

# integration_test_RAServices:
#   stage: integration_test
#   image: ci_raservices:latest
#   services:
#     - rabbitmq:latest
#   variables:
#     LOFAR_DEFAULT_BROKER: "rabbitmq"
#   script:
#     - PACKAGE=RAServices
#     - echo "Testing $PACKAGE..."
#     - cd build/gnucxx11_opt
#     - SKIP_UNIT_TESTS=true ctest
#   dependencies:
#     - build_RAServices
#   artifacts:
#     name: integration-test-report
#     when: always
#     paths:
#       - build/gnucxx11_opt/Testing/Temporary/LastTest.log


