File: gem.gitlab-ci.yml

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (92 lines) | stat: -rw-r--r-- 2,897 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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:
    bundle_gemfiles:
      type: array
      default: ['Gemfile']
    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: "ruby:${RUBY_VERSION}"
  cache:
    key: "$[[inputs.gem_name]]-${RUBY_VERSION}"
    paths:
      - "$[[inputs.gem_path_prefix]]$[[inputs.gem_name]]/vendor/ruby"
  before_script:
    - cd $[[inputs.gem_path_prefix]]$[[inputs.gem_name]]
    - ruby -v                                   # Print out ruby version for debugging
    - gem update --system
    - 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

.ruby_matrix:
  parallel:
    matrix:
      - RUBY_VERSION: ["${RUBY_VERSION_DEFAULT}", "${RUBY_VERSION_NEXT}"]

.ruby_on_rails_matrix:
  parallel:
    matrix:
      - RUBY_VERSION: ["${RUBY_VERSION_DEFAULT}", "${RUBY_VERSION_NEXT}"]
      - BUNDLE_GEMFILE: $[[inputs.bundle_gemfiles]]

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]]"

rubocop:
  extends: .ruby_matrix
  rules:
    - exists: ["$[[inputs.gem_path_prefix]]$[[inputs.gem_name]]/.rubocop.yml"]
  script:
    - bundle exec rubocop

rspec:
  extends: .ruby_on_rails_matrix
  script:
    - RAILS_ENV=test bundle exec rspec
  coverage: '/LOC \((\d+\.\d+%)\) covered.$/'
  artifacts:
    expire_in: 31d
    when: always
    paths:
      - coverage/