manageiq-cross_repo 1.0.0 → 1.1.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: ecad3c073c0e642e1b0c6acdbd4aee93ab2ee491761c6674ca8333b8ddd2b778
4
- data.tar.gz: '0952c2b0fe57ee11a23ed5749ae3e1728e9c4eac1257e09b01edd17ac4b6b88b'
3
+ metadata.gz: 054abc092ffedefe7b8dcd8bdefb3e010b8e1ed04607ed7ded476ec32e2d3c75
4
+ data.tar.gz: '080cdb1b599cdc5cb2f83738223a21077e31f6dce21b73ea1e959d140f82071a'
5
5
  SHA512:
6
- metadata.gz: a519f48d8f113042c44c9a31a169ce415fb86b6c2ca0db0251bdda0f9a01d25bf76bb92b974054350bd800ca6f69a39ca0e3ec6fbea48c6f6142bf484b223378
7
- data.tar.gz: b7b6e3974e05fad7c7f8d2727fc174de49329bcec10445e97089f5adc2d2d95902dffb992b46eacfbd046808022c41d991e8577254ce6beace91223308bbb211
6
+ metadata.gz: 97eb42a587763a8425ab9972942cacb09692caf996156c909f5e4bba27626a68ecbaae2529f7b1c523025ab98d6a7d071b7304ce662d08408c0767106ab26a06
7
+ data.tar.gz: 9ce7dfe06414015efdaf174fd872ce72ac342bca85012bb8982a787f536d5b9b4f531eaa7b7cb67d053ed1832b9b97da61fd580a8a75e9871251e3883158afad
data/.codeclimate.yml ADDED
@@ -0,0 +1,16 @@
1
+ prepare:
2
+ fetch:
3
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_base.yml
4
+ path: ".rubocop_base.yml"
5
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_cc_base.yml
6
+ path: ".rubocop_cc_base.yml"
7
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/base.yml
8
+ path: styles/base.yml
9
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/cc_base.yml
10
+ path: styles/cc_base.yml
11
+ plugins:
12
+ rubocop:
13
+ enabled: true
14
+ config: ".rubocop_cc.yml"
15
+ channel: rubocop-0-82
16
+ version: '2'
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_gem:
2
+ manageiq-style: ".rubocop_base.yml"
3
+ inherit_from:
4
+ - ".rubocop_local.yml"
data/.rubocop_cc.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_from:
2
+ - ".rubocop_base.yml"
3
+ - ".rubocop_cc_base.yml"
4
+ - ".rubocop_local.yml"
File without changes
data/.travis.yml CHANGED
@@ -1,9 +1,7 @@
1
- dist: xenial
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.5.5
5
- cache:
6
- bundler: true
4
+ cache: bundler
7
5
  addons:
8
6
  postgresql: '10'
9
7
  apt:
data/README.md CHANGED
@@ -16,6 +16,8 @@ Options:
16
16
  If any of the repositories in the list are a core repository that will
17
17
  be used as the root repository, otherwise ManageIQ/manageiq@master will be the default.
18
18
  Can also be passed as a REPOS environment variable.
19
+ -s, --script-cmd=<s> Optional, a command string for running the specs. Defaults to `bundle exec rake`.
20
+ (default: )
19
21
 
20
22
  -v, --version Print version and exit
21
23
  -h, --help Show this message
@@ -31,6 +31,18 @@ opts = Optimist.options do
31
31
  Can also be passed as a REPOS environment variable.
32
32
  EOS
33
33
 
34
+ opt :test_suite, <<~EOS, :type => :string, :default => ENV["TEST_SUITE"].presence
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
37
+ and also to run different test suites, e.g. spec:javascript.
38
+ EOS
39
+
40
+ opt :script_cmd, <<~EOS, :type => :string, :default => ENV["SCRIPT_CMD"].presence
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
43
+ EOS
44
+
45
+
34
46
  # Manually add these so they appear in the right order in the help output
35
47
  banner ""
36
48
  opt :version, "Print version and exit"
@@ -84,9 +96,15 @@ opts = Optimist.options do
84
96
  end
85
97
 
86
98
  opts[:repos] = opts[:repos].flatten.flat_map { |repo| repo.split(",").map(&:strip) }
99
+ test_repo, repos, test_suite, script_cmd = opts.values_at(:test_repo, :repos, :test_suite, :script_cmd)
87
100
 
88
101
  begin
89
- ManageIQ::CrossRepo.run(opts[:test_repo], opts[:repos])
102
+ ManageIQ::CrossRepo.run(
103
+ :test_repo => test_repo,
104
+ :repos => repos,
105
+ :test_suite => test_suite,
106
+ :script_cmd => script_cmd
107
+ )
90
108
  rescue ArgumentError => e
91
109
  Optimist.die e
92
110
  end
@@ -19,6 +19,10 @@ module ManageIQ::CrossRepo
19
19
  repo.casecmp("manageiq") == 0
20
20
  end
21
21
 
22
+ def ==(other)
23
+ repo == other.repo && sha == other.sha
24
+ end
25
+
22
26
  def ensure_clone
23
27
  return if path.exist?
24
28
 
@@ -30,7 +34,7 @@ module ManageIQ::CrossRepo
30
34
  puts "Fetching #{tarball_url}"
31
35
 
32
36
  Dir.mktmpdir do |dir|
33
- Mixlib::Archive.new(open(tarball_url, "rb")).extract(dir)
37
+ Mixlib::Archive.new(open_tarball_url(tarball_url)).extract(dir)
34
38
 
35
39
  content_dir = Pathname.new(dir).children.detect(&:directory?)
36
40
  FileUtils.mkdir_p(path.dirname)
@@ -143,12 +147,25 @@ module ManageIQ::CrossRepo
143
147
  url && File.join(url, "tarball", sha)
144
148
  end
145
149
 
150
+ def open_tarball_url(url)
151
+ archive = URI.open(tarball_url, "rb")
152
+
153
+ if archive.kind_of?(StringIO)
154
+ archive = Tempfile.new('cross_repo').tap do |f|
155
+ f.write(archive.string)
156
+ f.fsync
157
+ end.path
158
+ end
159
+
160
+ archive
161
+ end
162
+
146
163
  def git_branch_to_sha(url, branch)
147
164
  `git ls-remote #{url} #{branch}`.split("\t").first
148
165
  end
149
166
 
150
167
  def git_pr_to_sha(url, pr)
151
- git_branch_to_sha(url, "refs/pull/#{pr}/head")
168
+ git_branch_to_sha(url, "refs/pull/#{pr}/merge") || git_branch_to_sha(url, "refs/pull/#{pr}/head")
152
169
  end
153
170
  end
154
171
  end
@@ -3,9 +3,9 @@ require "active_support/core_ext/object/blank"
3
3
 
4
4
  module ManageIQ::CrossRepo
5
5
  class Runner
6
- attr_reader :test_repo, :core_repo, :gem_repos
6
+ attr_reader :test_repo, :core_repo, :gem_repos, :test_suite, :script_cmd
7
7
 
8
- def initialize(test_repo, repos)
8
+ def initialize(test_repo:, repos:, test_suite: nil, script_cmd: nil)
9
9
  @test_repo = Repository.new(test_repo || "ManageIQ/manageiq@master")
10
10
 
11
11
  core_repos, @gem_repos = Array(repos).collect { |repo| Repository.new(repo) }.partition(&:core?)
@@ -20,34 +20,28 @@ module ManageIQ::CrossRepo
20
20
 
21
21
  @core_repo ||= Repository.new("ManageIQ/manageiq@master")
22
22
  end
23
+
24
+ @script_cmd = script_cmd.presence
25
+ @test_suite = test_suite.presence
23
26
  end
24
27
 
25
28
  def run
26
29
  test_repo.ensure_clone
27
- test_repo.core? ? run_core : run_plugin
30
+ core_repo.ensure_clone unless test_repo.core?
31
+ prepare_gem_repos
32
+ run_tests
28
33
  end
29
34
 
30
35
  private
31
36
 
32
- def run_core
33
- prepare_gem_repos
34
-
37
+ def run_tests
35
38
  with_test_env do
36
- system!({"TRAVIS_BUILD_DIR" => test_repo.path.to_s}, "bash", "tools/ci/before_install.sh") if ENV["CI"]
37
- system!("bin/setup")
38
- system!("bundle exec rake")
39
+ run_test_script(build_test_script)
39
40
  end
40
41
  end
41
42
 
42
- def run_plugin
43
- core_repo.ensure_clone
44
- prepare_gem_repos
45
-
46
- env_vars = {"MANAGEIQ_REPO" => core_repo.path.to_s}
47
- with_test_env do
48
- system!(env_vars, "bin/setup")
49
- system!("bundle exec rake")
50
- end
43
+ def env_vars
44
+ {"MANAGEIQ_REPO" => core_repo.path.to_s, "TRAVIS_BUILD_DIR" => test_repo.path.to_s, "TEST_SUITE" => test_suite}
51
45
  end
52
46
 
53
47
  def with_test_env
@@ -63,17 +57,26 @@ module ManageIQ::CrossRepo
63
57
  repo = Dir.pwd.split("/").last(2).join("/")
64
58
  puts "\e[36mDEBUG: #{repo} - #{args.join(" ")}\e[0m"
65
59
  end
66
- exit($?.exitstatus) unless system(*args)
60
+
61
+ Process.wait(spawn(*args))
62
+ exit($?.exitstatus) unless $?.success?
67
63
  end
68
64
 
69
65
  def generate_bundler_d
70
66
  bundler_d_path = core_repo.path.join("bundler.d")
71
67
  override_path = bundler_d_path.join("overrides.rb")
72
68
 
69
+ require "fileutils"
70
+
73
71
  if gem_repos.empty?
74
72
  FileUtils.rm_f override_path
75
73
  else
76
- content = gem_repos.map { |gem| "ensure_gem \"#{gem.repo}\", :path => \"#{gem.path}\"" }.join("\n")
74
+ content = gem_repos.map do |gem|
75
+ # If there is a gemspec get the name of the gem from that instead of the repository
76
+ gem_name = gem.path.glob("*.gemspec")&.first&.basename(".gemspec") || gem.repo
77
+ "ensure_gem \"#{gem_name}\", :path => \"#{gem.path}\""
78
+ end.join("\n")
79
+
77
80
  FileUtils.mkdir_p(bundler_d_path)
78
81
 
79
82
  File.write(override_path, content)
@@ -84,5 +87,82 @@ module ManageIQ::CrossRepo
84
87
  gem_repos.each { |gem_repo| gem_repo.ensure_clone }
85
88
  generate_bundler_d
86
89
  end
90
+
91
+ def run_test_script(test_script)
92
+ r, w = IO.pipe
93
+ w.write(test_script)
94
+ w.close
95
+
96
+ system!(env_vars, "/bin/bash -s", :in => r, :out => $stdout, :err => $stderr)
97
+ end
98
+
99
+ def build_test_script
100
+ load_travis_yml!
101
+
102
+ commands = environment_setup_commands
103
+
104
+ sections = %w[before_install install before_script script]
105
+ commands += sections.flat_map do |section|
106
+ # Travis sections can have a single command or an array of commands
107
+ section_commands = Array(travis_yml[section]).map { |cmd| "#{cmd} || exit $?" }
108
+ next if section_commands.blank?
109
+
110
+ [
111
+ "echo 'travis_fold:start:#{section}'",
112
+ *section_commands,
113
+ "echo 'travis_fold:end:#{section}'"
114
+ ]
115
+ end.compact
116
+
117
+ <<~BASH_SCRIPT
118
+ #!/bin/bash
119
+
120
+ #{commands.join("\n")}
121
+ BASH_SCRIPT
122
+ end
123
+
124
+ def environment_setup_commands
125
+ setup_commands = []
126
+
127
+ if travis_yml["node_js"]
128
+ setup_commands << "source ~/.nvm/nvm.sh"
129
+ setup_commands += Array(travis_yml["node_js"]).map do |node_version|
130
+ "nvm install #{node_version}"
131
+ end
132
+ end
133
+
134
+ setup_commands
135
+ end
136
+
137
+ def load_travis_yml!
138
+ # Load the test_repo's .travis.yml file
139
+ travis_yml
140
+
141
+ # Set missing travis sections to the proper defaults
142
+ travis_yml["install"] ||= travis_defaults[travis_yml["language"]]["install"]
143
+
144
+ travis_yml["script"] = script_cmd if script_cmd.present?
145
+ travis_yml["script"] ||= travis_defaults[travis_yml["language"]]["script"]
146
+ end
147
+
148
+ def travis_yml
149
+ @travis_yml ||= begin
150
+ require "yaml"
151
+ YAML.load_file(".travis.yml")
152
+ end
153
+ end
154
+
155
+ def travis_defaults
156
+ @travis_defaults ||= {
157
+ "node_js" => {
158
+ "install" => "npm install",
159
+ "script" => "npm test"
160
+ },
161
+ "ruby" => {
162
+ "install" => "bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}",
163
+ "script" => "bundle exec rake"
164
+ }
165
+ }.freeze
166
+ end
87
167
  end
88
168
  end
@@ -1,5 +1,5 @@
1
1
  module ManageIQ
2
2
  module CrossRepo
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
+ spec.add_development_dependency "manageiq-style"
25
26
  spec.add_development_dependency "rake"
26
27
  spec.add_development_dependency "rspec"
27
28
  spec.add_development_dependency "simplecov"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-cross_repo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.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: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2021-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: manageiq-style
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -109,14 +123,18 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  description: ManageIQ CrossRepo testing library
112
- email:
126
+ email:
113
127
  executables:
114
128
  - manageiq-cross_repo
115
129
  extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
132
+ - ".codeclimate.yml"
118
133
  - ".gitignore"
119
134
  - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".rubocop_cc.yml"
137
+ - ".rubocop_local.yml"
120
138
  - ".travis.yml"
121
139
  - Gemfile
122
140
  - LICENSE.txt
@@ -137,7 +155,7 @@ licenses:
137
155
  metadata:
138
156
  homepage_uri: https://github.com/ManageIQ/manageiq-cross_repo
139
157
  source_code_uri: https://github.com/ManageIQ/manageiq-cross_repo
140
- post_install_message:
158
+ post_install_message:
141
159
  rdoc_options: []
142
160
  require_paths:
143
161
  - lib
@@ -152,8 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
170
  - !ruby/object:Gem::Version
153
171
  version: '0'
154
172
  requirements: []
155
- rubygems_version: 3.0.6
156
- signing_key:
173
+ rubygems_version: 3.2.5
174
+ signing_key:
157
175
  specification_version: 4
158
176
  summary: ManageIQ CrossRepo testing library
159
177
  test_files: []