variables:
  TEST_PACKAGE_NAME: clmctest-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHA-.tar.gz

stages:  
  - build
  - test
  - clean

build:tests:
  stage: build
  script:
    - echo $TEST_PACKAGE_NAME
    - echo "$CI_COMMIT_REF_NAME-$CI_COMMIT_SHA" > clmctest/git-commit-ref  
    - python setup.py sdist --dist-dir=build
  artifacts:
    paths:
    - build/$TEST_PACKAGE_NAME
    expire_in: 1 day

test:
  stage: test
  dependencies: build:test
  script: 
    - vagrant --fixture=scripts -- up
    - vagrant --fixture=scripts -- ssh test-runner -- -tt "pip3 install /vagrant/build/$TEST_PACKAGE_NAME"
    - vagrant --fixture=scripts -- ssh test-runner -- -tt "pytest -s --pyargs clmctest.scripts"
    - vagrant --fixture=monitoring -- up
    - vagrant --fixture=monitoring -- ssh test-runner -- -tt "pytest -s --pyargs clmctest.monitoring"  
    - vagrant --fixture=inputs -- up
    - vagrant --fixture=scripts -- ssh test-runner -- -tt "pytest -s --pyargs clmctest.inputs"         
  when: manual   

clean:
  stage: clean
  script: 
    - vagrant --fixture=scripts -- ssh test-runner -- -tt "pip3 uninstall -y clmctest"    
    - vagrant --fixture=inputs -- destroy --force     
    - vagrant --fixture=monitoring -- destroy --force     
    - vagrant --fixture=scripts -- destroy --force
  when: on_failure
