# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages:
- test
sast:
  stage: test
include:
- template: Security/SAST.gitlab-ci.yml

variables:
  BUNDLE_INSTALL_FLAGS: "--quiet --jobs=$(nproc) --retry=3"
  BUNDLE_FROZEN: "false" # No lockfile!
  K_SOUP_COV_DEBUG: true
  K_SOUP_COV_DO: true
  K_SOUP_COV_HARD: true
  K_SOUP_COV_MIN_BRANCH: 100
  K_SOUP_COV_MIN_LINE: 100
  K_SOUP_COV_VERBOSE: true
  K_SOUP_COV_FORMATTERS: "html,xml,rcov,lcov,json,tty"
  K_SOUP_COV_MULTI_FORMATTERS: true
  K_SOUP_COV_COMMAND_NAME: "RSpec Coverage"

workflow:
  rules:
    # For merge requests, create a pipeline.
    - if: '$CI_MERGE_REQUEST_IID'
    # For default branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
    # For tags, create a pipeline.
    - if: '$CI_COMMIT_TAG'

.test_template-current: &test_definition-current
  image: ruby:${RUBY_VERSION}
  stage: test
  script:
    - gem update --silent --system
    - bundle config --local path vendor
    - bundle install
    - bundle exec rake
  cache:
    key: ${CI_JOB_IMAGE}
    paths:
      - vendor/ruby

.test_template-legacy: &test_definition-legacy
  image: ruby:${RUBY_VERSION}
  stage: test
  script:
    # Because we support EOL Ruby still...
    - gem install rubygems-update -v ${RUBYGEMS_VERSION}
    # Actually updates both RubyGems and Bundler!
    - update_rubygems
    - bundle config --local path vendor
    - bundle install
    - bundle exec rake test
  cache:
    key: ${CI_JOB_IMAGE}
    paths:
      - vendor/ruby

ruby-current:
  variables:
    BUNDLE_GEMFILE: gemfiles/omnibus.gemfile
    K_SOUP_COV_DO: true
  <<: *test_definition-current
  parallel:
    matrix:
      - RUBY_VERSION: ["3.2", "3.3", "3.4"]

ruby-ruby3_1:
  variables:
    RUBYGEMS_VERSION: "3.6.9"
    BUNDLE_GEMFILE: gemfiles/vanilla.gemfile
    K_SOUP_COV_DO: false
  <<: *test_definition-legacy
  parallel:
    matrix:
      - RUBY_VERSION: ["3.1"]

ruby-ruby3_0:
  variables:
    RUBYGEMS_VERSION: "3.5.23"
    BUNDLE_GEMFILE: gemfiles/vanilla.gemfile
    K_SOUP_COV_DO: false
  <<: *test_definition-legacy
  parallel:
    matrix:
      - RUBY_VERSION: ["3.0"]

ruby-ruby2_7:
  variables:
    RUBYGEMS_VERSION: "3.4.22"
    BUNDLE_GEMFILE: gemfiles/vanilla.gemfile
    K_SOUP_COV_DO: false
  <<: *test_definition-legacy
  parallel:
    matrix:
      - RUBY_VERSION: ["2.7"]
