Class: Gemika::Matrix

Inherits:
Object
  • Object
show all
Defined in:
lib/gemika/matrix.rb,
lib/gemika/matrix/travis_config.rb,
lib/gemika/matrix/github_actions_config.rb

Defined Under Namespace

Classes: Row

Constant Summary collapse

COLOR_HEAD =
"\e[44;97m"
COLOR_WARNING =
"\e[33m"
COLOR_SUCCESS =
"\e[32m"
COLOR_FAILURE =
"\e[31m"
COLOR_RESET =
"\e[0m"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Matrix

Returns a new instance of Matrix.



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/gemika/matrix.rb', line 115

def initialize(options)
  @rows = options.fetch(:rows)
  @silent = options.fetch(:silent, false)
  @io = options.fetch(:io, STDOUT)
  @color = options.fetch(:color, true)
  validate = options.fetch(:validate, true)
  @rows.each(&:validate!) if validate
  @results = Env.new_ordered_hash
  @compatible_count = 0
  @all_passed = nil
  @current_ruby = options.fetch(:current_ruby, RUBY_VERSION)
  @aliased_rubys = {}
end

Instance Attribute Details

#current_rubyObject (readonly)

Returns the value of attribute current_ruby.



201
202
203
# File 'lib/gemika/matrix.rb', line 201

def current_ruby
  @current_ruby
end

#rowsObject (readonly)

Returns the value of attribute rows.



201
202
203
# File 'lib/gemika/matrix.rb', line 201

def rows
  @rows
end

Class Method Details

.from_ci_configObject

Builds a Gemika::Matrix from a .travis.yml file, or falls back to a Github Action .yml file

Parameters:

  • options (Hash)


167
168
169
170
171
172
173
174
175
176
177
# File 'lib/gemika/matrix.rb', line 167

def self.from_ci_config
  travis_location = '.travis.yml'
  workflow_location = '.github/workflows/test.yml'
  if File.exist?(travis_location)
    from_travis_yml(:path => travis_location)
  elsif File.exist?(workflow_location)
    from_github_actions_yml(:path => workflow_location)
  else
    raise MissingMatrixDefinition, "expected either a #{travis_location} or a #{workflow_location}"
  end
end

.from_github_actions_yml(options = {}) ⇒ Object

Builds a Gemika::Matrix from the given Github Action workflow definition

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • Path (String)

    to the .yml file.



196
197
198
199
# File 'lib/gemika/matrix.rb', line 196

def self.from_github_actions_yml(options = {})
  rows = GithubActionsConfig.load_rows(options)
  new(options.merge(:rows => rows))
end

.from_travis_yml(options = {}) ⇒ Object

Builds a Gemika::Matrix from the given .travis.yml file.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • Path (String)

    to the .travis.yml file.



185
186
187
188
# File 'lib/gemika/matrix.rb', line 185

def self.from_travis_yml(options = {})
  rows = TravisConfig.load_rows(options)
  new(options.merge(:rows => rows))
end

.generate_github_actions_workflow(options = {}) ⇒ Object



203
204
205
206
207
# File 'lib/gemika/matrix.rb', line 203

def self.generate_github_actions_workflow(options= {})
  require 'gemika/github_actions_generator'
  rows = TravisConfig.load_rows(options)
  GithubActionsGenerator.new(bundler_version: Bundler::VERSION).generate(rows)
end

Instance Method Details

#each(&block) ⇒ Object

Runs the given block for each matrix row that is compatible with the current Ruby.

The row's gemfile will be set as an environment variable, so Bundler will use that gemfile if you shell out in block.

At the end it will print a summary of which rows have passed, failed or were skipped (due to incompatible Ruby version).



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gemika/matrix.rb', line 136

def each(&block)
  @all_passed = true
  rows.each do |row|
    gemfile = row.gemfile
    if row.compatible_with_ruby?(current_ruby)
      @compatible_count += 1

      @aliased_rubys[current_ruby] = row.ruby

      print_title gemfile
      gemfile_passed = Env.with_gemfile(gemfile, row, &block)
      @all_passed &= gemfile_passed
      if gemfile_passed
        @results[row] = tint('Success', COLOR_SUCCESS)
      else
        @results[row] = tint('Failed', COLOR_FAILURE)
      end
    else
      @results[row] = tint("Skipped", COLOR_WARNING)
    end
  end
  print_summary
end