mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-07-20 16:46:17 +00:00
113 lines
3.6 KiB
YAML
113 lines
3.6 KiB
YAML
# The template generates jobs for gems vendored in the main GitLab project
|
|
# under `gem_path_prefix` (defaults to `gems/`).
|
|
#
|
|
# Inputs
|
|
# - `gem_name`: The name of the gem, i.e. if the gem is located at `gems/gitlab-rspec`, `gem_name` should be set to `gitlab-rspec`.
|
|
# - `gem_path_prefix`: The prefix of the gem path, i.e. if the gem is located at `vendor/gems/gitlab-rspec`, `gem_path_prefix` should be set to `vendor/gems/`. Defaults to `gems/`.
|
|
# - `skip_gem_validation`: Whether a validation should be performed.. Defaults to `false`.
|
|
spec:
|
|
inputs:
|
|
gem_name:
|
|
gem_path_prefix:
|
|
default: "gems/"
|
|
skip_gem_validation:
|
|
type: boolean
|
|
default: false
|
|
---
|
|
workflow:
|
|
name: '[$[[inputs.gem_name]] gem] Ruby $RUBY_VERSION pipeline'
|
|
rules:
|
|
- when: always
|
|
|
|
variables:
|
|
BUNDLE_PATH: "vendor"
|
|
BUNDLE_FROZEN: "true"
|
|
GIT_DEPTH: "20"
|
|
# 'GIT_STRATEGY: clone' optimizes the pack-objects cache hit ratio
|
|
GIT_STRATEGY: "clone"
|
|
GIT_SUBMODULE_STRATEGY: "none"
|
|
GET_SOURCES_ATTEMPTS: "3"
|
|
# Default Ruby version for jobs that don't use .ruby_matrix
|
|
RUBY_VERSION: "${RUBY_VERSION_DEFAULT}"
|
|
|
|
include:
|
|
- local: .gitlab/ci/version.yml
|
|
|
|
default:
|
|
tags:
|
|
- gitlab-org
|
|
image: ${GITLAB_DEPENDENCY_PROXY_ADDRESS}ruby:${RUBY_VERSION}
|
|
cache:
|
|
key: "$[[inputs.gem_name]]-${RUBY_VERSION}"
|
|
paths:
|
|
- "$[[inputs.gem_path_prefix]]$[[inputs.gem_name]]/vendor/ruby"
|
|
before_script:
|
|
- cp config/{database.yml.postgresql,database.yml}
|
|
- "sed -i 's/username: postgres$/username: gitlab/g' config/database.yml"
|
|
- "sed -i 's/password:\\s*$/password: password/g' config/database.yml"
|
|
- "sed -i 's/host: localhost$/host: postgres/g' config/database.yml"
|
|
- cd $[[inputs.gem_path_prefix]]$[[inputs.gem_name]]
|
|
- ruby -v # Print out ruby version for debugging
|
|
- bundle_version=$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1 | sed -e 's/[[:space:]]//')
|
|
- gem install bundler --version "$bundle_version" --no-document # Bundler is not installed with the image
|
|
- bundle config # Show bundler configuration
|
|
- bundle install --jobs=$(nproc) --retry=3
|
|
after_script:
|
|
- source $CI_PROJECT_DIR/scripts/utils.sh
|
|
|
|
.ruby_matrix:
|
|
parallel:
|
|
matrix:
|
|
- RUBY_VERSION: ["${RUBY_VERSION_DEFAULT}", "${RUBY_VERSION_NEXT}"]
|
|
|
|
.ruby_and_postgres_matrix:
|
|
services:
|
|
- name: postgres:${POSTGRES_VERSION}
|
|
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
|
|
parallel:
|
|
matrix:
|
|
- RUBY_VERSION: ["${RUBY_VERSION_DEFAULT}", "${RUBY_VERSION_NEXT}"]
|
|
POSTGRES_VERSION: ["14", "15", "16"]
|
|
|
|
validate-gem:
|
|
rules:
|
|
- if: "'$[[inputs.skip_gem_validation]]' == 'true'"
|
|
when: never
|
|
# Validate all gems stored in `gems/`.
|
|
- if: "'$[[inputs.gem_path_prefix]]' == 'gems/'"
|
|
script:
|
|
- $CI_PROJECT_DIR/scripts/validate-monorepo-gem "$[[inputs.gem_name]]"
|
|
|
|
validate-gemfile-lock:
|
|
rules:
|
|
# Validate all Gemfile.lock stored in `gems/`.
|
|
- if: "'$[[inputs.gem_path_prefix]]' == 'gems/'"
|
|
exists: ["$[[inputs.gem_path_prefix]]$[[inputs.gem_name]]/Gemfile.lock"]
|
|
extends:
|
|
- .ruby_matrix
|
|
script:
|
|
- bundle lock --add-checksums
|
|
|
|
rubocop:
|
|
rules:
|
|
- exists: ["$[[inputs.gem_path_prefix]]$[[inputs.gem_name]]/.rubocop.yml"]
|
|
extends:
|
|
- .ruby_matrix
|
|
script:
|
|
- bundle exec rubocop
|
|
|
|
rspec:
|
|
extends:
|
|
- .ruby_and_postgres_matrix
|
|
variables:
|
|
POSTGRES_USER: gitlab
|
|
POSTGRES_PASSWORD: password
|
|
script:
|
|
- RAILS_ENV=test bundle exec rspec
|
|
coverage: '/LOC \((\d+\.\d+%)\) covered.$/'
|
|
artifacts:
|
|
expire_in: 31d
|
|
when: always
|
|
paths:
|
|
- coverage/
|