services:
 - docker:1.13-dind

stages:
  - check
  - test
  - notify

variables:
  TEST_IMAGE: registry.gitlab.com/gitlab-org/gitlab-build-images:gitlab-qa
  DOCKER_DRIVER: overlay
  DOCKER_HOST: tcp://docker:2375
  QA_ARTIFACTS_DIR: $CI_PROJECT_DIR
  QA_CAN_TEST_GIT_PROTOCOL_V2: 'false'

before_script:
  - bundle install
  - if [ -n "$TRIGGERED_USER" ] && [ -n "$TRIGGER_SOURCE" ]; then
      echo "Pipeline triggered by $TRIGGERED_USER at $TRIGGER_SOURCE";
    fi

check:rubocop:
  stage: check
  image: $TEST_IMAGE
  script: bundle exec rubocop
  except:
    - triggers
  tags:
    - docker

check:rspec:
  stage: check
  image: $TEST_IMAGE
  script: bundle exec rspec
  except:
    - triggers
  tags:
    - docker

.test: &test
  stage: test
  image: $TEST_IMAGE
  tags:
    - docker
  artifacts:
    when: on_failure
    expire_in: 30d
    paths:
      - ./gitlab-qa-run-*

.ce-qa: &ce-qa
  only:
    variables:
      - $RELEASE == null
      - $RELEASE =~ /gitlab-ce/

.ee-qa: &ee-qa
  only:
    variables:
      - $RELEASE == null
      - $RELEASE =~ /gitlab-ee/

.only-qa: &only-qa
  except:
    variables:
      - $RELEASE

.high-capacity: &high-capacity
  tags:
    - docker
    - 7gb
    - triggered-packages

.quarantine: &quarantine
  allow_failure: true

ce:sanity-framework:
  script:
    - ./bin/expect_exit_code_and_text "bin/qa Test::Instance::Image ${RELEASE:=CE} --tag framework" 1 "2 examples, 1 failure"
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ee:sanity-framework:
  script:
    - ./bin/expect_exit_code_and_text "bin/qa Test::Instance::Image ${RELEASE:=EE} --tag framework" 1 "2 examples, 1 failure"
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ce:instance:
  script:
    - bin/qa Test::Instance::Image ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:instance-quarantine:
  script:
    - bin/qa Test::Instance::Image ${RELEASE:=CE} --tag quarantine --tag ~orchestrated
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:instance:
  script:
    - bin/qa Test::Instance::Image ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:instance-quarantine:
  script:
    - bin/qa Test::Instance::Image ${RELEASE:=EE} --tag quarantine --tag ~orchestrated
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ce:docker:
  script:
    - bin/qa Test::Instance::Image ${RELEASE:=CE} --tag docker
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ee:docker:
  script:
    - bin/qa Test::Instance::Image ${RELEASE:=EE} --tag docker
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ce:relative_url:
  script:
    - bin/qa Test::Instance::RelativeUrl ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:relative_url-quarantine:
  script:
    - bin/qa Test::Instance::RelativeUrl ${RELEASE:=CE} --tag quarantine --tag ~orchestrated
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:relative_url:
  script:
    - bin/qa Test::Instance::RelativeUrl ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:relative_url-quarantine:
  script:
    - bin/qa Test::Instance::RelativeUrl ${RELEASE:=EE} --tag quarantine --tag ~orchestrated
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ce:image:
  script:
    - bin/qa Test::Omnibus::Image ${RELEASE:=CE}
  <<: *test
  <<: *ce-qa

ee:image:
  script:
    - bin/qa Test::Omnibus::Image ${RELEASE:=EE}
  <<: *test
  <<: *ee-qa

ce:update:
  script:
    - bin/qa Test::Omnibus::Update ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:update-quarantine:
  script:
    - bin/qa Test::Omnibus::Update ${RELEASE:=CE} ${RELEASE:=CE} --tag quarantine --tag ~orchestrated
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:update:
  script:
    - bin/qa Test::Omnibus::Update ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:update-quarantine:
  script:
    - bin/qa Test::Omnibus::Update ${RELEASE:=EE} ${RELEASE:=EE} --tag quarantine --tag ~orchestrated
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ce:upgrade:
  script:
    - bin/qa Test::Omnibus::Upgrade
  <<: *test
  <<: *high-capacity
  <<: *only-qa

ce:upgrade-quarantine:
  script:
    - bin/qa Test::Omnibus::Upgrade CE --tag quarantine --tag ~orchestrated
  <<: *test
  <<: *high-capacity
  <<: *only-qa
  <<: *quarantine

ee-previous-to-ce:update:
  script:
     - bin/qa Test::Omnibus::Update EE CE
  <<: *test
  <<: *high-capacity
  <<: *only-qa

ee-previous-to-ce:update-quarantine:
  script:
     - bin/qa Test::Omnibus::Update EE CE --tag quarantine --tag ~orchestrated
  <<: *test
  <<: *high-capacity
  <<: *only-qa
  <<: *quarantine

ce:mattermost:
  script:
    - bin/qa Test::Integration::Mattermost ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:mattermost-quarantine:
  script:
    - bin/qa Test::Integration::Mattermost ${RELEASE:=CE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:mattermost:
  script:
    - bin/qa Test::Integration::Mattermost ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:mattermost-quarantine:
  script:
    - bin/qa Test::Integration::Mattermost ${RELEASE:=EE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ee:geo:
  script:
    - bin/qa Test::Integration::Geo ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:geo-quarantine:
  script:
    - bin/qa Test::Integration::Geo ${RELEASE:=EE} -- --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ce:ldap_no_tls:
  script:
    - bin/qa Test::Integration::LDAPNoTLS ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:ldap_no_tls-quarantine:
  script:
    - bin/qa Test::Integration::LDAPNoTLS ${RELEASE:=CE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:ldap_no_tls:
  script:
    - bin/qa Test::Integration::LDAPNoTLS ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:ldap_no_tls-quarantine:
  script:
    - bin/qa Test::Integration::LDAPNoTLS ${RELEASE:=EE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ce:ldap_tls:
  script:
    - bin/qa Test::Integration::LDAPTLS ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:ldap_tls-quarantine:
  script:
    - bin/qa Test::Integration::LDAPTLS ${RELEASE:=CE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:ldap_tls:
  script:
    - bin/qa Test::Integration::LDAPTLS ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:ldap_tls-quarantine:
  script:
    - bin/qa Test::Integration::LDAPTLS ${RELEASE:=EE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ce:instance_saml:
  script:
  - bin/qa Test::Integration::InstanceSAML ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:instance_saml-quarantine:
  script:
  - bin/qa Test::Integration::InstanceSAML ${RELEASE:=CE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:instance_saml:
  script:
  - bin/qa Test::Integration::InstanceSAML ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:instance_saml-quarantine:
  script:
  - bin/qa Test::Integration::InstanceSAML ${RELEASE:=EE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ee:group_saml:
  script:
  - bin/qa Test::Integration::GroupSAML ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:group_saml-quarantine:
  script:
  - bin/qa Test::Integration::GroupSAML ${RELEASE:=EE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ce:kubernetes:
  script:
    - bin/qa Test::Integration::Kubernetes ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:kubernetes-quarantine:
  script:
    - bin/qa Test::Integration::Kubernetes ${RELEASE:=CE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:kubernetes:
  script:
    - bin/qa Test::Integration::Kubernetes ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:kubernetes-quarantine:
  script:
    - bin/qa Test::Integration::Kubernetes ${RELEASE:=EE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ce:object_storage:
  script:
    - bin/qa Test::Integration::ObjectStorage ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:object_storage-quarantine:
  script:
    - bin/qa Test::Integration::ObjectStorage ${RELEASE:=CE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:object_storage:
  script:
    - bin/qa Test::Integration::ObjectStorage ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:object_storage-quarantine:
  script:
    - bin/qa Test::Integration::ObjectStorage ${RELEASE:=EE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

ce:oauth:
  script:
    - bin/qa Test::Integration::OAuth ${RELEASE:=CE}
  <<: *test
  <<: *high-capacity
  <<: *ce-qa

ce:oauth-quarantine:
  script:
    - bin/qa Test::Integration::OAuth ${RELEASE:=CE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ce-qa
  <<: *quarantine

ee:oauth:
  script:
    - bin/qa Test::Integration::OAuth ${RELEASE:=EE}
  <<: *test
  <<: *high-capacity
  <<: *ee-qa

ee:oauth-quarantine:
  script:
    - bin/qa Test::Integration::OAuth ${RELEASE:=EE} --tag quarantine
  <<: *test
  <<: *high-capacity
  <<: *ee-qa
  <<: *quarantine

.notify_upstream_commit: &notify_upstream_commit
  stage: notify
  image: $TEST_IMAGE
  before_script:
    - gem install gitlab --no-document
  only:
    variables:
      - $TOP_UPSTREAM_SOURCE_PROJECT
      - $TOP_UPSTREAM_SOURCE_SHA

notify_upstream_commit:success:
  <<: *notify_upstream_commit
  script:
    - bin/notify_upstream_commit success
  when: on_success

notify_upstream_commit:failure:
  <<: *notify_upstream_commit
  script:
    - bin/notify_upstream_commit failure
  when: on_failure

.notify_slack: &notify_slack
  image: alpine
  stage: notify
  dependencies: []
  cache: {}
  before_script:
    - apk update && apk add git curl bash
  only:
    variables:
      - $TOP_UPSTREAM_SOURCE_JOB

notify_slack:
  <<: *notify_slack
  script:
    - bin/slack quality-alerts "☠️ Pipeline on \`$CI_BUILD_REF_NAME\` failed! ☠️ Commit \`$(git log -1 --oneline | sed 's|\"|\\\\\"|g')\` See $CI_PIPELINE_URL (triggered from $TOP_UPSTREAM_SOURCE_JOB)" ci_failing
  when: on_failure