Class: Gemika::Matrix
- Inherits:
-
Object
- Object
- Gemika::Matrix
- 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
-
#current_ruby ⇒ Object
readonly
Returns the value of attribute current_ruby.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Class Method Summary collapse
-
.from_ci_config ⇒ Object
Builds a Matrix from a
.travis.yml
file, or falls back to a Github Action .yml file. -
.from_github_actions_yml(options = {}) ⇒ Object
Builds a Matrix from the given Github Action workflow definition.
-
.from_travis_yml(options = {}) ⇒ Object
Builds a Matrix from the given
.travis.yml
file. - .generate_github_actions_workflow(options = {}) ⇒ Object
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Runs the given
block
for each matrix row that is compatible with the current Ruby. -
#initialize(options) ⇒ Matrix
constructor
A new instance of Matrix.
Constructor Details
#initialize(options) ⇒ Matrix
Returns a new instance of Matrix.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gemika/matrix.rb', line 56 def initialize() @rows = .fetch(:rows) @silent = .fetch(:silent, false) @io = .fetch(:io, STDOUT) @color = .fetch(:color, true) validate = .fetch(:validate, true) @rows.each(&:validate!) if validate @results = Env.new_ordered_hash @compatible_count = 0 @all_passed = nil @current_ruby = .fetch(:current_ruby, RUBY_VERSION) end |
Instance Attribute Details
#current_ruby ⇒ Object (readonly)
Returns the value of attribute current_ruby.
138 139 140 |
# File 'lib/gemika/matrix.rb', line 138 def current_ruby @current_ruby end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
138 139 140 |
# File 'lib/gemika/matrix.rb', line 138 def rows @rows end |
Class Method Details
.from_ci_config ⇒ Object
Builds a Gemika::Matrix from a .travis.yml
file, or falls back to a Github Action .yml file
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/gemika/matrix.rb', line 104 def self.from_ci_config travis_location = '.travis.yml' workflow_location = '.github/workflows/test.yml' if File.exists?(travis_location) from_travis_yml(:path => travis_location) elsif File.exists?(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
133 134 135 136 |
# File 'lib/gemika/matrix.rb', line 133 def self.from_github_actions_yml( = {}) rows = GithubActionsConfig.load_rows() new(.merge(:rows => rows)) end |
.from_travis_yml(options = {}) ⇒ Object
Builds a Gemika::Matrix from the given .travis.yml
file.
122 123 124 125 |
# File 'lib/gemika/matrix.rb', line 122 def self.from_travis_yml( = {}) rows = TravisConfig.load_rows() new(.merge(:rows => rows)) end |
.generate_github_actions_workflow(options = {}) ⇒ Object
140 141 142 143 144 |
# File 'lib/gemika/matrix.rb', line 140 def self.generate_github_actions_workflow(= {}) require 'gemika/github_actions_generator' rows = TravisConfig.load_rows() 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).
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gemika/matrix.rb', line 76 def each(&block) @all_passed = true rows.each do |row| gemfile = row.gemfile if row.compatible_with_ruby?(current_ruby) @compatible_count += 1 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 |