manageiq-cross_repo 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 756d32fbaca87b4fcd09bcb95dca76ad5e4560561586431dd64c7ea050d56573
4
- data.tar.gz: 9ddbaeb1080a02757d20113cf93f6161086e24d91cc03a8793893900b9933969
3
+ metadata.gz: 303420d045bf57bacab3391945b7652115e42e2dece17c37c9c15b6bfe4e07bd
4
+ data.tar.gz: fd8e604e86f2ed8abb7c383ad08403cb4b20970caeba3fdae913d55fb87543ea
5
5
  SHA512:
6
- metadata.gz: f23fd2b6b57843d2974b06058786d1da8321d8eb83599fe4fe4935006e822ab036d5615cebc407db51c68c25f8d24bb3d78a85e37eb745565b68e66b55b35082
7
- data.tar.gz: bd339e043a899aef5fafd10d2a8f85a59fc0d813b19d17c3b738ded4a6809b3f246e548eb2bdba0a11a5298fba3933296ffd4b1583a9fce2808ac62b503c613f
6
+ metadata.gz: 94020cc0c92e37dca3df2c0eb78ec3b61e3874ea79d5fa09f5d16949d0acf28a99095c2396d3b3ae7b8ca92d8de7d7889084bf6cdce2fbde77c6efe0928aacdf
7
+ data.tar.gz: 040c9f3265bce6a0d51c7e0ab46cf414f7c8b7fb798a34725ee5e162adb137907ec699cbe004d7ab084e868a72fa41ed78f9e208332bb66fc546c43df68c4a81
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  .rspec_status
12
12
 
13
13
  Gemfile.lock
14
+ /repos/
@@ -33,13 +33,13 @@ opts = Optimist.options do
33
33
 
34
34
  opt :test_suite, <<~EOS, :type => :string, :default => ENV["TEST_SUITE"].presence
35
35
  Optional, the name of a rake test suite to pass as an environment variable to the test being run.
36
- This is commonly used by the .travis.yml to conditionally perform different setup tasks
36
+ This is commonly used by the CI config to conditionally perform different setup tasks
37
37
  and also to run different test suites, e.g. spec:javascript.
38
38
  EOS
39
39
 
40
40
  opt :script_cmd, <<~EOS, :type => :string, :default => ENV["SCRIPT_CMD"].presence
41
41
  Optional, a command string for running the specs.
42
- If present this will override the the script section of the test_repo's .travis.yml
42
+ If present this will override the the script section of the test_repo's CI config
43
43
  EOS
44
44
 
45
45
 
@@ -0,0 +1,102 @@
1
+ require "active_support/core_ext/object/blank"
2
+ require "yaml"
3
+
4
+ module ManageIQ::CrossRepo
5
+ class Runner
6
+ class Base
7
+ attr_accessor :script_cmd
8
+
9
+ def initialize(script_cmd = nil)
10
+ @script_cmd = script_cmd.presence
11
+ end
12
+
13
+ def build_test_script
14
+ load_config!
15
+ build_script
16
+ end
17
+
18
+ private
19
+
20
+ def environment_setup_commands
21
+ commands = []
22
+
23
+ if config["node_js"]
24
+ commands << "source ~/.nvm/nvm.sh"
25
+ commands += Array(config["node_js"]).map do |node_version|
26
+ "nvm install #{node_version}"
27
+ end
28
+ end
29
+
30
+ commands.any? ? build_section("environment", *commands) : commands
31
+ end
32
+
33
+ def section_commands
34
+ sections = %w[before_install install before_script script]
35
+ sections.flat_map do |section|
36
+ commands = build_section_commands(section)
37
+ build_section(section, *commands) if commands.present?
38
+ end.compact
39
+ end
40
+
41
+ def build_commands
42
+ environment_setup_commands + section_commands
43
+ end
44
+
45
+ def build_section_commands(section)
46
+ # Travis sections can have a single command or an array of commands
47
+ Array(config[section]).map { |cmd| "#{cmd} || exit $?" }
48
+ end
49
+
50
+ def build_section(section, *commands)
51
+ [
52
+ "echo 'travis_fold:start:#{section}'",
53
+ *commands,
54
+ "echo 'travis_fold:end:#{section}'"
55
+ ]
56
+ end
57
+
58
+ def build_script
59
+ <<~BASH_SCRIPT
60
+ #!/bin/bash
61
+
62
+ #{build_commands.join("\n")}
63
+ BASH_SCRIPT
64
+ end
65
+
66
+ def load_config!
67
+ config
68
+ end
69
+
70
+ def config
71
+ @config ||= travis_config.tap do |config|
72
+ # Set missing sections to the proper defaults
73
+ config["install"] ||= defaults[config["language"]]["install"]
74
+
75
+ config["script"] = script_cmd if script_cmd.present?
76
+ config["script"] ||= defaults[config["language"]]["script"]
77
+ end
78
+ end
79
+
80
+ def travis_config
81
+ raise NotImplementedError, "must be implemented in a subclass"
82
+ end
83
+
84
+ def defaults
85
+ @defaults ||= {
86
+ "node_js" => {
87
+ "language" => "node_js",
88
+ "node_js" => ["12"],
89
+ "install" => "npm install",
90
+ "script" => "npm test"
91
+ },
92
+ "ruby" => {
93
+ "language" => "ruby",
94
+ "rvm" => ["2.7"],
95
+ "install" => "bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}",
96
+ "script" => "bundle exec rake"
97
+ }
98
+ }.freeze
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "./base"
2
+ require "yaml"
3
+
4
+ module ManageIQ::CrossRepo
5
+ class Runner
6
+ class Github < Base
7
+ CONFIG_FILE = ".github/workflows/ci.yaml".freeze
8
+
9
+ def self.available?
10
+ File.exist?(CONFIG_FILE)
11
+ end
12
+
13
+ private
14
+
15
+ def travis_config
16
+ steps = github_config["jobs"]["ci"]["steps"]
17
+ language = steps.any? { |s| s["uses"] == "ruby/setup-ruby@v1" } ? "ruby" : "node_js"
18
+
19
+ defaults[language].clone.tap do |config|
20
+ script_step = steps.detect { |s| s["name"] == "Run tests" }
21
+ config["script"] = script_step["run"] if script_step
22
+ end
23
+ end
24
+
25
+ def github_config
26
+ YAML.load_file(CONFIG_FILE)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "./base"
2
+ require "yaml"
3
+
4
+ module ManageIQ::CrossRepo
5
+ class Runner
6
+ class Travis < Base
7
+ CONFIG_FILE = ".travis.yml".freeze
8
+
9
+ def self.available?
10
+ File.exist?(CONFIG_FILE)
11
+ end
12
+
13
+ private
14
+
15
+ def travis_config
16
+ YAML.load_file(CONFIG_FILE)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,7 @@
1
1
  require "manageiq/cross_repo/repository"
2
+ require "active_support/core_ext/class/subclasses"
2
3
  require "active_support/core_ext/object/blank"
4
+ Dir.glob(File.join(__dir__, "runner", "*")).sort.each { |f| require f }
3
5
 
4
6
  module ManageIQ::CrossRepo
5
7
  class Runner
@@ -16,8 +18,6 @@ module ManageIQ::CrossRepo
16
18
 
17
19
  @core_repo = @test_repo
18
20
  else
19
- raise ArgumentError, "You must pass at least one repo when running a plugin test." if repos.blank?
20
-
21
21
  @core_repo ||= Repository.new("ManageIQ/manageiq@master")
22
22
  end
23
23
 
@@ -41,7 +41,8 @@ module ManageIQ::CrossRepo
41
41
 
42
42
  def run_tests
43
43
  with_test_env do
44
- run_test_script(build_test_script)
44
+ test_script = script_source.new(script_cmd).build_test_script
45
+ run_test_script(test_script)
45
46
  end
46
47
  end
47
48
 
@@ -67,6 +68,10 @@ module ManageIQ::CrossRepo
67
68
  exit($?.exitstatus) unless $?.success?
68
69
  end
69
70
 
71
+ def script_source
72
+ Base.descendants.detect(&:available?)
73
+ end
74
+
70
75
  def generate_bundler_d
71
76
  bundler_d_path = core_repo.path.join("bundler.d")
72
77
  override_path = bundler_d_path.join("overrides.rb")
@@ -100,74 +105,5 @@ module ManageIQ::CrossRepo
100
105
 
101
106
  system!(env_vars, "/bin/bash -s", :in => r, :out => $stdout, :err => $stderr)
102
107
  end
103
-
104
- def build_test_script
105
- load_travis_yml!
106
-
107
- commands = environment_setup_commands
108
-
109
- sections = %w[before_install install before_script script]
110
- commands += sections.flat_map do |section|
111
- # Travis sections can have a single command or an array of commands
112
- section_commands = Array(travis_yml[section]).map { |cmd| "#{cmd} || exit $?" }
113
- next if section_commands.blank?
114
-
115
- [
116
- "echo 'travis_fold:start:#{section}'",
117
- *section_commands,
118
- "echo 'travis_fold:end:#{section}'"
119
- ]
120
- end.compact
121
-
122
- <<~BASH_SCRIPT
123
- #!/bin/bash
124
-
125
- #{commands.join("\n")}
126
- BASH_SCRIPT
127
- end
128
-
129
- def environment_setup_commands
130
- setup_commands = []
131
-
132
- if travis_yml["node_js"]
133
- setup_commands << "source ~/.nvm/nvm.sh"
134
- setup_commands += Array(travis_yml["node_js"]).map do |node_version|
135
- "nvm install #{node_version}"
136
- end
137
- end
138
-
139
- setup_commands
140
- end
141
-
142
- def load_travis_yml!
143
- # Load the test_repo's .travis.yml file
144
- travis_yml
145
-
146
- # Set missing travis sections to the proper defaults
147
- travis_yml["install"] ||= travis_defaults[travis_yml["language"]]["install"]
148
-
149
- travis_yml["script"] = script_cmd if script_cmd.present?
150
- travis_yml["script"] ||= travis_defaults[travis_yml["language"]]["script"]
151
- end
152
-
153
- def travis_yml
154
- @travis_yml ||= begin
155
- require "yaml"
156
- YAML.load_file(".travis.yml")
157
- end
158
- end
159
-
160
- def travis_defaults
161
- @travis_defaults ||= {
162
- "node_js" => {
163
- "install" => "npm install",
164
- "script" => "npm test"
165
- },
166
- "ruby" => {
167
- "install" => "bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}",
168
- "script" => "bundle exec rake"
169
- }
170
- }.freeze
171
- end
172
108
  end
173
109
  end
@@ -1,5 +1,5 @@
1
1
  module ManageIQ
2
2
  module CrossRepo
3
- VERSION = "1.1.3"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
data/repos/.gitkeep ADDED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-cross_repo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Authors
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-27 00:00:00.000000000 Z
11
+ date: 2021-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: manageiq-style
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  description: ManageIQ CrossRepo testing library
126
- email:
126
+ email:
127
127
  executables:
128
128
  - manageiq-cross_repo
129
129
  extensions: []
@@ -147,15 +147,19 @@ files:
147
147
  - lib/manageiq/cross_repo.rb
148
148
  - lib/manageiq/cross_repo/repository.rb
149
149
  - lib/manageiq/cross_repo/runner.rb
150
+ - lib/manageiq/cross_repo/runner/base.rb
151
+ - lib/manageiq/cross_repo/runner/github.rb
152
+ - lib/manageiq/cross_repo/runner/travis.rb
150
153
  - lib/manageiq/cross_repo/version.rb
151
154
  - manageiq-cross_repo.gemspec
155
+ - repos/.gitkeep
152
156
  homepage: https://github.com/ManageIQ/manageiq-cross_repo
153
157
  licenses:
154
158
  - MIT
155
159
  metadata:
156
160
  homepage_uri: https://github.com/ManageIQ/manageiq-cross_repo
157
161
  source_code_uri: https://github.com/ManageIQ/manageiq-cross_repo
158
- post_install_message:
162
+ post_install_message:
159
163
  rdoc_options: []
160
164
  require_paths:
161
165
  - lib
@@ -170,8 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
174
  - !ruby/object:Gem::Version
171
175
  version: '0'
172
176
  requirements: []
173
- rubygems_version: 3.2.5
174
- signing_key:
177
+ rubygems_version: 3.2.27
178
+ signing_key:
175
179
  specification_version: 4
176
180
  summary: ManageIQ CrossRepo testing library
177
181
  test_files: []