cobra_commander 0.6.0 → 0.9.0
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 +4 -4
- data/.editorconfig +11 -0
- data/.github/workflows/ci.yml +38 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +24 -0
- data/README.md +109 -10
- data/cobra_commander.gemspec +6 -1
- data/exe/cobra +1 -1
- data/lib/cobra_commander.rb +10 -8
- data/lib/cobra_commander/affected.rb +43 -28
- data/lib/cobra_commander/change.rb +6 -6
- data/lib/cobra_commander/cli.rb +61 -73
- data/lib/cobra_commander/component.rb +52 -0
- data/lib/cobra_commander/dependencies.rb +4 -0
- data/lib/cobra_commander/dependencies/bundler.rb +38 -0
- data/lib/cobra_commander/dependencies/yarn/package.rb +37 -0
- data/lib/cobra_commander/dependencies/yarn/package_repo.rb +31 -0
- data/lib/cobra_commander/dependencies/yarn_workspace.rb +55 -0
- data/lib/cobra_commander/executor.rb +12 -23
- data/lib/cobra_commander/executor/component_exec.rb +23 -0
- data/lib/cobra_commander/executor/multi_exec.rb +45 -0
- data/lib/cobra_commander/output.rb +3 -72
- data/lib/cobra_commander/output/ascii_tree.rb +55 -0
- data/lib/cobra_commander/output/flat_list.rb +16 -0
- data/lib/cobra_commander/output/graph_viz.rb +27 -0
- data/lib/cobra_commander/umbrella.rb +51 -0
- data/lib/cobra_commander/version.rb +1 -1
- data/renovate.json +8 -0
- metadata +71 -15
- data/lib/cobra_commander/cached_component_tree.rb +0 -24
- data/lib/cobra_commander/calculated_component_tree.rb +0 -146
- data/lib/cobra_commander/component_tree.rb +0 -69
- data/lib/cobra_commander/graph.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d77734cb3eeb9f21c539f66a92d15e8aa94030046db7cdad3be8f6ed191c00aa
|
4
|
+
data.tar.gz: feacbdfbafb7baf191948e81014d9335b1cddf4a1ddd0f0a2aeac13af823efb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd926a0cc0bf9978b9b3dae6319e5b33853a2191f0d3b82645e696355a671769bf23894de45a58fb02fe5d0bb302c986d2ec8b3d71559c414248a82e2822c921
|
7
|
+
data.tar.gz: 60c750c84313992647cf94463ecc31fda2e5e3502f21a6eaacf4d6dbf206eddb8cacbd28d8925547c2851034bb64e3775413467f0c00962397e42af7484ac986
|
data/.editorconfig
ADDED
@@ -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.48.1
|
35
|
+
filter_mode: nofilter
|
36
|
+
fail_on_error: true
|
37
|
+
rubocop_extensions: ""
|
38
|
+
github_token: ${{ secrets.github_token }}
|
data/.travis.yml
CHANGED
@@ -4,8 +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
|
8
|
+
- export PATH="$HOME/.yarn/bin:$PATH"
|
7
9
|
rvm:
|
8
10
|
- 2.5.1
|
9
11
|
env:
|
10
|
-
- BUNDLER_VERSION=1.
|
11
|
-
- BUNDLER_VERSION=1.16.3
|
12
|
+
- BUNDLER_VERSION=1.17.3
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,30 @@
|
|
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
|
+
|
25
|
+
## Version 0.6.1 - 2019-07-05
|
26
|
+
|
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)
|
28
|
+
|
5
29
|
## Version 0.6.0 - 2019-07-03
|
6
30
|
|
7
31
|
* Tracks package.json `workspaces` in addition to `dependencies` and `devDependencies`. PR [#31](https://github.com/powerhome/cobra_commander/pull/31)
|
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
|
32
|
-
cobra
|
33
|
-
cobra
|
34
|
-
cobra
|
35
|
-
cobra
|
36
|
-
cobra
|
37
|
-
cobra
|
38
|
-
|
39
|
-
|
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.
|
data/cobra_commander.gemspec
CHANGED
@@ -11,10 +11,12 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.authors = [
|
12
12
|
"Ben Langfeld",
|
13
13
|
"Garett Arrowood",
|
14
|
+
"Carlos Palhares",
|
14
15
|
]
|
15
16
|
spec.email = [
|
16
17
|
"blangfeld@powerhrg.com",
|
17
18
|
"garett.arrowood@powerhrg.com",
|
19
|
+
"carlos.palhares@powerhrg.com",
|
18
20
|
]
|
19
21
|
spec.summary = "Tools for working with Component Based Rails Apps"
|
20
22
|
spec.description = <<~DESCRIPTION
|
@@ -32,10 +34,13 @@ DESCRIPTION
|
|
32
34
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
35
|
spec.require_paths = ["lib"]
|
34
36
|
|
37
|
+
spec.add_dependency "bundler", "~> 1.17"
|
35
38
|
spec.add_dependency "thor", ["< 2.0", ">= 0.18.1"]
|
36
39
|
spec.add_dependency "ruby-graphviz", "~> 1.2.3"
|
40
|
+
spec.add_dependency "tty-command", "~> 0.9.0"
|
41
|
+
spec.add_dependency "tty-spinner", "~> 0.9.3"
|
37
42
|
|
38
|
-
spec.add_development_dependency "bundler", "~> 1.
|
43
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
39
44
|
spec.add_development_dependency "rake", "~> 10.0"
|
40
45
|
spec.add_development_dependency "rspec", "~> 3.5"
|
41
46
|
spec.add_development_dependency "guard-rspec"
|
data/exe/cobra
CHANGED
data/lib/cobra_commander.rb
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "cobra_commander/
|
4
|
-
require "cobra_commander/
|
5
|
-
require "cobra_commander/
|
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
|
-
|
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 ||=
|
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:
|
27
|
-
transitively_affected_components:
|
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
|
-
|
43
|
-
@transitively.
|
44
|
-
@
|
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
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
76
|
+
@all_affected ||= (@directly | @transitively).sort_by(&:name)
|
66
77
|
end
|
67
78
|
|
68
79
|
def paths
|
69
|
-
@paths ||= all_affected.map
|
80
|
+
@paths ||= all_affected.map(&:root_paths).flatten.uniq
|
70
81
|
end
|
71
82
|
|
72
|
-
def
|
73
|
-
|
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
|
-
|
92
|
+
all_affected_sources.include?(:bundler)
|
78
93
|
end
|
79
94
|
|
80
95
|
def contains_js?
|
81
|
-
|
96
|
+
all_affected_sources.include?(:yarn)
|
82
97
|
end
|
83
98
|
end
|
84
99
|
end
|
@@ -8,12 +8,12 @@ module CobraCommander
|
|
8
8
|
class Change
|
9
9
|
InvalidSelectionError = Class.new(StandardError)
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@root_dir = Dir.chdir(
|
11
|
+
def initialize(umbrella, results, branch)
|
12
|
+
@root_dir = Dir.chdir(umbrella.path) { `git rev-parse --show-toplevel`.chomp }
|
13
13
|
@results = results
|
14
14
|
@branch = branch
|
15
|
-
@
|
16
|
-
@affected = Affected.new(@
|
15
|
+
@umbrella = umbrella
|
16
|
+
@affected = Affected.new(@umbrella, changes)
|
17
17
|
end
|
18
18
|
|
19
19
|
def run!
|
@@ -85,8 +85,8 @@ module CobraCommander
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
def display(
|
89
|
-
"#{
|
88
|
+
def display(name:, type:, **)
|
89
|
+
"#{name} - #{type}"
|
90
90
|
end
|
91
91
|
|
92
92
|
def blank_line
|