Skip to content
代码片段 群组 项目
代码所有者
将用户和群组指定为特定文件更改的核准人。 了解更多。
main.gitlab-ci.yml 7.70 KiB
include:
  - local: .gitlab/ci/global.gitlab-ci.yml
  - local: .gitlab/ci/qa-common/main.gitlab-ci.yml
  - local: .gitlab/ci/qa-common/rules.gitlab-ci.yml
  - local: .gitlab/ci/qa-common/variables.gitlab-ci.yml

# code pattern changes
.code-pattern-changes: &code-pattern-changes
  if: $MR_CODE_PATTERNS == "true"

# Run all tests when QA framework changes present, full suite execution is explicitly enabled or a feature flag file is removed
.qa-run-all-tests: &qa-run-all-tests
  if: $QA_FRAMEWORK_CHANGES == "true" || $QA_RUN_ALL_TESTS == "true" || $QA_RUN_ALL_E2E_LABEL == "true" || $QA_FEATURE_FLAGS =~ /deleted/

.rules:gdk:qa-selective:
  rules:
    - <<: *code-pattern-changes
      when: never
    - !reference [.rules:test:qa-selective, rules]
    - if: $QA_SUITES =~ /Test::Instance::Blocking/

.rules:gdk:qa-parallel:
  rules:
    # To account for cases where a group label is set which may trigger selective execution
    # But we want to execute full reliable suite on gdk in case of code-pattern-changes
    - <<: *code-pattern-changes
      variables:
        QA_TESTS: ""
    - !reference [.rules:test:qa-parallel, rules]
    - if: $QA_SUITES =~ /Test::Instance::Blocking/
    - !reference [.rules:test:manual, rules]

.rules:gdk:qa-smoke:
  rules:
    - <<: *code-pattern-changes
      variables:
        QA_TESTS: ""
    - <<: *qa-run-all-tests
      variables:
        QA_TESTS: ""
    - if: $QA_SUITES =~ /Test::Instance::Smoke/
    - !reference [.rules:test:manual, rules]

.rules:test:gdk-load-balancer-changes:
  rules:
    - when: manual
      allow_failure: true
      changes:
        - ".gitlab/ci/test-on-gdk/**"
        - "lib/gitlab/database/load_balancing/**/*"

.with-gdk-log:
  after_script:
    - mv $CI_BUILDS_DIR/*.log $CI_PROJECT_DIR/

.gdk-qa-base:
  image: ${REGISTRY_HOST}/${REGISTRY_GROUP}/gitlab-build-images/debian-${DEBIAN_VERSION}-ruby-${RUBY_VERSION}:bundler-${BUNDLER_VERSION}-git-2.36-lfs-2.9-chrome-${CHROME_VERSION}-docker-${DOCKER_VERSION}-gcloud-383-kubectl-1.23
  extends:
    - .qa-cache
    - .default-retry
    - .gitlab-qa-report
  stage: test
  services:
    - name: docker:${DOCKER_VERSION}-dind
    - name: ${GDK_IMAGE}
      alias: gdk.test
      # CI setup will tail each component in to separate file
      # Override default command so we don't tail all of the logs to stdout unnecessarily
      command: [gdk, tail, rails-web]
  tags:
    - e2e
  variables:
    DOCKER_HOST: tcp://docker:2375
    QA_GENERATE_ALLURE_REPORT: "true"
    QA_CAN_TEST_PRAEFECT: "false"
    QA_INTERCEPT_REQUESTS: "false"
    QA_SUITE_STATUS_ENV_FILE: "$CI_PROJECT_DIR/suite_status.env"
    QA_DOCKER_NETWORK: host
    GITLAB_QA_ADMIN_ACCESS_TOKEN: $QA_ADMIN_ACCESS_TOKEN
    RSPEC_REPORT_OPTS: "--order random --force-color --format documentation --format RspecJunitFormatter --out tmp/rspec-${CI_JOB_ID}.xml --format QA::Support::JsonFormatter --out tmp/rspec-${CI_JOB_ID}.json  --format html --out tmp/rspec-${CI_JOB_ID}.htm"
    GDK_URL: http://gdk.test:3000
    FF_NETWORK_PER_BUILD: "true"
  before_script:
    - echo "SUITE_RAN=true" > "$QA_SUITE_STATUS_ENV_FILE"
    - echo -e "\e[0Ksection_start:`date +%s`:install_gems[collapsed=true]\r\e[0KInstall gems"
    - source scripts/utils.sh
    - cd qa && bundle config set --local without 'development' && bundle install
    - echo -e "\e[0Ksection_end:`date +%s`:install_gems\r\e[0K"
  script:
    - export QA_COMMAND="bundle exec bin/qa ${QA_SCENARIO:=Test::Instance::All} $GDK_URL $GITLAB_QA_OPTS -- $QA_TESTS $QA_RSPEC_TAGS $RSPEC_REPORT_OPTS"
    - echo "Running - '$QA_COMMAND'"
    - eval "$QA_COMMAND"
  after_script:
    - !reference [.with-gdk-log, after_script]
    - !reference [.gitlab-qa-report, after_script]
  artifacts:
    paths:
      - qa/tmp
      - ${CI_PROJECT_DIR}/*.log
    reports:
      junit: qa/tmp/rspec-*.xml
      dotenv: "$QA_SUITE_STATUS_ENV_FILE"
    expire_in: 7 days
    when: always

# Take the existing GDK docker image and reconfigure it with Postgres load
# balancing. Adding 5s lag to 1 of the replicas to validate robustness of
# the load balancer.
.gdk-with-load-balancer-setup:
  variables:
    WITH_LOAD_BALANCER: "true"

# ==========================================
# Pre stage
# ==========================================
# override .download-knapsack-report job to not depend on qa-image build
download-knapsack-report:
  extends:
    - .download-knapsack-report
    - .ruby-image
    - .bundler-variables
    - .qa-cache
    - .rules:download-knapsack
  variables:
    GIT_STRATEGY: clone
  before_script:
    - cd qa && bundle install
  after_script: []

# ==========================================
# Test stage
# ==========================================

# ------------------------------------------
# Blocking tests
# ------------------------------------------
gdk-qa-smoke:
  extends:
    - .gdk-qa-base
    - .rules:gdk:qa-smoke
  variables:
    QA_SCENARIO: Test::Instance::Smoke
    QA_RUN_TYPE: gdk-qa-smoke

gdk-qa-blocking:
  extends:
    - .gdk-qa-base
    - .rules:gdk:qa-parallel
  variables:
    QA_SCENARIO: Test::Instance::Blocking
    QA_RUN_TYPE: gdk-qa-blocking
  parallel: 10

gdk-qa-blocking-selective:
  extends:
    - .gdk-qa-base
    - .rules:gdk:qa-selective
  variables:
    QA_SCENARIO: Test::Instance::Blocking
    QA_RUN_TYPE: gdk-qa-blocking

# ------------------------------------------
# Non Blocking tests
# ------------------------------------------
gdk-qa-smoke-with-load-balancer:
  extends:
    - .gdk-qa-base
    - .gdk-with-load-balancer-setup
    - .with-gdk-log
  variables:
    QA_SCENARIO: Test::Instance::Smoke
    QA_RUN_TYPE: gdk-qa-smoke
  artifacts:
    paths:
      - gdk.log
    reports:
      dotenv: ""
  rules:
    - !reference [".rules:test:never-schedule-pipeline", rules]
    - !reference [".rules:test:gdk-load-balancer-changes", rules]

gdk-qa-blocking-with-load-balancer:
  extends:
    - .gdk-qa-base
    - .gdk-with-load-balancer-setup
    - .with-gdk-log
  variables:
    QA_SCENARIO: Test::Instance::Blocking
    QA_RUN_TYPE: gdk-qa-blocking
  parallel: 5
  artifacts:
    paths:
      - log
    reports:
      dotenv: ""
  rules:
    - !reference [".rules:test:never-schedule-pipeline", rules]
    - !reference [".rules:test:gdk-load-balancer-changes", rules]

gdk-qa-non-blocking:
  extends:
    - .gdk-qa-base
    - .with-gdk-log
  variables:
    QA_SCENARIO: Test::Instance::NonBlocking
    QA_RUN_TYPE: gdk-qa-non-blocking
  parallel: 5
  allow_failure: true
  artifacts:
    paths:
      - log
    reports:
      dotenv: ""
  rules:
    # run tests on master pipelines to collect metrics and move tests to `blocking` job until `non-blocking` job
    # is removed entirely
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
    - when: manual

# ==========================================
# Post test stage
# ==========================================
e2e-test-report:
  extends: .rules:report:allure-report
  variables:
    ALLURE_REPORT_RESULTS_GLOB: "qa/tmp/allure-results"

upload-knapsack-report:
  extends:
    - .upload-knapsack-report
    - .rules:report:process-results
  variables:
    QA_KNAPSACK_REPORT_FILE_PATTERN: $CI_PROJECT_DIR/qa/tmp/knapsack/*/*.json

export-test-metrics:
  extends:
    - .export-test-metrics
    - .rules:report:process-results
  variables:
    QA_METRICS_REPORT_FILE_PATTERN: $CI_PROJECT_DIR/qa/tmp/test-metrics-*.json

.gitlab-qa-report:
  variables:
    QA_RSPEC_JSON_FILE_PATTERN: $CI_PROJECT_DIR/qa/tmp/rspec-*.json
    QA_SYSTEM_LOG_FILE_PATTERN: $CI_PROJECT_DIR/test_output/logs

generate-test-session:
  extends:
    - .generate-test-session
    - .rules:report:process-results
  variables:
    QA_RSPEC_JSON_FILE_PATTERN: $CI_PROJECT_DIR/qa/tmp/rspec-*.json

notify-slack:
  extends:
    - .notify-slack
    - .rules:report:process-results
  variables:
    QA_RSPEC_XML_FILE_PATTERN: $CI_PROJECT_DIR/qa/tmp/rspec-*.xml