cobra_commander 0.6.1 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7b56002a2501fd994a0d806833c2d4f10f3d8090b5f9983534c1fd2b36bf8e6
4
- data.tar.gz: 6b0dca74d6a0f9a91ee7a0d7704bfbc82710cbfa89e696184e87de1f623beb40
3
+ metadata.gz: 8e12f66b669fc83fc691deb3f67183550c5341f6ce8fdf18d8f43ce5b5859589
4
+ data.tar.gz: 7a15cc9bbc0226df01609c96917c5e2d750376a2ef68769dc7153eb4a0224cd7
5
5
  SHA512:
6
- metadata.gz: a321af237699e859f729bc241889bb95b83832f7d8e4d5191e09fc627b5101240dfa8ef8f96034ab7c0f3dd42f5b4518976c65953fc088b7e69410040a0ad422
7
- data.tar.gz: 7a447a00e0fb9d4b389d1f9296115f8b2e232cd72b5d3519d3868b0b69211ad92ce0fb0bb07921ba596e87796f657f56826a905ced034cee1eb708783170672e
6
+ metadata.gz: 1077abb8aac431dec03d9f2ab79e95d411fa451ef1f6381a984fda377e8f4ee96c9084de69b2062712f7b943b03a74316e47aacce73cfca20475d128027aeee7
7
+ data.tar.gz: 5cf5496ed9ff196ca395a4474be66ddafaebd1fd0073d2a5b7bb957d2cd90dfc3f6a36706782bac361029996798cd5520093a3275126240df867a90791ec20e7
@@ -0,0 +1,11 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+ # top-most EditorConfig file
3
+ root = true
4
+
5
+ # Unix-style newlines with a newline ending every file
6
+ [*]
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+ indent_style = space
11
+ indent_size = 2
@@ -0,0 +1,38 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ name: Tests
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ ruby:
12
+ - "2.5"
13
+ - "2.6"
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ bundler: 1
21
+ bundler-cache: true
22
+ - name: Install Graphviz
23
+ run: sudo apt -qq install graphviz
24
+ - name: Run tests
25
+ run: bundle exec rake spec
26
+ lint:
27
+ name: Lint Ruby
28
+ runs-on: ubuntu-latest
29
+ steps:
30
+ - uses: actions/checkout@v2
31
+ - name: rubocop
32
+ uses: reviewdog/action-rubocop@v1
33
+ with:
34
+ rubocop_version: 0.88.0
35
+ filter_mode: nofilter
36
+ fail_on_error: true
37
+ rubocop_extensions: ""
38
+ github_token: ${{ secrets.github_token }}
@@ -1,50 +1,20 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
3
-
4
- Metrics/LineLength:
5
- Max: 120
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
6
4
 
7
5
  Metrics/BlockLength:
8
6
  Exclude:
9
7
  - spec/**/*.rb
10
8
  - cobra_commander.gemspec
11
9
 
12
- Metrics/ClassLength:
13
- Exclude:
14
- - spec/**/*.rb
15
- - cobra_commander.gemspec
16
-
17
- Style/AccessModifierIndentation:
10
+ Layout/AccessModifierIndentation:
18
11
  EnforcedStyle: outdent
19
12
 
20
- Style/Documentation:
21
- Enabled: true
22
-
23
- Style/ExtraSpacing:
24
- Exclude:
25
- - cobra_commander.gemspec
26
-
27
- Style/SpaceAroundOperators:
28
- Exclude:
29
- - cobra_commander.gemspec
30
-
31
- Style/Lambda:
32
- EnforcedStyle: literal
33
-
34
- Style/PercentLiteralDelimiters:
35
- PreferredDelimiters:
36
- default: ()
37
- '%i': '[]'
38
- '%I': '[]'
39
- '%r': '{}'
40
- '%w': '[]'
41
- '%W': '[]'
42
-
43
- # Single quotes being faster is hardly measurable and only affects parse time.
44
- # Enforcing double quotes reduces the times where you need to change them when introducing an interpolation.
45
- # Use single quotes only if their semantics are needed.
46
13
  Style/StringLiterals:
47
14
  EnforcedStyle: double_quotes
48
15
 
49
- Style/TrailingCommaInLiteral:
50
- EnforcedStyleForMultiline: comma
16
+ Style/TrailingCommaInArrayLiteral:
17
+ EnforcedStyleForMultiline: consistent_comma
18
+
19
+ Style/TrailingCommaInHashLiteral:
20
+ EnforcedStyleForMultiline: consistent_comma
@@ -4,10 +4,9 @@ before_install:
4
4
  - "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
5
5
  - gem install bundler:"$BUNDLER_VERSION"
6
6
  - sudo apt-get -qq install graphviz
7
- - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.13.0
7
+ - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.13.0
8
8
  - export PATH="$HOME/.yarn/bin:$PATH"
9
9
  rvm:
10
10
  - 2.5.1
11
11
  env:
12
- - BUNDLER_VERSION=1.15.4
13
- - BUNDLER_VERSION=1.16.3
12
+ - BUNDLER_VERSION=1.17.3
@@ -2,6 +2,26 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Version 0.9.0 - 2020-08-26
6
+
7
+ * Add support for parallel task execution to `cobra exec`.
8
+
9
+ ## Version 0.8.1 - 2020-07-29
10
+
11
+ * Fix CobraCommander::Executor when running [`bundler`](https://bundler.io/) based commands (i.e.: `bundle exec rspec`)
12
+
13
+ ## Version 0.8 - 2020-07-21
14
+
15
+ * Standardize Cobra CLI options
16
+ * More powerful filters to all cobra commands (--js, --ruby)
17
+ * More powerful filters to cobra ls and exec (--dependencies, --dependents)
18
+ * Graphs for components, not just umbrella
19
+
20
+ ## Version 0.7 - 2020-07-08
21
+
22
+ * Introduces CobraCommander::Umbrella with optimizations for dependency resolution
23
+ * Deprecates cobra cache and cache usages
24
+
5
25
  ## Version 0.6.1 - 2019-07-05
6
26
 
7
27
  * Better supports yarn workspaces globbing by delegating to yarn to calculate the list of components rather than re-implementing in Ruby. PR [#34](https://github.com/powerhome/cobra_commander/pull/34)
data/README.md CHANGED
@@ -24,19 +24,110 @@ Or install it yourself as:
24
24
 
25
25
  $ gem install cobra_commander
26
26
 
27
- ## Usage
27
+ ## Usage (cobra help)
28
28
 
29
29
  ```bash
30
30
  Commands:
31
- cobra cache APP_PATH CACHE_PATH # Caches a representation of the component structure of the app
32
- cobra changes APP_PATH [--results=RESULTS] [--branch=BRANCH] [--cache=nil] # Prints list of changed files
33
- cobra dependencies_of [component] [--app=pwd] [--format=FORMAT] [--cache=nil] # Outputs a list of components that [component] depends on within [app] context
34
- cobra dependents_of [component] [--app=pwd] [--format=FORMAT] [--cache=nil] # Outputs count of components in [app] dependent on [component]
35
- cobra do [command] [--app=pwd] [--cache=nil] # Executes the command in the context of each component in [app]
36
- cobra graph APP_PATH [--format=FORMAT] [--cache=nil] # Outputs graph
37
- cobra help [COMMAND] # Describe available commands or one specific command
38
- cobra ls [app_path] [--app=pwd] [--format=FORMAT] [--cache=nil] # Prints tree of components for an app
39
- cobra version # Prints version
31
+ cobra changes [--results=RESULTS] [--branch=BRANCH] # Prints list of changed files
32
+ cobra exec [component] <command> # Executes the command in the context of a given component or set of components. If no component is given executes the command in all components.
33
+ cobra graph [component] # Outputs a graph of a given component or umbrella
34
+ cobra help [COMMAND] # Describe available commands or one specific command
35
+ cobra ls [component] # Lists the components in the context of a given component or umbrella
36
+ cobra tree [component] # Prints the dependency tree of a given component or umbrella
37
+ cobra version # Prints version
38
+
39
+ Options:
40
+ -a, [--app=APP]
41
+ # Default: /Users/chjunior/workspace/power/cobra_commander
42
+ [--js], [--no-js] # Consider only the JS dependency graph
43
+ [--ruby], [--no-ruby] # Consider only the Ruby dependency graph
44
+ ```
45
+
46
+ ### cobra changes
47
+
48
+ ```sh
49
+ ➜ nitro git:(nova/remove-cobra-commander) be cobra help changes
50
+ Usage:
51
+ cobra changes [--results=RESULTS] [--branch=BRANCH]
52
+
53
+ Options:
54
+ -r, [--results=RESULTS] # Accepts test, full, name or json
55
+ # Default: test
56
+ -b, [--branch=BRANCH] # Specified target to calculate against
57
+ # Default: master
58
+ -a, [--app=APP]
59
+ # Default: /Users/chjunior/workspace/power/nitro
60
+ [--js], [--no-js] # Consider only the JS dependency graph
61
+ [--ruby], [--no-ruby] # Consider only the Ruby dependency graph
62
+
63
+ Prints list of changed files
64
+ ```
65
+
66
+ ### cobra exec
67
+
68
+ ```sh
69
+ Usage:
70
+ cobra exec [component] <command>
71
+
72
+ Options:
73
+ [--dependencies], [--no-dependencies] # Run the command on each dependency of a given component
74
+ [--dependents], [--no-dependents] # Run the command on each dependency of a given component
75
+ -a, [--app=APP]
76
+ # Default: /Users/chjunior/workspace/power/cobra_commander
77
+ [--js], [--no-js] # Consider only the JS dependency graph
78
+ [--ruby], [--no-ruby] # Consider only the Ruby dependency graph
79
+
80
+ Executes the command in the context of a given component or set of components. If no component is given executes the command in all components.
81
+ ```
82
+
83
+ ### cobra graph
84
+
85
+ ```sh
86
+ Usage:
87
+ cobra graph [component]
88
+
89
+ Options:
90
+ -o, [--output=OUTPUT] # Output file, accepts .png or .dot
91
+ # Default: /Users/chjunior/workspace/power/cobra_commander/output.png
92
+ -a, [--app=APP]
93
+ # Default: /Users/chjunior/workspace/power/cobra_commander
94
+ [--js], [--no-js] # Consider only the JS dependency graph
95
+ [--ruby], [--no-ruby] # Consider only the Ruby dependency graph
96
+
97
+ Outputs a graph of a given component or umbrella
98
+ ```
99
+
100
+ ### cobra ls
101
+
102
+ ```sh
103
+ Usage:
104
+ cobra ls [component]
105
+
106
+ Options:
107
+ -d, [--dependencies], [--no-dependencies] # Run the command on each dependency of a given component
108
+ -D, [--dependents], [--no-dependents] # Run the command on each dependency of a given component
109
+ -t, [--total], [--no-total] # Prints the total count of components
110
+ -a, [--app=APP]
111
+ # Default: /Users/chjunior/workspace/power/cobra_commander
112
+ [--js], [--no-js] # Consider only the JS dependency graph
113
+ [--ruby], [--no-ruby] # Consider only the Ruby dependency graph
114
+
115
+ Lists the components in the context of a given component or umbrella
116
+ ```
117
+
118
+ ### cobra tree
119
+
120
+ ```sh
121
+ Usage:
122
+ cobra tree [component]
123
+
124
+ Options:
125
+ -a, [--app=APP]
126
+ # Default: /Users/chjunior/workspace/power/cobra_commander
127
+ [--js], [--no-js] # Consider only the JS dependency graph
128
+ [--ruby], [--no-ruby] # Consider only the Ruby dependency graph
129
+
130
+ Prints the dependency tree of a given component or umbrella
40
131
  ```
41
132
 
42
133
  ## Development
@@ -45,6 +136,14 @@ After checking out the repo, run `bin/setup` to install dependencies. You will a
45
136
 
46
137
  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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
138
 
139
+ ### Bundled App
140
+
141
+ In order to maintain the features around umbrella apps and specially `changes`, a bundled [`umbrella app repo`](spec/fixtures/app.tgz) is included in this repository. This repo is compacted by `tar`/`gzip` in order to keep isolation, the format was chosen to avoid issues described in https://github.com/swcarpentry/git-novice/issues/272. To avoid the same issues, the workflow for this fixture app is the following:
142
+
143
+ 1. unpack it somewhere outside your repo
144
+ 1. do your changes and commit (locally only, it doesn't have a remote)
145
+ 1. from within the app run `tar cfz path/to/cobra/spec/fixtures/app.tgz .`
146
+
48
147
  ## Contributing
49
148
 
50
149
  Bug reports and pull requests are welcome on GitHub at https://github.com/powerhome/cobra_commander. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require "cobra_commander/version"
7
6
 
@@ -11,17 +10,19 @@ Gem::Specification.new do |spec|
11
10
  spec.authors = [
12
11
  "Ben Langfeld",
13
12
  "Garett Arrowood",
13
+ "Carlos Palhares",
14
14
  ]
15
- spec.email = [
15
+ spec.email = [
16
16
  "blangfeld@powerhrg.com",
17
17
  "garett.arrowood@powerhrg.com",
18
+ "carlos.palhares@powerhrg.com",
18
19
  ]
19
20
  spec.summary = "Tools for working with Component Based Rails Apps"
20
21
  spec.description = <<~DESCRIPTION
21
22
  Tools for working with Component Based Rails Apps (see http://shageman.github.io/cbra.info/).
22
23
  Includes tools for graphing the components of an app and their relationships, as well as selectively
23
24
  testing components based on changes made.
24
- DESCRIPTION
25
+ DESCRIPTION
25
26
  spec.homepage = "http://tech.powerhrg.com/cobra_commander/"
26
27
  spec.license = "MIT"
27
28
 
@@ -32,14 +33,17 @@ DESCRIPTION
32
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
34
  spec.require_paths = ["lib"]
34
35
 
35
- spec.add_dependency "thor", ["< 2.0", ">= 0.18.1"]
36
+ spec.add_dependency "bundler", "~> 1.17"
36
37
  spec.add_dependency "ruby-graphviz", "~> 1.2.3"
38
+ spec.add_dependency "thor", ["< 2.0", ">= 0.18.1"]
39
+ spec.add_dependency "tty-command", "~> 0.9.0"
40
+ spec.add_dependency "tty-spinner", "~> 0.9.3"
37
41
 
38
- spec.add_development_dependency "bundler", "~> 1.13"
39
- spec.add_development_dependency "rake", "~> 10.0"
40
- spec.add_development_dependency "rspec", "~> 3.5"
41
- spec.add_development_dependency "guard-rspec"
42
42
  spec.add_development_dependency "aruba", "~> 0.14.2"
43
- spec.add_development_dependency "rubocop", "0.48.1"
43
+ spec.add_development_dependency "bundler", "~> 1.17"
44
+ spec.add_development_dependency "guard-rspec"
44
45
  spec.add_development_dependency "pry"
46
+ spec.add_development_dependency "rake", "~> 10.0"
47
+ spec.add_development_dependency "rspec", "~> 3.5"
48
+ spec.add_development_dependency "rubocop", "0.88.0"
45
49
  end
data/exe/cobra CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "cobra_commander"
4
+ require "cobra_commander/cli"
5
5
 
6
6
  CobraCommander::CLI.start
@@ -1,14 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "cobra_commander/cli"
4
- require "cobra_commander/cached_component_tree"
5
- require "cobra_commander/calculated_component_tree"
3
+ require "cobra_commander/dependencies"
4
+ require "cobra_commander/component"
5
+ require "cobra_commander/umbrella"
6
6
  require "cobra_commander/version"
7
- require "cobra_commander/graph"
8
- require "cobra_commander/change"
9
- require "cobra_commander/affected"
10
- require "cobra_commander/output"
11
- require "cobra_commander/executor"
12
7
 
13
8
  # Tools for working with Component Based Rails Apps (see http://shageman.github.io/cbra.info/).
14
9
  # Includes tools for graphing the components of an app and their relationships, as well as selectively
@@ -16,6 +11,13 @@ require "cobra_commander/executor"
16
11
  module CobraCommander
17
12
  UMBRELLA_APP_NAME = "App"
18
13
 
14
+ def self.umbrella(root_path, yarn: false, bundler: false, name: UMBRELLA_APP_NAME)
15
+ umbrella = Umbrella.new(name, root_path)
16
+ umbrella.add_source(:yarn, Dependencies::YarnWorkspace.new(root_path)) unless bundler
17
+ umbrella.add_source(:bundler, Dependencies::Bundler.new(root_path)) unless yarn
18
+ umbrella
19
+ end
20
+
19
21
  def self.umbrella_tree(path)
20
22
  CalculatedComponentTree.new(UMBRELLA_APP_NAME, path)
21
23
  end
@@ -3,28 +3,33 @@
3
3
  module CobraCommander
4
4
  # Calculates directly & transitively affected components
5
5
  class Affected
6
- attr_reader :directly, :transitively
7
-
8
- def initialize(tree, changes, path)
9
- @tree = tree
6
+ def initialize(umbrella, changes)
7
+ @umbrella = umbrella
10
8
  @changes = changes
11
- @path = path
12
9
  run!
13
10
  end
14
11
 
15
12
  def names
16
- @names ||= paths.map { |path| File.basename(path) }
13
+ @names ||= all_affected.map(&:name)
17
14
  end
18
15
 
19
16
  def scripts
20
17
  @scripts ||= paths.map { |path| File.join(path, "test.sh") }
21
18
  end
22
19
 
20
+ def directly
21
+ @directly.map(&method(:affected_component))
22
+ end
23
+
24
+ def transitively
25
+ @transitively.map(&method(:affected_component))
26
+ end
27
+
23
28
  def json_representation # rubocop:disable Metrics/MethodLength
24
29
  {
25
30
  changed_files: @changes,
26
- directly_affected_components: @directly,
27
- transitively_affected_components: @transitively,
31
+ directly_affected_components: directly,
32
+ transitively_affected_components: transitively,
28
33
  test_scripts: scripts,
29
34
  component_names: names,
30
35
  languages: {
@@ -39,46 +44,56 @@ module CobraCommander
39
44
  def run!
40
45
  @transitively = Set.new
41
46
  @directly = Set.new
42
- find_dependencies(@tree)
43
- @transitively.delete(name: UMBRELLA_APP_NAME, path: @path, type: @tree[:type])
44
- @transitively = @transitively.to_a.sort_by { |h| h[:name] }
45
- @directly = @directly.to_a.sort_by { |h| h[:name] }
47
+ @umbrella.components.each(&method(:add_if_changed))
48
+ @transitively = @transitively.sort_by(&:name)
49
+ @directly = @directly.sort_by(&:name)
46
50
  end
47
51
 
48
- def find_dependencies(parent_component)
49
- parent_component[:dependencies].each do |component|
50
- add_if_changed(component)
51
- find_dependencies(component)
52
+ def component_changed?(component)
53
+ component.root_paths.any? do |component_path|
54
+ @changes.any? do |file_path|
55
+ file_path.start_with?(component_path)
56
+ end
52
57
  end
53
58
  end
54
59
 
55
60
  def add_if_changed(component)
56
- @changes.each do |change|
57
- if change.start_with?(component[:path])
58
- @directly << component.reject { |k| k == :dependencies || k == :ancestry }
59
- @transitively.merge component[:ancestry]
60
- end
61
- end
61
+ return unless component_changed?(component)
62
+
63
+ @directly << component
64
+ @transitively.merge(component.deep_dependents)
65
+ end
66
+
67
+ def affected_component(component)
68
+ {
69
+ name: component.name,
70
+ path: component.root_paths,
71
+ type: component.sources.keys.map(&:to_s).map(&:capitalize).join(" & "),
72
+ }
62
73
  end
63
74
 
64
75
  def all_affected
65
- @all_affected ||= (@directly + @transitively).uniq.sort_by { |h| h[:path] }
76
+ @all_affected ||= (@directly | @transitively).sort_by(&:name)
66
77
  end
67
78
 
68
79
  def paths
69
- @paths ||= all_affected.map { |component| component[:path] }
80
+ @paths ||= all_affected.map(&:root_paths).flatten.uniq
70
81
  end
71
82
 
72
- def types
73
- @types ||= all_affected.map { |component| component[:type] }
83
+ def all_affected_sources
84
+ all_affected
85
+ .map(&:sources)
86
+ .map(&:keys)
87
+ .flatten
88
+ .uniq
74
89
  end
75
90
 
76
91
  def contains_ruby?
77
- types.uniq.join.include?("Ruby")
92
+ all_affected_sources.include?(:bundler)
78
93
  end
79
94
 
80
95
  def contains_js?
81
- types.uniq.join.include?("JS")
96
+ all_affected_sources.include?(:yarn)
82
97
  end
83
98
  end
84
99
  end