<commit_before>image: "dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.4.4-golang-1.9-git-2.17-chrome-67.0-node-8.x-yarn-1.2-postgresql-9.6-graphicsmagick-1.3.29"

.dedicated-runner: &dedicated-runner
  retry: 1
  tags:
    - gitlab-org

.default-cache: &default-cache
  key: "ruby-2.4.4-debian-stretch-with-yarn"
  paths:
    - vendor/ruby
    - .yarn-cache/
    - vendor/gitaly-ruby

.push-cache: &push-cache
  cache:
    <<: *default-cache
    policy: push

.pull-cache: &pull-cache
  cache:
    <<: *default-cache
    policy: pull

variables:
  MYSQL_ALLOW_EMPTY_PASSWORD: "1"
  RAILS_ENV: "test"
  NODE_ENV: "test"
  SIMPLECOV: "true"
  GIT_DEPTH: "20"
  GIT_SUBMODULE_STRATEGY: "none"
  GET_SOURCES_ATTEMPTS: "3"
  KNAPSACK_RSPEC_SUITE_REPORT_PATH: knapsack/${CI_PROJECT_NAME}/rspec_report-master.json
  FLAKY_RSPEC_SUITE_REPORT_PATH: rspec_flaky/report-suite.json

before_script:
  - bundle --version
  - date
  - source scripts/utils.sh
  - date
  - source scripts/prepare_build.sh
  - date

after_script:
  - date

stages:
  - build
  - prepare
  - test
  - post-test
  - pages
  - post-cleanup

# Predefined scopes
.tests-metadata-state: &tests-metadata-state
  <<: *dedicated-runner
  variables:
    TESTS_METADATA_S3_BUCKET: "gitlab-ce-cache"
  before_script:
    - source scripts/utils.sh
  artifacts:
    expire_in: 31d
    paths:
      - knapsack/
      - rspec_flaky/

.use-pg: &use-pg
  services:
    # As of Jan 2018, we don't have a strong reason to upgrade to 9.6 for CI yet,
    # so using the least common denominator ensures backwards compatibility
    # (as many users are still using 9.2).
    - postgres:9.2
    - redis:alpine

.use-mysql: &use-mysql
  services:
    - mysql:5.7
    - redis:alpine

.rails5-variables: &rails5-variables
  script:
    - export RAILS5=${RAILS5}
    - export BUNDLE_GEMFILE=${BUNDLE_GEMFILE}

.rails5: &rails5
  allow_failure: true
  only:
    - /rails5/
  variables:
    BUNDLE_GEMFILE: "Gemfile.rails5"
    RAILS5: "true"

# Skip all jobs except the ones that begin with 'docs/'.
# Used for commits including ONLY documentation changes.
# https://docs.gitlab.com/ce/development/writing_documentation.html#testing
.except-docs: &except-docs
  except:
    - /(^docs[\/-].*|.*-docs$)/

.except-qa: &except-qa
  except:
    - /(^qa[\/-].*|.*-qa$)/

.except-docs-and-qa: &except-docs-and-qa
  except:
    - /(^docs[\/-].*|.*-docs$)/
    - /(^qa[\/-].*|.*-qa$)/

# Jobs that only need to pull cache
.dedicated-no-docs-pull-cache-job: &dedicated-no-docs-pull-cache-job
  <<: *dedicated-runner
  <<: *except-docs
  <<: *pull-cache
  dependencies:
    - setup-test-env
  stage: test

# Jobs that do not need a DB
.dedicated-no-docs-no-db-pull-cache-job: &dedicated-no-docs-no-db-pull-cache-job
  <<: *dedicated-no-docs-pull-cache-job
  variables:
    SETUP_DB: "false"

.dedicated-no-docs-and-no-qa-pull-cache-job: &dedicated-no-docs-and-no-qa-pull-cache-job
  <<: *dedicated-no-docs-pull-cache-job
  <<: *except-docs-and-qa

.single-script-job: &single-script-job
  image: ruby:2.4-alpine
  before_script: []
  stage: build
  cache: {}
  dependencies: []
  variables: &single-script-job-variables
    GIT_STRATEGY: none
  before_script:
    # We need to download the script rather than clone the repo since the
    # package-and-qa job will not be able to run when the branch gets
    # deleted (when merging the MR).
    - export SCRIPT_NAME="${SCRIPT_NAME:-$CI_JOB_NAME}"
    - apk add --update openssl
    - wget $CI_PROJECT_URL/raw/$CI_COMMIT_SHA/scripts/$SCRIPT_NAME
    - chmod 755 $SCRIPT_NAME

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

.rspec-metadata: &rspec-metadata
  <<: *dedicated-runner
  <<: *except-docs-and-qa
  <<: *pull-cache
  <<: *rails5-variables
  stage: test
  script:
    - JOB_NAME=( $CI_JOB_NAME )
    - export CI_NODE_INDEX=${JOB_NAME[-2]}
    - export CI_NODE_TOTAL=${JOB_NAME[-1]}
    - export KNAPSACK_REPORT_PATH=knapsack/${CI_PROJECT_NAME}/${JOB_NAME[0]}_node_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export KNAPSACK_GENERATE_REPORT=true
    - export SUITE_FLAKY_RSPEC_REPORT_PATH=${FLAKY_RSPEC_SUITE_REPORT_PATH}
    - export FLAKY_RSPEC_REPORT_PATH=rspec_flaky/all_${JOB_NAME[0]}_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export NEW_FLAKY_RSPEC_REPORT_PATH=rspec_flaky/new_${JOB_NAME[0]}_${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
    - knapsack rspec "--color --format documentation"
  artifacts:
    expire_in: 31d
    when: always
    paths:
      - coverage/
      - knapsack/
      - rspec_flaky/
      - tmp/capybara/

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

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

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

.rspec-metadata-mysql-rails5: &rspec-metadata-mysql-rails5
  <<: *rspec-metadata-mysql
  <<: *rails5

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

.gitlab-setup: &gitlab-setup
  <<: *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

# DB migration, rollback, and seed jobs
.db-migrate-reset: &db-migrate-reset
  <<: *dedicated-no-docs-and-no-qa-pull-cache-job
  script:
    - bundle exec rake db:migrate:reset

.migration-paths: &migration-paths
  <<: *dedicated-no-docs-and-no-qa-pull-cache-job
  variables:
    SETUP_DB: "false"
  script:
    - git fetch https://gitlab.com/gitlab-org/gitlab-ce.git v9.3.0
    - git checkout -f FETCH_HEAD
    - 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

##
# Trigger a package build in omnibus-gitlab repository
#
package-and-qa:
  <<: *single-script-job
  variables:
    <<: *single-script-job-variables
    SCRIPT_NAME: trigger-build
  retry: 0
  script:
    - ./$SCRIPT_NAME omnibus
  when: manual
  only:
    - //@gitlab-org/gitlab-ce
    - //@gitlab-org/gitlab-ee

# Review docs base
.review-docs: &review-docs
  <<: *dedicated-runner
  <<: *single-script-job
  variables:
    <<: *single-script-job-variables
    SCRIPT_NAME: trigger-build-docs
  environment:
    name: review-docs/$CI_COMMIT_REF_NAME
    # DOCS_REVIEW_APPS_DOMAIN and DOCS_GITLAB_REPO_SUFFIX are secret variables
    # Discussion: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/14236/diffs#note_40140693
    url: http://$DOCS_GITLAB_REPO_SUFFIX-$CI_ENVIRONMENT_SLUG.$DOCS_REVIEW_APPS_DOMAIN/$DOCS_GITLAB_REPO_SUFFIX
    on_stop: review-docs-cleanup

# Trigger a manual docs build in gitlab-docs only on non docs-only branches.
# Useful to preview the docs changes live.
review-docs-deploy-manual:
  <<: *review-docs
  stage: build
  script:
    - gem install gitlab --no-ri --no-rdoc
    - ./$SCRIPT_NAME deploy
  when: manual
  only:
    - branches
  <<: *except-docs-and-qa

# Always trigger a docs build in gitlab-docs only on docs-only branches.
# Useful to preview the docs changes live.
review-docs-deploy:
  <<: *review-docs
  stage: post-test
  script:
    - gem install gitlab --no-ri --no-rdoc
    - ./$SCRIPT_NAME deploy
  only:
    - /(^docs[\/-].*|.*-docs$)/
  <<: *except-qa

# Cleanup remote environment of gitlab-docs
review-docs-cleanup:
  <<: *review-docs
  stage: post-cleanup
  environment:
    name: review-docs/$CI_COMMIT_REF_NAME
    action: stop
  when: manual
  script:
    - gem install gitlab --no-ri --no-rdoc
    - ./$SCRIPT_NAME cleanup

##
# Trigger a docker image build in CNG (Cloud Native GitLab) repository
#
cloud-native-image:
  image: ruby:2.4-alpine
  before_script: []
  stage: build
  allow_failure: true
  variables:
    GIT_DEPTH: "1"<commit_msg>Run the review-docs jobs for gitlab-org repos only<commit_after>image: "dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.4.4-golang-1.9-git-2.17-chrome-67.0-node-8.x-yarn-1.2-postgresql-9.6-graphicsmagick-1.3.29"

.dedicated-runner: &dedicated-runner
  retry: 1
  tags:
    - gitlab-org

.default-cache: &default-cache
  key: "ruby-2.4.4-debian-stretch-with-yarn"
  paths:
    - vendor/ruby
    - .yarn-cache/
    - vendor/gitaly-ruby

.push-cache: &push-cache
  cache:
    <<: *default-cache
    policy: push

.pull-cache: &pull-cache
  cache:
    <<: *default-cache
    policy: pull

variables:
  MYSQL_ALLOW_EMPTY_PASSWORD: "1"
  RAILS_ENV: "test"
  NODE_ENV: "test"
  SIMPLECOV: "true"
  GIT_DEPTH: "20"
  GIT_SUBMODULE_STRATEGY: "none"
  GET_SOURCES_ATTEMPTS: "3"
  KNAPSACK_RSPEC_SUITE_REPORT_PATH: knapsack/${CI_PROJECT_NAME}/rspec_report-master.json
  FLAKY_RSPEC_SUITE_REPORT_PATH: rspec_flaky/report-suite.json

before_script:
  - bundle --version
  - date
  - source scripts/utils.sh
  - date
  - source scripts/prepare_build.sh
  - date

after_script:
  - date

stages:
  - build
  - prepare
  - test
  - post-test
  - pages
  - post-cleanup

# Predefined scopes
.tests-metadata-state: &tests-metadata-state
  <<: *dedicated-runner
  variables:
    TESTS_METADATA_S3_BUCKET: "gitlab-ce-cache"
  before_script:
    - source scripts/utils.sh
  artifacts:
    expire_in: 31d
    paths:
      - knapsack/
      - rspec_flaky/

.use-pg: &use-pg
  services:
    # As of Jan 2018, we don't have a strong reason to upgrade to 9.6 for CI yet,
    # so using the least common denominator ensures backwards compatibility
    # (as many users are still using 9.2).
    - postgres:9.2
    - redis:alpine

.use-mysql: &use-mysql
  services:
    - mysql:5.7
    - redis:alpine

.rails5-variables: &rails5-variables
  script:
    - export RAILS5=${RAILS5}
    - export BUNDLE_GEMFILE=${BUNDLE_GEMFILE}

.rails5: &rails5
  allow_failure: true
  only:
    - /rails5/
  variables:
    BUNDLE_GEMFILE: "Gemfile.rails5"
    RAILS5: "true"

# Skip all jobs except the ones that begin with 'docs/'.
# Used for commits including ONLY documentation changes.
# https://docs.gitlab.com/ce/development/writing_documentation.html#testing
.except-docs: &except-docs
  except:
    - /(^docs[\/-].*|.*-docs$)/

.except-qa: &except-qa
  except:
    - /(^qa[\/-].*|.*-qa$)/

.except-docs-and-qa: &except-docs-and-qa
  except:
    - /(^docs[\/-].*|.*-docs$)/
    - /(^qa[\/-].*|.*-qa$)/

# Jobs that only need to pull cache
.dedicated-no-docs-pull-cache-job: &dedicated-no-docs-pull-cache-job
  <<: *dedicated-runner
  <<: *except-docs
  <<: *pull-cache
  dependencies:
    - setup-test-env
  stage: test

# Jobs that do not need a DB
.dedicated-no-docs-no-db-pull-cache-job: &dedicated-no-docs-no-db-pull-cache-job
  <<: *dedicated-no-docs-pull-cache-job
  variables:
    SETUP_DB: "false"

.dedicated-no-docs-and-no-qa-pull-cache-job: &dedicated-no-docs-and-no-qa-pull-cache-job
  <<: *dedicated-no-docs-pull-cache-job
  <<: *except-docs-and-qa

.single-script-job: &single-script-job
  image: ruby:2.4-alpine
  before_script: []
  stage: build
  cache: {}
  dependencies: []
  variables: &single-script-job-variables
    GIT_STRATEGY: none
  before_script:
    # We need to download the script rather than clone the repo since the
    # package-and-qa job will not be able to run when the branch gets
    # deleted (when merging the MR).
    - export SCRIPT_NAME="${SCRIPT_NAME:-$CI_JOB_NAME}"
    - apk add --update openssl
    - wget $CI_PROJECT_URL/raw/$CI_COMMIT_SHA/scripts/$SCRIPT_NAME
    - chmod 755 $SCRIPT_NAME

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

.rspec-metadata: &rspec-metadata
  <<: *dedicated-runner
  <<: *except-docs-and-qa
  <<: *pull-cache
  <<: *rails5-variables
  stage: test
  script:
    - JOB_NAME=( $CI_JOB_NAME )
    - export CI_NODE_INDEX=${JOB_NAME[-2]}
    - export CI_NODE_TOTAL=${JOB_NAME[-1]}
    - export KNAPSACK_REPORT_PATH=knapsack/${CI_PROJECT_NAME}/${JOB_NAME[0]}_node_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export KNAPSACK_GENERATE_REPORT=true
    - export SUITE_FLAKY_RSPEC_REPORT_PATH=${FLAKY_RSPEC_SUITE_REPORT_PATH}
    - export FLAKY_RSPEC_REPORT_PATH=rspec_flaky/all_${JOB_NAME[0]}_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json
    - export NEW_FLAKY_RSPEC_REPORT_PATH=rspec_flaky/new_${JOB_NAME[0]}_${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
    - knapsack rspec "--color --format documentation"
  artifacts:
    expire_in: 31d
    when: always
    paths:
      - coverage/
      - knapsack/
      - rspec_flaky/
      - tmp/capybara/

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

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

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

.rspec-metadata-mysql-rails5: &rspec-metadata-mysql-rails5
  <<: *rspec-metadata-mysql
  <<: *rails5

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

.gitlab-setup: &gitlab-setup
  <<: *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

# DB migration, rollback, and seed jobs
.db-migrate-reset: &db-migrate-reset
  <<: *dedicated-no-docs-and-no-qa-pull-cache-job
  script:
    - bundle exec rake db:migrate:reset

.migration-paths: &migration-paths
  <<: *dedicated-no-docs-and-no-qa-pull-cache-job
  variables:
    SETUP_DB: "false"
  script:
    - git fetch https://gitlab.com/gitlab-org/gitlab-ce.git v9.3.0
    - git checkout -f FETCH_HEAD
    - 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

##
# Trigger a package build in omnibus-gitlab repository
#
package-and-qa:
  <<: *single-script-job
  variables:
    <<: *single-script-job-variables
    SCRIPT_NAME: trigger-build
  retry: 0
  script:
    - ./$SCRIPT_NAME omnibus
  when: manual
  only:
    - //@gitlab-org/gitlab-ce
    - //@gitlab-org/gitlab-ee

# Review docs base
.review-docs: &review-docs
  <<: *dedicated-runner
  <<: *single-script-job
  variables:
    <<: *single-script-job-variables
    SCRIPT_NAME: trigger-build-docs
  environment:
    name: review-docs/$CI_COMMIT_REF_NAME
    # DOCS_REVIEW_APPS_DOMAIN and DOCS_GITLAB_REPO_SUFFIX are secret variables
    # Discussion: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/14236/diffs#note_40140693
    url: http://$DOCS_GITLAB_REPO_SUFFIX-$CI_ENVIRONMENT_SLUG.$DOCS_REVIEW_APPS_DOMAIN/$DOCS_GITLAB_REPO_SUFFIX
    on_stop: review-docs-cleanup

# Trigger a manual docs build in gitlab-docs only on non docs-only branches.
# Useful to preview the docs changes live.
review-docs-deploy-manual:
  <<: *review-docs
  stage: build
  script:
    - gem install gitlab --no-ri --no-rdoc
    - ./$SCRIPT_NAME deploy
  when: manual
  only:
    - branches@gitlab-org/gitlab-ce
    - branches@gitlab-org/gitlab-ee
  <<: *except-docs-and-qa

# Always trigger a docs build in gitlab-docs only on docs-only branches.
# Useful to preview the docs changes live.
review-docs-deploy:
  <<: *review-docs
  stage: post-test
  script:
    - gem install gitlab --no-ri --no-rdoc
    - ./$SCRIPT_NAME deploy
  only:
    - /(^docs[\/-].*|.*-docs$)/
    - branches@gitlab-org/gitlab-ce
    - branches@gitlab-org/gitlab-ee
  <<: *except-qa

# Cleanup remote environment of gitlab-docs
review-docs-cleanup:
  <<: *review-docs
  stage: post-cleanup
  environment:
    name: review-docs/$CI_COMMIT_REF_NAME
    action: stop
  when: manual
  script:
    - gem install gitlab --no-ri --no-rdoc
    - ./$SCRIPT_NAME cleanup

##
# Trigger a docker image build in CNG (Cloud Native GitLab) repository
#
cloud-native-image:
  image: ruby:2.4-alpine
  before_script: []
  stage: build
  allow_failure: true
  variables:
    GIT_DEPTH: "1"
{'fraction_non_alphanumeric': 0.1383132798573975, 'fraction_numerical': 0.011140819964349376, 'mean_word_length': 3.13949734839751, 'pattern_counts': {'":': 0, '<': 147, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6365627', 'n_tokens_mistral': 7258, 'n_tokens_neox': 6982, 'n_words': 1235}