rdm 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +69 -1
- data/bin/rdm +102 -42
- data/example/.rdm/templates/configs/<%=config_path%> +2 -0
- data/example/.rdm/templates/configs/<%=role_config_path%> +2 -0
- data/example/Rdm.packages +8 -3
- data/example/domain/core/spec/core/one_more_spec.rb +5 -0
- data/example/domain/core/spec/core/sample_service_spec.rb +5 -0
- data/example/infrastructure/repository/Package.rb +1 -1
- data/example/infrastructure/repository/spec/example_spec.rb +5 -0
- data/example/infrastructure/repository/spec/spec_helper.rb +7 -0
- data/example/server/spec/server_spec.rb +5 -0
- data/example/server/spec/spec_helper.rb +7 -0
- data/example/{.runignore → tests/.runignore} +0 -0
- data/example/tests/diff_run +1 -30
- data/example/tests/run +1 -39
- data/lib/rdm.rb +2 -1
- data/lib/rdm/cli/dependencies_controller.rb +2 -0
- data/lib/rdm/cli/diff_spec_runner.rb +42 -0
- data/lib/rdm/errors.rb +3 -0
- data/lib/rdm/gen/config.rb +1 -3
- data/lib/rdm/gen/init.rb +13 -7
- data/lib/rdm/gen/package.rb +6 -6
- data/lib/rdm/handlers/dependencies_handler.rb +14 -9
- data/lib/rdm/handlers/diff_package_handler.rb +2 -1
- data/lib/rdm/handlers/template_handler.rb +2 -2
- data/lib/rdm/settings.rb +0 -1
- data/lib/rdm/source_modifier.rb +69 -0
- data/lib/rdm/spec_runner.rb +5 -2
- data/lib/rdm/spec_runner/command_generator.rb +3 -2
- data/lib/rdm/spec_runner/runner.rb +18 -8
- data/lib/rdm/templates/init/bin/console +1 -1
- data/lib/rdm/templates/init/{.runignore → tests/.runignore} +0 -0
- data/lib/rdm/templates/init/tests/diff_run +1 -33
- data/lib/rdm/templates/init/tests/run +1 -39
- data/lib/rdm/version.rb +1 -1
- data/spec/helpers/example_project_helper.rb +0 -185
- data/spec/rdm/cli/diff_spec_runner_spec.rb +55 -0
- data/spec/rdm/cli/init_spec.rb +0 -2
- data/spec/rdm/gen/init_spec.rb +9 -1
- data/spec/rdm/handlers/dependencies_handler_spec.rb +27 -0
- data/spec/rdm/source_parser_spec.rb +1 -2
- data/spec/rdm/spec_runner/runner_spec.rb +61 -3
- metadata +14 -9
- data/lib/rdm/source_composer.rb +0 -38
- data/spec/rdm/cli/diff_package_spec.rb +0 -5
- data/spec/rdm/source_composer_spec.rb +0 -76
data/lib/rdm.rb
CHANGED
@@ -16,6 +16,7 @@ module Rdm
|
|
16
16
|
require 'rdm/cli/template_generator'
|
17
17
|
require 'rdm/cli/dependencies_controller'
|
18
18
|
require 'rdm/cli/config'
|
19
|
+
require 'rdm/cli/diff_spec_runner.rb'
|
19
20
|
|
20
21
|
# Runtime part
|
21
22
|
require 'rdm/config'
|
@@ -28,12 +29,12 @@ module Rdm
|
|
28
29
|
require 'rdm/settings'
|
29
30
|
require 'rdm/source'
|
30
31
|
require 'rdm/source_parser'
|
31
|
-
require 'rdm/source_composer'
|
32
32
|
require 'rdm/source_locator'
|
33
33
|
require 'rdm/git/diff_manager'
|
34
34
|
require 'rdm/git/diff_command'
|
35
35
|
require 'rdm/git/repository_locator'
|
36
36
|
require 'rdm/config_locals'
|
37
|
+
require 'rdm/source_modifier'
|
37
38
|
|
38
39
|
# Package part
|
39
40
|
require 'rdm/packages/compiler_service'
|
@@ -24,6 +24,8 @@ module Rdm
|
|
24
24
|
@stdout.puts e.message
|
25
25
|
rescue Rdm::Errors::PackageHasNoDependencies => e
|
26
26
|
@stdout.puts "Package `#{e.message}` has no dependencies"
|
27
|
+
rescue Rdm::Errors::PackageDoesNotExist => e
|
28
|
+
@stdout.puts "Package `#{e.message}` is not defined"
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Rdm::CLI::DiffSpecRunner
|
2
|
+
def self.run(revision: 'HEAD', path:, stdout: STDOUT, show_output: true)
|
3
|
+
Rdm::CLI::DiffSpecRunner.new(revision, path, stdout, show_output).run
|
4
|
+
end
|
5
|
+
|
6
|
+
def initialize(revision, path, stdout, show_output)
|
7
|
+
@revision = revision
|
8
|
+
@path = path
|
9
|
+
@stdout = stdout
|
10
|
+
@show_output = show_output
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
changed_packages = Rdm::Handlers::DiffPackageHandler.handle(
|
15
|
+
path: @path,
|
16
|
+
revision: @revision
|
17
|
+
)
|
18
|
+
|
19
|
+
if changed_packages.empty?
|
20
|
+
@stdout.puts "No modified packages were found. Type `git add .` to index all changes..."
|
21
|
+
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
|
25
|
+
@stdout.puts "Tests for the following packages will run:\n - #{changed_packages.join("\n - ")}\n\n"
|
26
|
+
|
27
|
+
changed_packages.each do |package|
|
28
|
+
Rdm::SpecRunner.run(
|
29
|
+
package: package,
|
30
|
+
path: @path,
|
31
|
+
show_missing_packages: false,
|
32
|
+
stdout: @stdout,
|
33
|
+
show_output: @show_output
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
rescue Rdm::Errors::GitRepositoryNotInitialized
|
38
|
+
@stdout.puts "Git repository is not initialized. Use `git init .`"
|
39
|
+
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
end
|
data/lib/rdm/errors.rb
CHANGED
data/lib/rdm/gen/config.rb
CHANGED
@@ -14,8 +14,6 @@ class Rdm::Gen::Config
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def generate
|
17
|
-
@source.config(@config_name)
|
18
|
-
|
19
17
|
@locals = {
|
20
18
|
config_name: @config_name,
|
21
19
|
config_locals: @config_locals,
|
@@ -30,7 +28,7 @@ class Rdm::Gen::Config
|
|
30
28
|
local_path: './'
|
31
29
|
)
|
32
30
|
|
33
|
-
Rdm::
|
31
|
+
Rdm::SourceModifier.add_config(@config_name, get_source.root_path)
|
34
32
|
|
35
33
|
generated_files
|
36
34
|
end
|
data/lib/rdm/gen/init.rb
CHANGED
@@ -31,20 +31,26 @@ module Rdm
|
|
31
31
|
if File.exist?(File.join(@current_path, Rdm::SOURCE_FILENAME))
|
32
32
|
raise Rdm::Errors::ProjectAlreadyInitialized, "#{@current_path} has already #{Rdm::SOURCE_FILENAME}"
|
33
33
|
end
|
34
|
-
|
35
|
-
FileUtils.mkdir_p(local_templates_path)
|
36
|
-
FileUtils.cp_r(
|
37
|
-
@template_detector.gem_template_folder('package'),
|
38
|
-
@template_detector.project_template_folder('package')
|
39
|
-
)
|
40
34
|
|
41
|
-
Rdm::Handlers::TemplateHandler.generate(
|
35
|
+
generated_files = Rdm::Handlers::TemplateHandler.generate(
|
42
36
|
template_name: TEMPLATE_NAME,
|
43
37
|
current_path: @current_path,
|
44
38
|
local_path: INIT_PATH,
|
45
39
|
ignore_source_file: true,
|
46
40
|
stdout: @stdout
|
47
41
|
)
|
42
|
+
|
43
|
+
FileUtils.mkdir_p(local_templates_path)
|
44
|
+
FileUtils.cp_r(
|
45
|
+
@template_detector.gem_template_folder('package'),
|
46
|
+
File.dirname(@template_detector.project_template_folder('package'))
|
47
|
+
)
|
48
|
+
FileUtils.cp_r(
|
49
|
+
@template_detector.gem_template_folder('configs'),
|
50
|
+
File.dirname(@template_detector.project_template_folder('configs'))
|
51
|
+
)
|
52
|
+
|
53
|
+
generated_files
|
48
54
|
end
|
49
55
|
|
50
56
|
private
|
data/lib/rdm/gen/package.rb
CHANGED
@@ -21,20 +21,20 @@ module Rdm
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def create
|
24
|
-
@source.package(@local_path)
|
25
|
-
|
26
24
|
raise Rdm::Errors::PackageDirExists.new(@local_path) if Dir.exist?(File.join(@source.root_path, @local_path))
|
27
25
|
raise Rdm::Errors::PackageNameNotSpecified if @package_name.nil? || @package_name.empty?
|
28
26
|
raise Rdm::Errors::PackageExists if @source.packages.keys.include?(@package_name)
|
29
|
-
|
30
|
-
Rdm::
|
31
|
-
|
32
|
-
Rdm::Handlers::TemplateHandler.generate(
|
27
|
+
|
28
|
+
generated_files = Rdm::Handlers::TemplateHandler.generate(
|
33
29
|
template_name: TEMPLATE_NAME,
|
34
30
|
current_path: @current_path,
|
35
31
|
local_path: @local_path,
|
36
32
|
locals: { package_name: @package_name }.merge(@locals)
|
37
33
|
)
|
34
|
+
|
35
|
+
Rdm::SourceModifier.add_package(@local_path, get_source.root_path)
|
36
|
+
|
37
|
+
generated_files
|
38
38
|
end
|
39
39
|
|
40
40
|
def get_source
|
@@ -24,17 +24,14 @@ module Rdm
|
|
24
24
|
def initialize(package_name, project_path)
|
25
25
|
@package_name = package_name
|
26
26
|
@project_path = project_path
|
27
|
+
|
28
|
+
check_params!(
|
29
|
+
package_name: @package_name,
|
30
|
+
project_path: @project_path
|
31
|
+
)
|
27
32
|
end
|
28
33
|
|
29
|
-
def show_names
|
30
|
-
if @package_name.nil? || @package_name.empty?
|
31
|
-
raise Rdm::Errors::InvalidParams, "Package name should be specified"
|
32
|
-
end
|
33
|
-
|
34
|
-
if @project_path.nil? || @project_path.empty?
|
35
|
-
raise Rdm::Errors::InvalidParams, "Project directory should be specified"
|
36
|
-
end
|
37
|
-
|
34
|
+
def show_names
|
38
35
|
recursive_find_dependencies([@package_name])
|
39
36
|
end
|
40
37
|
|
@@ -90,6 +87,14 @@ module Rdm
|
|
90
87
|
|
91
88
|
private
|
92
89
|
|
90
|
+
def check_params!(package_name:, project_path:)
|
91
|
+
raise Rdm::Errors::InvalidParams, "Package name should be specified" if package_name.empty?
|
92
|
+
raise Rdm::Errors::InvalidParams, "Project directory should be specified" if project_path.empty?
|
93
|
+
raise Rdm::Errors::PackageDoesNotExist, package_name if source.packages[package_name].nil?
|
94
|
+
|
95
|
+
nil
|
96
|
+
end
|
97
|
+
|
93
98
|
def source
|
94
99
|
@source ||= Rdm::SourceParser.read_and_init_source(Rdm::SourceLocator.locate(@project_path))
|
95
100
|
end
|
@@ -21,11 +21,12 @@ module Rdm
|
|
21
21
|
|
22
22
|
modified_packages = Rdm::Git::DiffManager
|
23
23
|
.run(path: path, revision: revision)
|
24
|
+
.reject { |file| file.include?(Rdm::Gen::Init::LOCAL_TEMPLATES_PATH) }
|
24
25
|
.map { |file| Rdm::Packages::Locator.locate(file) rescue nil }
|
25
26
|
.map { |path_to_package| Rdm::PackageParser.parse_file(path_to_package).name rescue nil }
|
26
27
|
.reject(&:blank?)
|
27
28
|
.uniq
|
28
|
-
|
29
|
+
|
29
30
|
return get_dependencies(modified_packages) || []
|
30
31
|
end
|
31
32
|
|
@@ -43,7 +43,7 @@ module Rdm
|
|
43
43
|
template_detector = Rdm::Templates::TemplateDetector.new(project_path)
|
44
44
|
|
45
45
|
render_helper_path = "#{project_path}/.rdm/helpers/render_helper.rb"
|
46
|
-
require_relative render_helper_path if File.exist?(render_helper_path)
|
46
|
+
require_relative File.expand_path(render_helper_path) if File.exist?(render_helper_path)
|
47
47
|
|
48
48
|
@template_directory = template_detector.detect_template_folder(@template_name)
|
49
49
|
@destination_directory = File.join(project_path, @local_path)
|
@@ -99,7 +99,7 @@ module Rdm
|
|
99
99
|
|
100
100
|
rendered_rel_path
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
template_files_list.compact
|
104
104
|
end
|
105
105
|
|
data/lib/rdm/settings.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
class Rdm::SourceModifier
|
2
|
+
PACKAGE_LINE_REGEX = /package\s+['"]([\d\w\/\-_]+)['"]/
|
3
|
+
CONFIG_LINE_REGEX = /config\s+([:\w\-_\d]+)/
|
4
|
+
RDM_CONTENT_SPACES = "\n\n"
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def add_package(package_path, root_path)
|
8
|
+
Rdm::SourceModifier.new(root_path).add_package(package_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_config(config_name, root_path)
|
12
|
+
Rdm::SourceModifier.new(root_path).add_config(config_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(root_path)
|
17
|
+
@source_path = File.join(root_path, Rdm::SOURCE_FILENAME)
|
18
|
+
@package_lines = []
|
19
|
+
@config_lines = []
|
20
|
+
@setup_lines = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_package(package_path)
|
24
|
+
rebuild_file do
|
25
|
+
@package_lines.push "package \"#{package_path}\""
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_config(config_name)
|
30
|
+
rebuild_file do
|
31
|
+
@config_lines.push "config :#{config_name}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def rebuild_file
|
38
|
+
File.open(@source_path).each_line do |line|
|
39
|
+
case line
|
40
|
+
when PACKAGE_LINE_REGEX
|
41
|
+
@package_lines.push line
|
42
|
+
when CONFIG_LINE_REGEX
|
43
|
+
@config_lines.push line
|
44
|
+
when "\n"
|
45
|
+
# DO NOTHING
|
46
|
+
else
|
47
|
+
@setup_lines.push line
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
yield
|
52
|
+
|
53
|
+
File.open(@source_path, 'w') do |file|
|
54
|
+
file.write @setup_lines.join
|
55
|
+
file.write(RDM_CONTENT_SPACES)
|
56
|
+
|
57
|
+
file.write @config_lines.join
|
58
|
+
file.write(RDM_CONTENT_SPACES)
|
59
|
+
|
60
|
+
file.write @package_lines.join
|
61
|
+
end
|
62
|
+
|
63
|
+
@package_lines = []
|
64
|
+
@config_lines = []
|
65
|
+
@setup_lines = []
|
66
|
+
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
end
|
data/lib/rdm/spec_runner.rb
CHANGED
@@ -6,14 +6,17 @@ module Rdm::SpecRunner
|
|
6
6
|
show_missing_packages: true,
|
7
7
|
skip_ignored_packages: false,
|
8
8
|
stdout: STDOUT,
|
9
|
-
stdin: STDIN
|
9
|
+
stdin: STDIN,
|
10
|
+
show_output: true
|
10
11
|
)
|
11
12
|
Rdm::SpecRunner::Runner.new(
|
12
13
|
path: path,
|
13
14
|
package: package,
|
14
15
|
spec_matcher: spec_matcher,
|
15
16
|
show_missing_packages: show_missing_packages,
|
16
|
-
skip_ignored_packages: skip_ignored_packages
|
17
|
+
skip_ignored_packages: skip_ignored_packages,
|
18
|
+
show_output: show_output,
|
19
|
+
stdout: stdout
|
17
20
|
).run
|
18
21
|
|
19
22
|
rescue Rdm::Errors::SpecMatcherNoFiles => e
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class Rdm::SpecRunner::CommandGenerator
|
2
2
|
attr_accessor :package_name, :package_path, :spec_matcher
|
3
|
-
def initialize(package_name:, package_path:, spec_matcher:)
|
3
|
+
def initialize(package_name:, package_path:, spec_matcher:, show_output: true)
|
4
4
|
@package_name = package_name
|
5
5
|
@package_path = package_path
|
6
6
|
@spec_matcher = spec_matcher
|
7
|
+
@output = show_output ? '$stdout' : 'File::NULL'
|
7
8
|
end
|
8
9
|
|
9
10
|
def spec_count
|
@@ -14,7 +15,7 @@ class Rdm::SpecRunner::CommandGenerator
|
|
14
15
|
"print_message(
|
15
16
|
'**** Package: #{package_name} *****') \\
|
16
17
|
&& system('cd #{package_path} \\
|
17
|
-
&& bundle exec rspec --color --tty #{spec_matcher}', out:
|
18
|
+
&& bundle exec rspec --color --tty #{spec_matcher}', out: #{@output.to_s}, err: :out)"
|
18
19
|
end
|
19
20
|
|
20
21
|
def generate
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class Rdm::SpecRunner::Runner
|
2
|
-
RUNIGNORE_PATH
|
2
|
+
RUNIGNORE_PATH = 'tests/.runignore'.freeze
|
3
|
+
RUNIGNORE_COMMENT = '#'
|
3
4
|
|
4
5
|
attr_accessor :no_specs_packages
|
5
6
|
attr_accessor :prepared_command_params
|
@@ -10,7 +11,9 @@ class Rdm::SpecRunner::Runner
|
|
10
11
|
spec_matcher: nil,
|
11
12
|
path: nil,
|
12
13
|
show_missing_packages: true,
|
13
|
-
skip_ignored_packages: false
|
14
|
+
skip_ignored_packages: false,
|
15
|
+
stdout: STDOUT,
|
16
|
+
show_output: true
|
14
17
|
)
|
15
18
|
@package_name = package
|
16
19
|
@no_specs_packages = []
|
@@ -21,6 +24,8 @@ class Rdm::SpecRunner::Runner
|
|
21
24
|
@show_missing_packages = show_missing_packages
|
22
25
|
@skip_ignored_packages = skip_ignored_packages
|
23
26
|
@skipped_packages = []
|
27
|
+
@stdout = stdout
|
28
|
+
@show_output = show_output
|
24
29
|
end
|
25
30
|
|
26
31
|
def run
|
@@ -33,7 +38,7 @@ class Rdm::SpecRunner::Runner
|
|
33
38
|
format_string_number = @spec_string_number == 0 ? "" : ":#{@spec_string_number}"
|
34
39
|
@spec_matcher = @spec_file_matches.first + format_string_number
|
35
40
|
|
36
|
-
puts "Following spec matches your input: #{@spec_matcher}"
|
41
|
+
@stdout.puts "Following spec matches your input: #{@spec_matcher}"
|
37
42
|
else
|
38
43
|
raise Rdm::Errors::SpecMatcherMultipleFiles, @spec_file_matches.join("\n")
|
39
44
|
end
|
@@ -57,7 +62,7 @@ class Rdm::SpecRunner::Runner
|
|
57
62
|
end
|
58
63
|
|
59
64
|
def print_message(msg)
|
60
|
-
puts msg
|
65
|
+
@stdout.puts msg
|
61
66
|
true
|
62
67
|
end
|
63
68
|
|
@@ -101,7 +106,10 @@ class Rdm::SpecRunner::Runner
|
|
101
106
|
@prepared_command_params ||= begin
|
102
107
|
packages.map do |_name, package|
|
103
108
|
Rdm::SpecRunner::CommandGenerator.new(
|
104
|
-
package_name: package.name,
|
109
|
+
package_name: package.name,
|
110
|
+
package_path: package.path,
|
111
|
+
spec_matcher: @spec_matcher,
|
112
|
+
show_output: @show_output
|
105
113
|
).generate
|
106
114
|
end
|
107
115
|
end
|
@@ -140,11 +148,12 @@ class Rdm::SpecRunner::Runner
|
|
140
148
|
.map(&:strip)
|
141
149
|
.reject(&:empty?) rescue []
|
142
150
|
|
143
|
-
@skipped_packages
|
144
|
-
|
151
|
+
@skipped_packages = skipped_package_list.select {|line| package_list.include?(line)}
|
152
|
+
comment_runignore_lines = skipped_package_list.select {|line| line.start_with?(RUNIGNORE_COMMENT)}
|
153
|
+
invalid_ignore_packages = skipped_package_list - @skipped_packages - comment_runignore_lines
|
145
154
|
|
146
155
|
if !invalid_ignore_packages.empty?
|
147
|
-
puts "WARNING: #{RUNIGNORE_PATH} contains invalid package names: #{invalid_ignore_packages.
|
156
|
+
@stdout.puts "WARNING: #{RUNIGNORE_PATH} contains invalid package names: \n#{invalid_ignore_packages.join("\n")}"
|
148
157
|
end
|
149
158
|
else
|
150
159
|
@skipped_packages = []
|
@@ -175,5 +184,6 @@ class Rdm::SpecRunner::Runner
|
|
175
184
|
if $? && !$?.success?
|
176
185
|
exit(1)
|
177
186
|
end
|
187
|
+
|
178
188
|
end
|
179
189
|
end
|