<commit_before>.use-pg: &use-pg
  services:
    - name: postgres:9.6
      command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
    - name: redis:alpine

.use-pg-10: &use-pg-10
  services:
    - name: postgres:10.7
      command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
    - name: redis:alpine

.only-schedules-master: &only-schedules-master
  only:
    - schedules@gitlab-org/gitlab-ce
    - schedules@gitlab-org/gitlab-ee
    - master@gitlab-org/gitlab-ce
    - master@gitlab-org/gitlab-ee
    - master@gitlab/gitlabhq
    - master@gitlab/gitlab-ee

.gitlab-setup: &gitlab-setup
  extends:
    - .dedicated-no-docs-and-no-qa-pull-cache-job
    - .use-pg
  variables:
    SETUP_DB: "false"
  script:
    # Manually clone gitlab-test and only seed this project in
    # db/fixtures/development/04_project.rb thanks to SIZE=1 below
    - git clone https://gitlab.com/gitlab-org/gitlab-test.git
       /home/git/repositories/gitlab-org/gitlab-test.git
    - scripts/gitaly-test-spawn
    - force=yes SIZE=1 FIXTURE_PATH="db/fixtures/development" bundle exec rake gitlab:setup
  artifacts:
    when: on_failure
    expire_in: 1d
    paths:
      - log/development.log

.rake-exec: &rake-exec
  extends: .dedicated-no-docs-no-db-pull-cache-job
  script:
    - bundle exec rake $CI_JOB_NAME

.rspec-metadata: &rspec-metadata
  extends:
    - .dedicated-pull-cache-job
    - .no-docs-and-no-qa
  stage: test
  script:
    - JOB_NAME=( $CI_JOB_NAME )
    - TEST_TOOL=${JOB_NAME[0]}
    - TEST_LEVEL=${JOB_NAME[1]}
    - DATABASE=${JOB_NAME[2]}
    - export KNAPSACK_REPORT_PATH=knapsack/${CI_PROJECT_NAME}/${TEST_TOOL}_${TEST_LEVEL}_${DATABASE}_node_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export KNAPSACK_GENERATE_REPORT=true KNAPSACK_LOG_LEVEL=debug KNAPSACK_TEST_DIR=spec
    - export SUITE_FLAKY_RSPEC_REPORT_PATH=${FLAKY_RSPEC_SUITE_REPORT_PATH}
    - export FLAKY_RSPEC_REPORT_PATH=rspec_flaky/all_${TEST_TOOL}_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export NEW_FLAKY_RSPEC_REPORT_PATH=rspec_flaky/new_${TEST_TOOL}_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export FLAKY_RSPEC_GENERATE_REPORT=true
    - export CACHE_CLASSES=true
    - cp ${KNAPSACK_RSPEC_SUITE_REPORT_PATH} ${KNAPSACK_REPORT_PATH}
    - '[[ -f $FLAKY_RSPEC_REPORT_PATH ]] || echo "{}" > ${FLAKY_RSPEC_REPORT_PATH}'
    - '[[ -f $NEW_FLAKY_RSPEC_REPORT_PATH ]] || echo "{}" > ${NEW_FLAKY_RSPEC_REPORT_PATH}'
    - scripts/gitaly-test-spawn
    - date
    - 'export KNAPSACK_TEST_FILE_PATTERN=$(ruby -r./lib/quality/test_level.rb -e "puts Quality::TestLevel.new.pattern(:${TEST_LEVEL})")'
    - knapsack rspec "--color --format documentation --format RspecJunitFormatter --out junit_rspec.xml --tag level:${TEST_LEVEL} --tag ~geo"
    - date
  artifacts:
    expire_in: 31d
    when: always
    paths:
      - coverage/
      - knapsack/
      - rspec_flaky/
      - rspec_profiling/
      - tmp/capybara/
    reports:
      junit: junit_rspec.xml

.rspec-metadata-pg: &rspec-metadata-pg
  <<: *rspec-metadata
  <<: *use-pg

.rspec-metadata-pg-10: &rspec-metadata-pg-10
  <<: *rspec-metadata
  <<: *use-pg-10
  image: "dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.6.3-golang-1.11-git-2.21-chrome-73.0-node-12.x-yarn-1.16-postgresql-10-graphicsmagick-1.3.29"

# DB migration, rollback, and seed jobs
.db-migrate-reset: &db-migrate-reset
  extends: .dedicated-no-docs-and-no-qa-pull-cache-job
  script:
    - bundle exec rake db:migrate:reset
  dependencies:
    - setup-test-env

.migration-paths: &migration-paths
  extends: .dedicated-no-docs-and-no-qa-pull-cache-job
  variables:
    SETUP_DB: "false"
  script:
    - git fetch https://gitlab.com/gitlab-org/gitlab-ce.git v11.11.0
    - git checkout -f FETCH_HEAD
    - sed -i "s/gem 'oj', '~> 2.17.4'//" Gemfile
    - sed -i "s/gem 'bootsnap', '~> 1.0.0'/gem 'bootsnap'/" Gemfile
    - bundle update google-protobuf grpc bootsnap
    - bundle install $BUNDLE_INSTALL_FLAGS
    - date
    - cp config/gitlab.yml.example config/gitlab.yml
    - bundle exec rake db:drop db:create db:schema:load db:seed_fu
    - date
    - git checkout -f $CI_COMMIT_SHA
    - bundle install $BUNDLE_INSTALL_FLAGS
    - date
    - . scripts/prepare_build.sh
    - date
    - bundle exec rake db:migrate
  dependencies:
    - setup-test-env

setup-test-env:
  extends:
    - .dedicated-runner-default-cache
    - .no-docs
    - .use-pg
  stage: prepare
  script:
    - bundle exec ruby -Ispec -e 'require "spec_helper" ; TestEnv.init'
    - scripts/gitaly-test-build  # Do not use 'bundle exec' here
  artifacts:
    expire_in: 7d
    paths:
      - tmp/tests
      - config/secrets.yml
      - vendor/gitaly-ruby

rspec unit pg:
  <<: *rspec-metadata-pg
  parallel: 25

rspec integration pg:
  <<: *rspec-metadata-pg
  parallel: 6

rspec system pg:
  <<: *rspec-metadata-pg
  parallel: 24

rspec unit pg-10:
  <<: *rspec-metadata-pg-10
  <<: *only-schedules-master
  parallel: 25

rspec integration pg-10:
  <<: *rspec-metadata-pg-10
  <<: *only-schedules-master
  parallel: 6

rspec system pg-10:
  <<: *rspec-metadata-pg-10
  <<: *only-schedules-master
  parallel: 24

rspec-fast-spec-helper:
  <<: *rspec-metadata-pg
  script:
    - bundle exec rspec spec/fast_spec_helper.rb

.rspec-quarantine: &rspec-quarantine
  <<: *only-schedules-master
  script:
    - export CACHE_CLASSES=true
    - scripts/gitaly-test-spawn
    - bin/rspec --color --format documentation --tag quarantine -- spec/

rspec quarantine pg:
  <<: *rspec-metadata-pg
  <<: *rspec-quarantine
  allow_failure: true

static-analysis:
  extends: .dedicated-no-docs-no-db-pull-cache-job
  dependencies:
    - compile-assets
    - compile-assets pull-cache
    - setup-test-env
  script:
    - scripts/static-analysis
  cache:
    key: "debian-stretch-ruby-2.6.3-node-12.x-and-rubocop"
    paths:
      - vendor/ruby
      - .yarn-cache/
      - tmp/rubocop_cache
    policy: pull-push

downtime_check:
  <<: *rake-exec
  except:
    refs:
      - master
      - tags
      - /^[\d-]+-stable(-ee)?$/
      - /(^docs[\/-].*|.*-docs$)/
      - /(^qa[\/-].*|.*-qa$)/
  dependencies:
    - setup-test-env

ee_compat_check:
  <<: *rake-exec
  dependencies: []
  except:
    refs:
      - master
      - tags
      - /[\d-]+-stable(-ee)?/
      - /^security-/
      - branches@<EMAIL>-org/gitlab-ee
      - branches@gitlab/gitlab-ee
  retry: 0
  artifacts:
    name: "${CI_JOB_NAME}_${CI_COMIT_REF_NAME}_${CI_COMMIT_SHA}"
    when: always
    expire_in: 10d
    paths:
      - ee_compat_check/patches/*.patch

db:migrate:reset-pg:
  <<: *db-migrate-reset
  <<: *use-pg

db:check-schema-pg:
  <<: *db-migrate-reset
  <<: *use-pg
  script:
    - source scripts/schema_changed.sh

migration:path-pg:
  <<: *migration-paths
  <<: *use-pg

.db-rollback: &db-rollback
  extends: .dedicated-no-docs-and-no-qa-pull-cache-job
  script:
    - bundle exec rake db:migrate VERSION=20170523121229
    - bundle exec rake db:migrate SKIP_SCHEMA_VERSION_CHECK=true
  dependencies:
    - setup-test-env

db:rollback-pg:
  <<: *db-rollback
  <<: *use-pg

gitlab:setup-pg:<commit_msg>Run the db:rollback-pg CI job from 2018<commit_after>.use-pg: &use-pg
  services:
    - name: postgres:9.6
      command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
    - name: redis:alpine

.use-pg-10: &use-pg-10
  services:
    - name: postgres:10.7
      command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
    - name: redis:alpine

.only-schedules-master: &only-schedules-master
  only:
    - schedules@gitlab-org/gitlab-ce
    - schedules@gitlab-org/gitlab-ee
    - master@gitlab-org/gitlab-ce
    - master@gitlab-org/gitlab-ee
    - master@gitlab/gitlabhq
    - master@gitlab/gitlab-ee

.gitlab-setup: &gitlab-setup
  extends:
    - .dedicated-no-docs-and-no-qa-pull-cache-job
    - .use-pg
  variables:
    SETUP_DB: "false"
  script:
    # Manually clone gitlab-test and only seed this project in
    # db/fixtures/development/04_project.rb thanks to SIZE=1 below
    - git clone https://gitlab.com/gitlab-org/gitlab-test.git
       /home/git/repositories/gitlab-org/gitlab-test.git
    - scripts/gitaly-test-spawn
    - force=yes SIZE=1 FIXTURE_PATH="db/fixtures/development" bundle exec rake gitlab:setup
  artifacts:
    when: on_failure
    expire_in: 1d
    paths:
      - log/development.log

.rake-exec: &rake-exec
  extends: .dedicated-no-docs-no-db-pull-cache-job
  script:
    - bundle exec rake $CI_JOB_NAME

.rspec-metadata: &rspec-metadata
  extends:
    - .dedicated-pull-cache-job
    - .no-docs-and-no-qa
  stage: test
  script:
    - JOB_NAME=( $CI_JOB_NAME )
    - TEST_TOOL=${JOB_NAME[0]}
    - TEST_LEVEL=${JOB_NAME[1]}
    - DATABASE=${JOB_NAME[2]}
    - export KNAPSACK_REPORT_PATH=knapsack/${CI_PROJECT_NAME}/${TEST_TOOL}_${TEST_LEVEL}_${DATABASE}_node_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export KNAPSACK_GENERATE_REPORT=true KNAPSACK_LOG_LEVEL=debug KNAPSACK_TEST_DIR=spec
    - export SUITE_FLAKY_RSPEC_REPORT_PATH=${FLAKY_RSPEC_SUITE_REPORT_PATH}
    - export FLAKY_RSPEC_REPORT_PATH=rspec_flaky/all_${TEST_TOOL}_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export NEW_FLAKY_RSPEC_REPORT_PATH=rspec_flaky/new_${TEST_TOOL}_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export FLAKY_RSPEC_GENERATE_REPORT=true
    - export CACHE_CLASSES=true
    - cp ${KNAPSACK_RSPEC_SUITE_REPORT_PATH} ${KNAPSACK_REPORT_PATH}
    - '[[ -f $FLAKY_RSPEC_REPORT_PATH ]] || echo "{}" > ${FLAKY_RSPEC_REPORT_PATH}'
    - '[[ -f $NEW_FLAKY_RSPEC_REPORT_PATH ]] || echo "{}" > ${NEW_FLAKY_RSPEC_REPORT_PATH}'
    - scripts/gitaly-test-spawn
    - date
    - 'export KNAPSACK_TEST_FILE_PATTERN=$(ruby -r./lib/quality/test_level.rb -e "puts Quality::TestLevel.new.pattern(:${TEST_LEVEL})")'
    - knapsack rspec "--color --format documentation --format RspecJunitFormatter --out junit_rspec.xml --tag level:${TEST_LEVEL} --tag ~geo"
    - date
  artifacts:
    expire_in: 31d
    when: always
    paths:
      - coverage/
      - knapsack/
      - rspec_flaky/
      - rspec_profiling/
      - tmp/capybara/
    reports:
      junit: junit_rspec.xml

.rspec-metadata-pg: &rspec-metadata-pg
  <<: *rspec-metadata
  <<: *use-pg

.rspec-metadata-pg-10: &rspec-metadata-pg-10
  <<: *rspec-metadata
  <<: *use-pg-10
  image: "dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.6.3-golang-1.11-git-2.21-chrome-73.0-node-12.x-yarn-1.16-postgresql-10-graphicsmagick-1.3.29"

# DB migration, rollback, and seed jobs
.db-migrate-reset: &db-migrate-reset
  extends: .dedicated-no-docs-and-no-qa-pull-cache-job
  script:
    - bundle exec rake db:migrate:reset
  dependencies:
    - setup-test-env

.migration-paths: &migration-paths
  extends: .dedicated-no-docs-and-no-qa-pull-cache-job
  variables:
    SETUP_DB: "false"
  script:
    - git fetch https://gitlab.com/gitlab-org/gitlab-ce.git v11.11.0
    - git checkout -f FETCH_HEAD
    - sed -i "s/gem 'oj', '~> 2.17.4'//" Gemfile
    - sed -i "s/gem 'bootsnap', '~> 1.0.0'/gem 'bootsnap'/" Gemfile
    - bundle update google-protobuf grpc bootsnap
    - bundle install $BUNDLE_INSTALL_FLAGS
    - date
    - cp config/gitlab.yml.example config/gitlab.yml
    - bundle exec rake db:drop db:create db:schema:load db:seed_fu
    - date
    - git checkout -f $CI_COMMIT_SHA
    - bundle install $BUNDLE_INSTALL_FLAGS
    - date
    - . scripts/prepare_build.sh
    - date
    - bundle exec rake db:migrate
  dependencies:
    - setup-test-env

setup-test-env:
  extends:
    - .dedicated-runner-default-cache
    - .no-docs
    - .use-pg
  stage: prepare
  script:
    - bundle exec ruby -Ispec -e 'require "spec_helper" ; TestEnv.init'
    - scripts/gitaly-test-build  # Do not use 'bundle exec' here
  artifacts:
    expire_in: 7d
    paths:
      - tmp/tests
      - config/secrets.yml
      - vendor/gitaly-ruby

rspec unit pg:
  <<: *rspec-metadata-pg
  parallel: 25

rspec integration pg:
  <<: *rspec-metadata-pg
  parallel: 6

rspec system pg:
  <<: *rspec-metadata-pg
  parallel: 24

rspec unit pg-10:
  <<: *rspec-metadata-pg-10
  <<: *only-schedules-master
  parallel: 25

rspec integration pg-10:
  <<: *rspec-metadata-pg-10
  <<: *only-schedules-master
  parallel: 6

rspec system pg-10:
  <<: *rspec-metadata-pg-10
  <<: *only-schedules-master
  parallel: 24

rspec-fast-spec-helper:
  <<: *rspec-metadata-pg
  script:
    - bundle exec rspec spec/fast_spec_helper.rb

.rspec-quarantine: &rspec-quarantine
  <<: *only-schedules-master
  script:
    - export CACHE_CLASSES=true
    - scripts/gitaly-test-spawn
    - bin/rspec --color --format documentation --tag quarantine -- spec/

rspec quarantine pg:
  <<: *rspec-metadata-pg
  <<: *rspec-quarantine
  allow_failure: true

static-analysis:
  extends: .dedicated-no-docs-no-db-pull-cache-job
  dependencies:
    - compile-assets
    - compile-assets pull-cache
    - setup-test-env
  script:
    - scripts/static-analysis
  cache:
    key: "debian-stretch-ruby-2.6.3-node-12.x-and-rubocop"
    paths:
      - vendor/ruby
      - .yarn-cache/
      - tmp/rubocop_cache
    policy: pull-push

downtime_check:
  <<: *rake-exec
  except:
    refs:
      - master
      - tags
      - /^[\d-]+-stable(-ee)?$/
      - /(^docs[\/-].*|.*-docs$)/
      - /(^qa[\/-].*|.*-qa$)/
  dependencies:
    - setup-test-env

ee_compat_check:
  <<: *rake-exec
  dependencies: []
  except:
    refs:
      - master
      - tags
      - /[\d-]+-stable(-ee)?/
      - /^security-/
      - <EMAIL>/gitlab-ee
      - branches@gitlab/gitlab-ee
  retry: 0
  artifacts:
    name: "${CI_JOB_NAME}_${CI_COMIT_REF_NAME}_${CI_COMMIT_SHA}"
    when: always
    expire_in: 10d
    paths:
      - ee_compat_check/patches/*.patch

db:migrate:reset-pg:
  <<: *db-migrate-reset
  <<: *use-pg

db:check-schema-pg:
  <<: *db-migrate-reset
  <<: *use-pg
  script:
    - source scripts/schema_changed.sh

migration:path-pg:
  <<: *migration-paths
  <<: *use-pg

.db-rollback: &db-rollback
  extends: .dedicated-no-docs-and-no-qa-pull-cache-job
  script:
    - bundle exec rake db:migrate VERSION=20180101160629
    - bundle exec rake db:migrate SKIP_SCHEMA_VERSION_CHECK=true
  dependencies:
    - setup-test-env

db:rollback-pg:
  <<: *db-rollback
  <<: *use-pg

gitlab:setup-pg:
{'fraction_non_alphanumeric': 0.1498920387267535, 'fraction_numerical': 0.015462840426272897, 'mean_word_length': 2.879492029181302, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5424243', 'n_tokens_mistral': 5916, 'n_tokens_neox': 5702, 'n_words': 885}