Class: CIRunner::Configuration::Project
- Inherits:
-
Object
- Object
- CIRunner::Configuration::Project
- Includes:
- Singleton
- Defined in:
- lib/ci_runner/configuration/project.rb
Overview
A class to interact with a project’s Configuration.
CI Runner tries its best to come out of the box functional. It comes bundled with a set of regexes that detects variety of output. For instance if your project uses RSpec or Minitest AND you haven’t modified their reporters, CI Runner should just work with no extra setup.
However, if your application or Gem has custom reporters, CI Runner set of regexes won’t work, as the output expected will change because of those custom reporters. CI Runner allows to change those regexes thanks to a configuration file you can store on each of your project.
Note that all *_regex configuration value can be either a String or a Serialized Regexp object.
Constant Summary collapse
- CONFIG_PATH =
".github/ci_runner.yml"
Instance Method Summary collapse
-
#buffer_starts_regex ⇒ nil, Regexp
This regex is used to tell CI Runner when to start buffering.
-
#config_file ⇒ Pathname
The path of the configuration file.
-
#gemfile_detection_regex ⇒ nil, Regexp
This regex is used to detect the Gemfile version that was used on a CI.
-
#initialize ⇒ void
constructor
Singleton class.
-
#load! ⇒ void
Load the configuration file from the project into memory.
-
#process_on_new_match? ⇒ nil, Regexp
This is to be used in conjuction with the
buffer_starts_regex
. -
#ruby_detection_regex ⇒ nil, Regexp
This regex is used to detect the Ruby version that was used on a CI.
-
#seed_detection_regex ⇒ nil, Regexp
This regex is used to detect the SEED on a CI.
-
#test_failure_detection_regex ⇒ nil, Regexp
Main detection regex used to detect test failures.
Constructor Details
#initialize ⇒ void
Singleton class. Shouldn’t/Can’t be called directly. Call Project.instance instead.
38 39 40 |
# File 'lib/ci_runner/configuration/project.rb', line 38 def initialize load! end |
Instance Method Details
#buffer_starts_regex ⇒ nil, Regexp
This regex is used to tell CI Runner when to start buffering. The failures will then be matched agains this buffer rather than the whole log output. An example to better understand:
131 132 133 |
# File 'lib/ci_runner/configuration/project.rb', line 131 def buffer_starts_regex to_regexp(@yaml_config.dig("buffer_starts_regex")) end |
#config_file ⇒ Pathname
Returns The path of the configuration file.
228 229 230 |
# File 'lib/ci_runner/configuration/project.rb', line 228 def config_file Pathname(File.(CONFIG_PATH, Dir.pwd)) end |
#gemfile_detection_regex ⇒ nil, Regexp
This regex is used to detect the Gemfile version that was used on a CI. It’s quite common to have a CI testing a gem with different set of dependencies thanks to multiple Gemfiles. If detected, CI Runner will use the same Gemfile from your machine (if it exists) to run the test suite.
Important. Your regex has to contain ONE capturing match, being the Gemfile path.
79 80 81 |
# File 'lib/ci_runner/configuration/project.rb', line 79 def gemfile_detection_regex to_regexp(@yaml_config.dig("gemfile_regex")) end |
#load! ⇒ void
This method returns an undefined value.
Load the configuration file from the project into memory.
45 46 47 |
# File 'lib/ci_runner/configuration/project.rb', line 45 def load! @yaml_config = config_file.exist? ? YAML.safe_load(config_file.read, permitted_classes: [Regexp]) : {} end |
#process_on_new_match? ⇒ nil, Regexp
This is to be used in conjuction with the buffer_starts_regex
. It accepts a boolean value.
This configuration tells CI Runner to process the buffer and find failures each time a new line matching buffer_starts_regex
appears.
To detect the file path of each failing test, we have to go through the stacktrace of each failing tests.
When you set the ‘process_on_new_match` value to true (the default), your regex test_failure_detection_regex
will be matched agains each erroring test.
180 181 182 183 184 |
# File 'lib/ci_runner/configuration/project.rb', line 180 def process_on_new_match? value = @yaml_config.dig("process_on_new_match") value.nil? ? true : value end |
#ruby_detection_regex ⇒ nil, Regexp
This regex is used to detect the Ruby version that was used on a CI. It’s quite common to have a CI testing a gem on different version of Ruby. If detected, CI Runner will use that same Ruby version from your machine (if it exists) to run the test suite.
Important. Your regex has to contain ONE capturing match, being the Ruby version itself.
62 63 64 |
# File 'lib/ci_runner/configuration/project.rb', line 62 def ruby_detection_regex to_regexp(@yaml_config.dig("ruby_regex")) end |
#seed_detection_regex ⇒ nil, Regexp
This regex is used to detect the SEED on a CI. CI Runner aims to rerun failing tests on your machine exactly the same as how it ran on CI, therefore in the same order. The SEED is what determine the order.
Important. Your regex has to contain ONE capturing match, being the SEED value.
95 96 97 |
# File 'lib/ci_runner/configuration/project.rb', line 95 def seed_detection_regex to_regexp(@yaml_config.dig("seed_regex")) end |
#test_failure_detection_regex ⇒ nil, Regexp
Main detection regex used to detect test failures.
Important This regexp 3 named capture groups. The order doesn’t matter.
-
“file_path”
-
“test_name”
-
“class”
Your regex should look something like: /(?<file_path>…)(?<test_name>…)(?<class>…)/
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/ci_runner/configuration/project.rb', line 205 def test_failure_detection_regex regexp = to_regexp(@yaml_config.dig("failures_regex")) return unless regexp expected_captures = ["file_path", "test_name", "class"] difference = expected_captures - regexp.names if difference.any? raise(Error, <<~EOM) The {{warning:failures_regex}} configuration of your project doesn't include expected named captures. CI Runner expects the following Regexp named captures: #{expected_captures.inspect}. Your Regex should look something like {{info:/(?<file_path>...)(?<test_name>...)(?<class>...)/}} EOM end regexp end |