<commit_before>image: ruby:<%= Suspenders::RUBY_VERSION %>

variables:
  GET_SOURCES_ATTEMPTS: 3
  ARTIFACT_DOWNLOAD_ATTEMPTS: 3
  RESTORE_CACHE_ATTEMPTS: 3
  POSTGRES_DB: rails_app_test
  POSTGRES_USER: root
  POSTGRES_PASSWORD: ''
  SELENIUM_REMOTE_URL: "http://selenium__standalone-chrome:4444/wd/hub/"

.services: &rails-services
  - postgres:<%= Suspenders::POSTGRES_VERSION %>
  - selenium/standalone-chrome:latest

.cache: &cache-settings
  key: "$CI_COMMIT_REF_SLUG"
  untracked: true
  policy: pull
  paths:
    - vendor/bundle

stages:
  - setup
  - quality
  - test

prepare:
  stage: setup
  cache:
    <<: *cache-settings
    policy: pull-push
  script:
    - bundle install --retry 3 --deployment --jobs $(nproc)

quality:rubocop:
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec rubocop

quality:slim_lint:
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec slim-lint app/views/

quality:bundler-audit:
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec bundle-audit check --update

quality:brakeman:
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec brakeman -z --skip-files vendor/bundle

quality:rubycritic:
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec rubycritic app/ config/ lib/ --no-browser --minimum-score 94 --format console

test:rspec:
  stage: test
  services: *rails-services
  cache:
    <<: *cache-settings
  script:
    # Install node
    - curl -sL https://deb.nodesource.com/setup_10.x | bash -
    - apt-get install -qq nodejs

    # Install yarn
    - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
    - echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
    - apt-get update -qq && apt-get install -qq yarn

    # Verify node and yarn versions
    - node --version<commit_msg>Run gitlab pipeline only on some conditions<commit_after>image: ruby:<%= Suspenders::RUBY_VERSION %>

variables:
  GET_SOURCES_ATTEMPTS: 3
  ARTIFACT_DOWNLOAD_ATTEMPTS: 3
  RESTORE_CACHE_ATTEMPTS: 3
  POSTGRES_DB: rails_app_test
  POSTGRES_USER: root
  POSTGRES_PASSWORD: ''
  SELENIUM_REMOTE_URL: "http://selenium__standalone-chrome:4444/wd/hub/"

.job-creation-policy: &job-creation-policy
  only:
    - master
    - merge_requests
  except:
    - staging

.services: &rails-services
  - postgres:<%= Suspenders::POSTGRES_VERSION %>
  - selenium/standalone-chrome:latest

.cache: &cache-settings
  key: "$CI_COMMIT_REF_SLUG"
  untracked: true
  policy: pull
  paths:
    - vendor/bundle

stages:
  - setup
  - quality
  - test

prepare:
  <<: *job-creation-policy
  stage: setup
  cache:
    <<: *cache-settings
    policy: pull-push
  script:
    - bundle install --retry 3 --deployment --jobs $(nproc)

quality:rubocop:
  <<: *job-creation-policy
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec rubocop

quality:slim_lint:
  <<: *job-creation-policy
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec slim-lint app/views/

quality:bundler-audit:
  <<: *job-creation-policy
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec bundle-audit check --update

quality:brakeman:
  <<: *job-creation-policy
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec brakeman -z --skip-files vendor/bundle

quality:rubycritic:
  <<: *job-creation-policy
  stage: quality
  cache:
    <<: *cache-settings
  script:
    - bundle check --path vendor/bundle
    - bundle exec rubycritic app/ config/ lib/ --no-browser --minimum-score 94 --format console

test:rspec:
  <<: *job-creation-policy
  stage: test
  services: *rails-services
  cache:
    <<: *cache-settings
  script:
    # Install node
    - curl -sL https://deb.nodesource.com/setup_10.x | bash -
    - apt-get install -qq nodejs

    # Install yarn
    - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
    - echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
    - apt-get update -qq && apt-get install -qq yarn

    # Verify node and yarn versions
    - node --version
{'fraction_non_alphanumeric': 0.12415003290195219, 'fraction_numerical': 0.005264312349199386, 'mean_word_length': 2.8578680203045685, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 9, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5080920', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1576, 'n_words': 369}