---
sudo: required
language: python
services:
  - docker

stages:
  - test
  - delivery
  - submit  

env:
  global:
    - CC_TEST_REPORTER_ID=a2579335b631ec35473874d7bb4fe983025c0287cea89c9dc34c35f98ee3963d
    - FUNCTIONAL_TEST=$TRAVIS_BUILD_DIR/test/docker_scripts.sh

jobs:
  include:
    - stage: test
      name: "original regression test"
      before_script:
        - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
        - chmod +x ./cc-test-reporter
        - ./cc-test-reporter before-build

      before_install:
        - docker pull krig/crmsh:latest

      script:
        - docker run -t -v "$(pwd):/app" krig/crmsh /bin/sh -c "systemctl start dbus; cd /app; ./test/run-in-travis.sh"

      after_failure:
        - sudo cat $TRAVIS_BUILD_DIR/crmtestout/regression.out $TRAVIS_BUILD_DIR/crmtestout/crm.*

      after_script:
        - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
  
    - name: "functional test for bootstrap - init, join and remove"
      before_install:
        - $FUNCTIONAL_TEST bootstrap before_install
      script:
        - $FUNCTIONAL_TEST bootstrap run init_join_remove

    - name: "functional test for bootstrap - options"
      before_install:
        - $FUNCTIONAL_TEST bootstrap before_install
      script:
        - $FUNCTIONAL_TEST bootstrap run options

    - name: "functional test for qdevice - setup and remove"
      before_install:
        - $FUNCTIONAL_TEST qdevice before_install
      script:
        - $FUNCTIONAL_TEST qdevice run setup_remove

    - name: "functional test for qdevice - options"
      before_install:
        - $FUNCTIONAL_TEST qdevice before_install
      script:
        - $FUNCTIONAL_TEST qdevice run options

    - name: "functional test for qdevice - validate"
      before_install:
        - $FUNCTIONAL_TEST qdevice before_install
      script:
        - $FUNCTIONAL_TEST qdevice run validate

    - name: "functional test for resource subcommand"
      before_install:
        - $FUNCTIONAL_TEST resource before_install
      script:
        - $FUNCTIONAL_TEST resource run

    - stage: delivery
      if: type != pull_request AND branch = master
      env:
        - FOLDER=/package
        - PACKAGE_NAME=crmsh

      before_install:
        - docker pull shap/continuous_deliver:latest 
      
      script:
        - |
          docker run -t -v "$(pwd):/package" \
          -e OBS_USER=$OBS_USER \
          -e OBS_PASS=$OBS_PASS \
          -e FOLDER=$FOLDER \
          -e OBS_PROJECT=$OBS_PROJECT \
          -e PACKAGE_NAME=$PACKAGE_NAME \
          shap/continuous_deliver \
          /bin/bash -c "cd /package;/scripts/upload.sh"

    - stage: submit
      if: type != pull_request AND branch = master
      env:
        - PACKAGE_NAME=crmsh

      before_install:
        - docker pull shap/continuous_deliver:latest

      script:
        - |
          docker run -t -v "$(pwd):/package" \
          -e OBS_USER=$OBS_USER \
          -e OBS_PASS=$OBS_PASS \
          -e OBS_PROJECT=$OBS_PROJECT \
          -e PACKAGE_NAME=$PACKAGE_NAME \
          -e TARGET_PROJECT=$TARGET_PROJECT \
          shap/continuous_deliver \
          /bin/bash -c "cd /package;/scripts/submit.sh"
