matrixeval-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4af8c6ab00f9e0a26f787dc9e3161f92c824f8aa2f06bd6809ff6b7875535d22
4
+ data.tar.gz: 6dc2c0275ba1b28a733f8bc72f627ac53cce9aae606087b9becb5b0a2c23fe7b
5
+ SHA512:
6
+ metadata.gz: c37a896625ce715a31fdc3506139aaa1025412c3f354cd5d8874ec6c3412c460757c08868e120ac412908c15bd3b686236b7bd4dfb891793590fa85df9b99078
7
+ data.tar.gz: 4610fa81ab3b5a00ab202ecf1a082ababc89f48a9af23d826e41dd1252528e61e837761c4d422c59a2e1ebc5942b4e785303d20e22567b5f46e078d43aedc8e8
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-02-06
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hopper.gee@hey.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in matrixeval-ruby.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "minitest-focus"
13
+ gem "byebug"
14
+ gem "mocha"
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ matrixeval-ruby (0.1.0)
5
+ concurrent-ruby
6
+ rainbow (~> 3.1)
7
+ terminal-table
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ byebug (11.1.3)
13
+ concurrent-ruby (1.1.9)
14
+ minitest (5.15.0)
15
+ minitest-focus (1.3.1)
16
+ minitest (>= 4, < 6)
17
+ mocha (1.13.0)
18
+ rainbow (3.1.1)
19
+ rake (13.0.6)
20
+ terminal-table (3.0.2)
21
+ unicode-display_width (>= 1.1.1, < 3)
22
+ unicode-display_width (2.1.0)
23
+
24
+ PLATFORMS
25
+ x86_64-darwin-19
26
+ x86_64-linux
27
+
28
+ DEPENDENCIES
29
+ byebug
30
+ matrixeval-ruby!
31
+ minitest (~> 5.0)
32
+ minitest-focus
33
+ mocha
34
+ rake (~> 13.0)
35
+
36
+ BUNDLED WITH
37
+ 2.2.32
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Hopper Gee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Matrixeval::Ruby
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/matrixeval/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'matrixeval-ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install matrixeval-ruby
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/matrixeval-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/matrixeval-ruby/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Matrixeval::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/matrixeval-ruby/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/matrixeval/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "matrixeval/ruby"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/test ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ system("ruby -Ilib:test #{ARGV.join(" ")}")
data/exe/matrixeval ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'matrixeval/ruby'
4
+ puts "Hello, MatrixEval!"
5
+ Matrixeval.start(ARGV)
data/exe/meval ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'matrixeval/ruby'
4
+ puts "Hello, MatrixEval!"
5
+ Matrixeval.start(ARGV)
@@ -0,0 +1,38 @@
1
+ module Matrixeval
2
+ module Ruby
3
+ class CommandLine
4
+ class ParseContextArguments
5
+ class << self
6
+ def call(context_arguments)
7
+ new(context_arguments).call
8
+ end
9
+ end
10
+
11
+ attr_reader :context_arguments, :options
12
+
13
+ def initialize(context_arguments)
14
+ @context_arguments = context_arguments
15
+ @options = {}
16
+ end
17
+
18
+ def call
19
+ parse!
20
+ options
21
+ end
22
+
23
+ private
24
+
25
+ def parse!
26
+ OptionParser.new do |opts|
27
+ opts.banner = "Usage: meval/matrixeval --[VECTOR_KEY] [VECTOR_CHOICE] [COMMAND] [COMMAND_OPTIONS]"
28
+
29
+ Config.vectors.each do |vector|
30
+ opts.on("--#{vector.key} [VERSION]", "Set #{vector.key} version")
31
+ end
32
+ end.parse!(context_arguments, into: options)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ require_relative "./command_line/parse_context_arguments"
2
+
3
+ module Matrixeval
4
+ module Ruby
5
+ class CommandLine
6
+
7
+ attr_reader :argv
8
+
9
+ def initialize(argv)
10
+ @argv = argv
11
+ end
12
+
13
+ def init?
14
+ argv[0] == 'init'
15
+ end
16
+
17
+ def all?
18
+ argv[0] == 'all'
19
+ end
20
+
21
+ def context_options
22
+ ParseContextArguments.call(context_arguments)
23
+ end
24
+
25
+ def context_arguments
26
+ argv[0...seperator_index]
27
+ end
28
+
29
+ def rest_arguments
30
+ argv[seperator_index..-1]
31
+ end
32
+
33
+ private
34
+
35
+ def seperator_index
36
+ argv.index do |argument|
37
+ seperator_commands.include?(argument)
38
+ end
39
+ end
40
+
41
+ def seperator_commands
42
+ ['rake', 'rspec', 'bundle', 'bash']
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,35 @@
1
+ module Matrixeval
2
+ module Ruby
3
+ class Config
4
+ class YAML
5
+ class << self
6
+
7
+ def create
8
+ return if File.exist?(path)
9
+
10
+ FileUtils.cp(template_path, path)
11
+ end
12
+
13
+ def template_path
14
+ Matrixeval::Ruby.root.join(
15
+ "lib/matrixeval/ruby/templates/matrixeval.yml"
16
+ )
17
+ end
18
+
19
+ def path
20
+ Matrixeval.working_dir.join("matrixeval.yml")
21
+ end
22
+
23
+ def [](key)
24
+ yaml[key]
25
+ end
26
+
27
+ def yaml
28
+ ::YAML.load File.read(path)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,55 @@
1
+ require 'yaml'
2
+ require_relative "./vector"
3
+ require_relative "./config/yaml"
4
+
5
+ module Matrixeval
6
+ module Ruby
7
+ class Config
8
+ class << self
9
+
10
+ def version
11
+ YAML["version"]
12
+ end
13
+
14
+ def target
15
+ YAML["target"]
16
+ end
17
+
18
+ def vectors
19
+ @vectors = YAML["matrix"].map do |key, vector_config|
20
+ Vector.new(key, vector_config)
21
+ end
22
+ end
23
+
24
+ def main_vector
25
+ vectors.find(&:main?)
26
+ end
27
+
28
+ def rest_vectors
29
+ vectors.reject(&:main?)
30
+ end
31
+
32
+ def variant_combinations
33
+ main_vector_variants.product(*rest_vector_variants_matrix)
34
+ end
35
+
36
+ def main_vector_variants
37
+ main_vector.variants
38
+ end
39
+
40
+ def rest_vector_variants_matrix
41
+ rest_vectors.map(&:variants)
42
+ end
43
+
44
+ def exclusions
45
+ YAML["exclude"] || []
46
+ end
47
+
48
+ def parallel_workers
49
+ YAML["parallel_workers"] || "number_of_processors"
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,67 @@
1
+ module Matrixeval
2
+ module Ruby
3
+ class Context
4
+ class FindByCommandOptions
5
+ class << self
6
+ def call(options)
7
+ new(options).call
8
+ end
9
+ end
10
+
11
+ attr_reader :options
12
+
13
+ def initialize(options)
14
+ @options = options
15
+ end
16
+
17
+ def call
18
+ context = Context.all.find do |context|
19
+ context.main_variant == main_variant &&
20
+ context.rest_variants == rest_variants
21
+ end
22
+
23
+ raise Error.new("Can't find a corresponding matrix") if context.nil?
24
+
25
+ context
26
+ end
27
+
28
+ private
29
+
30
+ def main_variant
31
+ dig_variant Config.main_vector
32
+ end
33
+
34
+ def rest_variants
35
+ Config.rest_vectors.map do |vector|
36
+ dig_variant vector
37
+ end.sort do |v1, v2|
38
+ v1.id <=> v2.id
39
+ end
40
+ end
41
+
42
+ def dig_variant(vector)
43
+ if option_key?(vector.key)
44
+ find_variant(vector)
45
+ else
46
+ vector.default_variant
47
+ end
48
+ end
49
+
50
+ def find_variant(vector)
51
+ vector.variants.find do |variant|
52
+ option(vector.key) == variant.key
53
+ end
54
+ end
55
+
56
+ def option(key)
57
+ options[key.to_sym] || options[key.to_s]
58
+ end
59
+
60
+ def option_key?(key)
61
+ options.key?(key.to_sym) || options.key?(key.to_s)
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,77 @@
1
+ require_relative "./context/find_by_command_options"
2
+
3
+ module Matrixeval
4
+ module Ruby
5
+ class Context
6
+
7
+ class << self
8
+
9
+ def find_by_command_options!(options)
10
+ FindByCommandOptions.call(options)
11
+ end
12
+
13
+ def all
14
+ Config.variant_combinations.map do |variants|
15
+ Context.new(
16
+ main_variant: variants.find { |v| v.vector.main? },
17
+ rest_variants: variants.reject { |v| v.vector.main? }
18
+ )
19
+ end.select do |context|
20
+ Config.exclusions.none? do |exclusion|
21
+ context.match_exclusion?(exclusion)
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ attr_reader :main_variant, :rest_variants
29
+
30
+ def initialize(main_variant:, rest_variants:)
31
+ @main_variant = main_variant
32
+ @rest_variants = (rest_variants || []).sort do |v1, v2|
33
+ v1.id <=> v2.id
34
+ end
35
+ end
36
+
37
+ def name
38
+ variants.map(&:name).join(", ")
39
+ end
40
+
41
+ def id
42
+ [[main_variant.id] + rest_variants.map(&:id)].join("_")
43
+ end
44
+
45
+ def env
46
+ rest_variants.map(&:env).reduce({}, &:merge)
47
+ .merge(main_variant.env)
48
+ end
49
+
50
+ def docker_compose_service_name
51
+ main_variant.id
52
+ end
53
+
54
+ def gemfile_lock_path
55
+ Matrixeval.working_dir.join(".matrixeval/Gemfile.lock.#{id}")
56
+ end
57
+
58
+ def variants
59
+ [main_variant] + rest_variants
60
+ end
61
+
62
+ def match_exclusion?(exclusion)
63
+ return false if exclusion.empty?
64
+
65
+ variants.all? do |variant|
66
+ vector_key = variant.vector.key
67
+ if exclusion.key?(vector_key)
68
+ exclusion[vector_key].to_s == variant.key
69
+ else
70
+ true
71
+ end
72
+ end
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,77 @@
1
+ require "erb"
2
+
3
+ module Matrixeval
4
+ module Ruby
5
+ class DockerCompose
6
+ class YAML
7
+ class << self
8
+
9
+ def create
10
+ FileUtils.mkdir_p dot_matrixeval_folder
11
+
12
+ File.open(path, 'w+') do |file|
13
+ file.puts build_content
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def build_content
20
+ {
21
+ "version" => "3",
22
+ "services" => services_json,
23
+ "volumes" => volumes_json
24
+ }.to_yaml.sub(/---\n/, "")
25
+ end
26
+
27
+ def services_json
28
+ services = {}
29
+
30
+ Config.main_vector_variants.map do |variant|
31
+ services[variant.docker_compose_service_name] = {
32
+ "image" => variant.image,
33
+ "volumes" => mounts(variant),
34
+ "environment" => {
35
+ "BUNDLE_PATH" => "/bundle",
36
+ "GEM_HOME" => "/bundle",
37
+ "BUNDLE_APP_CONFIG" => "/bundle",
38
+ "BUNDLE_BIN" => "/bundle/bin",
39
+ "PATH" => "/app/bin:/bundle/bin:$PATH"
40
+ },
41
+ "working_dir" => "/app"
42
+ }
43
+ end
44
+
45
+ services
46
+ end
47
+
48
+ def volumes_json
49
+ bundle_volumes.map do |volume|
50
+ [volume, {"name" => volume}]
51
+ end.to_h
52
+ end
53
+
54
+ def bundle_volumes
55
+ Config.main_vector_variants.map(&:bundle_volume_name)
56
+ end
57
+
58
+ def mounts(variant)
59
+ [
60
+ "..:/app:cached",
61
+ "#{variant.bundle_volume_name}:/bundle",
62
+ ] + Config.main_vector.mounts
63
+ end
64
+
65
+ def path
66
+ dot_matrixeval_folder.join("docker-compose.yml")
67
+ end
68
+
69
+ def dot_matrixeval_folder
70
+ Matrixeval.working_dir.join(".matrixeval")
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,47 @@
1
+
2
+ require_relative "./docker_compose/yaml"
3
+
4
+ module Matrixeval
5
+ module Ruby
6
+ class DockerCompose
7
+
8
+ attr_reader :context
9
+
10
+ def initialize(context)
11
+ @context = context
12
+ end
13
+
14
+ def run(arguments)
15
+ forward_arguments = arguments.join(" ")
16
+
17
+ system(
18
+ <<~DOCKER_COMPOSE_COMMAND
19
+ docker compose -f .matrixeval/docker-compose.yml \
20
+ run --rm \
21
+ #{env} \
22
+ #{gemfile_mount} \
23
+ #{docker_compose_service_name} \
24
+ #{forward_arguments}
25
+ DOCKER_COMPOSE_COMMAND
26
+ )
27
+ end
28
+
29
+ private
30
+
31
+ def env
32
+ context.env.map do |k, v|
33
+ "-e #{k}='#{v}'"
34
+ end.join(" ")
35
+ end
36
+
37
+ def gemfile_mount
38
+ "-v ./.matrixeval/Gemfile.lock.#{context.id}:/app/Gemfile.lock"
39
+ end
40
+
41
+ def docker_compose_service_name
42
+ context.docker_compose_service_name
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ module Matrixeval
2
+ module Ruby
3
+ class GemfileLocks
4
+ class << self
5
+
6
+ def create
7
+ FileUtils.mkdir_p dot_matrixeval_folder
8
+
9
+ Context.all.each do |context|
10
+ FileUtils.touch context.gemfile_lock_path
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def dot_matrixeval_folder
17
+ Matrixeval.working_dir.join(".matrixeval")
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+ module Matrixeval
2
+ module Ruby
3
+ class Gitignore
4
+ class << self
5
+
6
+ def update
7
+ add_docker_compose
8
+ add_gemfile_locks
9
+ end
10
+
11
+ private
12
+
13
+ def add_docker_compose
14
+ return if docker_compose_included?
15
+
16
+ File.open(gitignore_path, 'a+') do |file|
17
+ file.puts docker_compose_yaml
18
+ end
19
+ end
20
+
21
+ def add_gemfile_locks
22
+ return if gemfile_locks_included?
23
+
24
+ File.open(gitignore_path, 'a+') do |file|
25
+ file.puts gemfile_locks
26
+ end
27
+ end
28
+
29
+ def docker_compose_included?
30
+ File.exist?(gitignore_path) &&
31
+ File.read(gitignore_path).include?(docker_compose_yaml)
32
+ end
33
+
34
+ def gemfile_locks_included?
35
+ File.exist?(gitignore_path) &&
36
+ File.read(gitignore_path).include?(gemfile_locks)
37
+ end
38
+
39
+ def docker_compose_yaml
40
+ ".matrixeval/docker-compose.yml"
41
+ end
42
+
43
+ def gemfile_locks
44
+ ".matrixeval/Gemfile.lock.*"
45
+ end
46
+
47
+ def gitignore_path
48
+ Matrixeval.working_dir.join(".gitignore")
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,163 @@
1
+ require 'optparse'
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ require 'matrixeval/ruby/config'
5
+ require 'matrixeval/ruby/command_line'
6
+ require "concurrent/utility/processor_counter"
7
+ require 'terminal-table'
8
+
9
+ module Matrixeval
10
+ module Ruby
11
+ class Runner
12
+ class << self
13
+ def start(argv)
14
+ new(argv).start
15
+ end
16
+ end
17
+
18
+ attr_reader :argv, :command
19
+
20
+ def initialize(argv)
21
+ @argv = argv
22
+ @command = CommandLine.new(argv)
23
+ end
24
+
25
+ def start
26
+ if command.init?
27
+ init
28
+ elsif command.all?
29
+ run_all_contexts
30
+ else
31
+ run_a_specific_context
32
+ end
33
+ ensure
34
+ turn_on_stty_opost
35
+ end
36
+
37
+ private
38
+
39
+ def init
40
+ Config::YAML.create
41
+ Gitignore.update
42
+ end
43
+
44
+ def run_all_contexts
45
+ Config::YAML.create
46
+ DockerCompose::YAML.create
47
+ GemfileLocks.create
48
+ Gitignore.update
49
+
50
+ if workers_count == 1
51
+ run_all_contexts_sequentially
52
+ else
53
+ run_all_contexts_in_parallel
54
+ end
55
+ end
56
+
57
+ def run_all_contexts_sequentially
58
+ Context.all.each do |context|
59
+ puts Rainbow("[ MatrixEval ] ").blue.bright + Rainbow(" #{context.name} ").white.bright.bg(:blue)
60
+ puts Rainbow("[ MatrixEval ] Run \"#{command.rest_arguments.join(" ")}\"").blue.bright
61
+
62
+ docker_compose = DockerCompose.new(context)
63
+ success = docker_compose.run(command.rest_arguments)
64
+
65
+ matrixeval_results << [context, !!success]
66
+ end
67
+
68
+ report
69
+ end
70
+
71
+ def run_all_contexts_in_parallel
72
+ parallel do |contexts|
73
+ Thread.current[:matrixeval_results] = []
74
+
75
+ contexts.each do |context|
76
+ docker_compose = DockerCompose.new(context)
77
+ success = docker_compose.run(command.rest_arguments)
78
+
79
+ Thread.current[:matrixeval_results] << [context, !!success]
80
+ end
81
+ end
82
+
83
+ report
84
+ end
85
+
86
+ def run_a_specific_context
87
+ Config::YAML.create
88
+ DockerCompose::YAML.create
89
+ GemfileLocks.create
90
+ Gitignore.update
91
+
92
+ context = Context.find_by_command_options!(command.context_options)
93
+
94
+ puts Rainbow("[ MatrixEval ] ").blue.bright + Rainbow(" #{context.name} ").white.bright.bg(:blue)
95
+ puts Rainbow("[ MatrixEval ] Run \"#{command.rest_arguments.join(" ")}\"").blue.bright
96
+
97
+ docker_compose = DockerCompose.new(context)
98
+ docker_compose.run(command.rest_arguments)
99
+ end
100
+
101
+ def report
102
+ turn_on_stty_opost
103
+
104
+ table = Terminal::Table.new(title: Rainbow("MatrixEval").blue.bright + " Summary", alignment: :center) do |table|
105
+
106
+ table.add_row(Config.vectors.map(&:key) + ['result'])
107
+ table.add_separator
108
+
109
+ matrixeval_results.each do |context, success|
110
+ success_cell = [success ? Rainbow('Success').green : Rainbow('Failed').red]
111
+ row = (context.variants.map(&:key) + success_cell).map do |value|
112
+ { value: value, alignment: :center }
113
+ end
114
+
115
+ table.add_row row
116
+ end
117
+
118
+ end
119
+
120
+ puts table
121
+ end
122
+
123
+ def parallel
124
+ contexts = Context.all
125
+
126
+ contexts.each_slice(contexts.count / workers_count) do |sub_contexts|
127
+ threads << Thread.new do
128
+ yield sub_contexts
129
+ end
130
+ end
131
+
132
+ threads.each(&:join)
133
+
134
+ threads.each do |thread|
135
+ matrixeval_results += thread[:matrixeval_results]
136
+ end
137
+ end
138
+
139
+ def threads
140
+ @threads ||= []
141
+ end
142
+
143
+ def matrixeval_results
144
+ @matrixeval_results ||= []
145
+ end
146
+
147
+ def workers_count
148
+ count = if Config.parallel_workers == "number_of_processors"
149
+ Concurrent.physical_processor_count
150
+ else
151
+ Integer(Config.parallel_workers)
152
+ end
153
+
154
+ [count, 1].max
155
+ end
156
+
157
+ def turn_on_stty_opost
158
+ system("stty opost")
159
+ end
160
+
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,13 @@
1
+ version: 0.1
2
+ target: ruby
3
+ parallel_workers: number_of_processors
4
+ matrix:
5
+ ruby:
6
+ variants:
7
+ - key: 2.7
8
+ image: ruby:2.7.1
9
+ - key: 3.0
10
+ image: ruby:3.0.0
11
+ default: true
12
+ - key: 3.1
13
+ image: ruby:3.1.0
@@ -0,0 +1,56 @@
1
+ module Matrixeval
2
+ module Ruby
3
+ class Variant
4
+ class << self
5
+ def default(key, vector)
6
+ self.new({"key" => key}, vector)
7
+ end
8
+ end
9
+
10
+ attr_reader :key, :image, :env, :vector, :default
11
+
12
+ def initialize(config = {}, vector)
13
+ raise Error.new("Variant#key is missing") if config["key"].nil?
14
+
15
+ @vector = vector
16
+ @key = config["key"].to_s
17
+ @image = config["image"]
18
+ @env = config["env"] || {}
19
+ @default = config["default"] || false
20
+ end
21
+
22
+ def name
23
+ "#{vector.key}: #{key}"
24
+ end
25
+
26
+ def bundle_volume_name
27
+ "bundle_#{image.gsub(/[^A-Za-z0-9]/,'_')}"
28
+ end
29
+
30
+ def id
31
+ "#{vector.id}_#{key.to_s.gsub(/[^A-Za-z0-9]/,'_')}"
32
+ end
33
+
34
+ def docker_compose_service_name
35
+ id
36
+ end
37
+
38
+ def pathname
39
+ id
40
+ end
41
+
42
+ def default?
43
+ default
44
+ end
45
+
46
+ def match_command_options?(options)
47
+ options[vector.key] == key.to_s
48
+ end
49
+
50
+ def ==(variant)
51
+ vector.key == variant.vector.key &&
52
+ key == variant.key
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,40 @@
1
+ require_relative "./variant"
2
+
3
+ module Matrixeval
4
+ module Ruby
5
+ class Vector
6
+ attr_reader :key, :variants, :mounts
7
+
8
+ def initialize(key, config)
9
+ @key = key.to_s
10
+ @mounts = config["mounts"] || []
11
+ @variants = (config["variants"] || []).map do |variant_config|
12
+ config = if variant_config.is_a?(Hash)
13
+ variant_config
14
+ else
15
+ { "key" => variant_config.to_s }
16
+ end
17
+
18
+ Variant.new(config, self)
19
+ end
20
+ end
21
+
22
+ def main?
23
+ key == "ruby"
24
+ end
25
+
26
+ def id
27
+ "#{key.to_s.gsub(/[^A-Za-z0-9]/,'_')}"
28
+ end
29
+
30
+ def default_variant
31
+ variant = variants.find(&:default?)
32
+ if variant.nil?
33
+ raise Error.new("Please set a default variant for matrix #{vector.key}")
34
+ end
35
+
36
+ variant
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Matrixeval
4
+ module Ruby
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby/version"
4
+ require 'rainbow'
5
+ require 'matrixeval/ruby/docker_compose'
6
+ require 'matrixeval/ruby/context'
7
+ require 'matrixeval/ruby/gemfile_locks'
8
+ require 'matrixeval/ruby/runner'
9
+ require 'matrixeval/ruby/gitignore'
10
+
11
+ module Matrixeval
12
+ module Ruby
13
+ class Error < StandardError; end
14
+
15
+ module_function
16
+ def root
17
+ Pathname.new("#{__dir__}/../..")
18
+ end
19
+ end
20
+
21
+ module_function
22
+ def start(argv)
23
+ Ruby::Runner.start(argv)
24
+ end
25
+
26
+ def working_dir
27
+ Pathname.new(Dir.getwd)
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matrixeval-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hopper Gee
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: concurrent-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: MatrixEval-Ruby
56
+ email:
57
+ - hopper.gee@hey.com
58
+ executables:
59
+ - matrixeval
60
+ - meval
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - CHANGELOG.md
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - bin/test
74
+ - exe/matrixeval
75
+ - exe/meval
76
+ - lib/matrixeval/ruby.rb
77
+ - lib/matrixeval/ruby/command_line.rb
78
+ - lib/matrixeval/ruby/command_line/parse_context_arguments.rb
79
+ - lib/matrixeval/ruby/config.rb
80
+ - lib/matrixeval/ruby/config/yaml.rb
81
+ - lib/matrixeval/ruby/context.rb
82
+ - lib/matrixeval/ruby/context/find_by_command_options.rb
83
+ - lib/matrixeval/ruby/docker_compose.rb
84
+ - lib/matrixeval/ruby/docker_compose/yaml.rb
85
+ - lib/matrixeval/ruby/gemfile_locks.rb
86
+ - lib/matrixeval/ruby/gitignore.rb
87
+ - lib/matrixeval/ruby/runner.rb
88
+ - lib/matrixeval/ruby/templates/matrixeval.yml
89
+ - lib/matrixeval/ruby/variant.rb
90
+ - lib/matrixeval/ruby/vector.rb
91
+ - lib/matrixeval/ruby/version.rb
92
+ homepage: https://github.com/MatrixEval/matrixeval-ruby
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ homepage_uri: https://github.com/MatrixEval/matrixeval-ruby
97
+ source_code_uri: https://github.com/MatrixEval/matrixeval-ruby
98
+ changelog_uri: https://github.com/MatrixEval/matrixeval-ruby/blob/main/CHANGELOG.md
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 2.5.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.2.15
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: MatrixEval-Ruby
118
+ test_files: []