language: ruby
cache: bundler
stages:
- name: before-merge
  if: type IN (push, pull_request)
- name: after-merge
  if: type IN (api, cron)
- name: platform-cleanup
  if: type IN (cron)

git:
  depth: false # this is needed for pronto

jobs:
  include:
  # BEFORE MERGE
  - name: pronto code review
    stage: before-merge
    script: |
      git remote add upstream https://github.com/gooddata/gooddata-ruby.git
      git fetch upstream master
      bundle exec pronto run -c upstream/master --exit-code

  - name: unit tests
    stage: before-merge
    script: bundle exec rake test:unit
    rvm:
    - 2.2
    - 2.3
    - 2.4
    - 2.5
    - jruby-1.7.19
    - jruby-9.1.5
    - jruby-9.1.7
    - jruby-9.1.14

  - name: sdk integration (vcr) tests - base
    stage: before-merge
    script: bundle exec rake test:sdk
    env: VCR_RECORD_MODE=none
    rvm: 2.3

  - name: sdk integration (vcr) tests - project
    stage: before-merge
    script: bundle exec rake test:project
    env: VCR_RECORD_MODE=none
    rvm: 2.3

  - name: lcm integration (vcr) tests - e2e
    stage: before-merge
    script: bundle exec rspec spec/lcm/integration/lcm_end_to_end_spec.rb
    env:
    - VCR_RECORD_MODE=none
    - GD_ENV=development
    rvm: 2.3

  #  AFTER MERGE
  #  staging 1
  - &lcm-integration-tests
    name: staging1 - lcm integration tests
    stage: after-merge
    script: |
      bundle exec rake -f lcm.rake docker:build
      bundle exec rake -f lcm.rake docker:bundle
      bundle exec rake -f lcm.rake test:docker:integration
    env:
    - VCR_ON=false
    - GD_ENV=staging
    rvm: jruby-9.1.14

  - &lcm-slow-tests
    name: staging1 - lcm slow tests
    stage: after-merge
    script: |
      bundle exec rake -f lcm.rake docker:build
      bundle exec rake -f lcm.rake docker:bundle
      bundle exec rake -f lcm.rake test:docker:slow
    env:
    - VCR_ON=false
    - GD_ENV=staging
    rvm: jruby-9.1.14

  - &userprov-tests
    name: staging1 - user provisioning tests
    stage: after-merge
    script: |
      bundle exec rake -f lcm.rake docker:build
      bundle exec rake -f lcm.rake docker:bundle
      bundle exec rake -f lcm.rake test:docker:userprov
    env:
    - VCR_ON=false
    - GD_ENV=staging
    rvm: jruby-9.1.14

  - &sdk-integration-tests
    name: staging1 - sdk integration tests - base
    stage: after-merge
    script: bundle exec rake test:sdk
    env:
    - VCR_ON=false
    - GD_ENV=staging
    rvm: jruby-9.1.14

  - &sdk-integration-tests-project
    name: staging1 - sdk integration tests - project
    stage: after-merge
    script: bundle exec rake test:project
    env:
    - VCR_ON=false
    - GD_ENV=staging
    rvm: jruby-9.1.14

  # staging 2
  - <<: *lcm-integration-tests
    name: staging2 - lcm integration tests
    env:
    - GD_ENV=testing
    - VCR_ON=false

  - <<: *lcm-slow-tests
    name: staging2 - lcm slow tests
    env:
    - GD_ENV=staging
    - VCR_ON=false

  - <<: *userprov-tests
    name: staging2 - lcm user provisioning tests
    env:
    - GD_ENV=staging
    - VCR_ON=false

  - <<: *sdk-integration-tests
    name: staging2 - sdk integration tests - base
    env:
    - GD_ENV=testing
    - VCR_ON=false

  - <<: *sdk-integration-tests-project
    name: staging2 - sdk integration tests - project
    env:
    - GD_ENV=testing
    - VCR_ON=false

  # staging 3
  - <<: *lcm-integration-tests
    name: staging3 - lcm integration tests
    env:
    - GD_ENV=development
    - VCR_ON=false

  - <<: *lcm-slow-tests
    name: staging3 - lcm slow tests
    env:
    - GD_ENV=staging
    - VCR_ON=false

  - <<: *userprov-tests
    name: staging3 - lcm user provisioning tests
    env:
    - GD_ENV=staging
    - VCR_ON=false

  - <<: *sdk-integration-tests
    name: staging3 - sdk integration tests - base
    env:
    - GD_ENV=development
    - VCR_ON=false

  - <<: *sdk-integration-tests-project
    name: staging3 - sdk integration tests - project
    env:
    - GD_ENV=development
    - VCR_ON=false

  # cleanups
  - &cleanup
    stage: after-merge
    name: staging1 - test environment clean-up
    script: bundle exec ruby bin/test_projects_cleanup.rb -f
    env: GD_ENV=staging

  - <<: *cleanup
    name: staging2 - test environment clean-up
    env: GD_ENV=testing

  - <<: *cleanup
    name: staging3 - test environment clean-up
    env: GD_ENV=development

notifications:
  email:
    recipients:
      secure: AMTssALc5Qt4ApAoI7gCmqP3d7AL0dGyZ+DsxYYlas2T0tjXdOH97XlY2jRzFSxZU1P3JKJkjHLmxu0m908Q28SQVcdBlK29Ofyl2pwGnniExY4wdQJLmqNW9eKa2dmSMUsntR6DryNThKVn9mqUACdXgpT8X2CnQl/DWMGpo80=
    on_success: always
    on_failure: always