ruby_workspace_manager 0.2.0 → 0.3.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/lib/rwm/affected_detector.rb +21 -13
- data/lib/rwm/cli.rb +11 -0
- data/lib/rwm/gemfile.rb +5 -1
- data/lib/rwm/task_cache.rb +6 -6
- data/lib/rwm/version.rb +1 -1
- data/lib/rwm/workspace.rb +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fbe69d99300fafa6359944aa4a1cb16a3ed9cbb0e1e544b3a428a4e04af4dc66
|
|
4
|
+
data.tar.gz: 114e54d2ac5872ae866ecf0503b8ebdeb9c72b0db892a564e0b3889b4ff1e0fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bad333bc09182d824ef4c5b4e50fc290a7922e81a8e616a991d54cf994cca8340038fc5bb4b2dfa1612292ac7fc3f6008089ea6ff7a95b702ef65c0335ee97b4
|
|
7
|
+
data.tar.gz: bdfb899d956de2f9aa4d694d83b74cd79cb9936c0f38cfa1f64c78931846436be644510e0fce9dcfb8774af61b74d5cc24e09769aa0b2547c6a9ffba45d1dc95
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "open3"
|
|
4
|
+
|
|
3
5
|
module Rwm
|
|
4
6
|
class AffectedDetector
|
|
5
7
|
attr_reader :workspace, :graph, :base_branch
|
|
@@ -41,16 +43,22 @@ module Rwm
|
|
|
41
43
|
|
|
42
44
|
def detect_base_branch
|
|
43
45
|
# Try to read the remote's default branch
|
|
44
|
-
ref =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
ref, _, status = Open3.capture3("git", "-C", workspace.root, "symbolic-ref", "refs/remotes/origin/HEAD")
|
|
47
|
+
if status.success?
|
|
48
|
+
ref = ref.chomp
|
|
49
|
+
unless ref.empty?
|
|
50
|
+
# refs/remotes/origin/main → main
|
|
51
|
+
return ref.sub(%r{^refs/remotes/origin/}, "")
|
|
52
|
+
end
|
|
48
53
|
end
|
|
49
54
|
|
|
50
55
|
# Fall back: check if main or master exists
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
out, _, status = Open3.capture3("git", "-C", workspace.root, "branch", "--list", "main", "master")
|
|
57
|
+
if status.success?
|
|
58
|
+
branches = out.lines.map(&:strip)
|
|
59
|
+
return "main" if branches.include?("main")
|
|
60
|
+
return "master" if branches.include?("master")
|
|
61
|
+
end
|
|
54
62
|
|
|
55
63
|
# Last resort
|
|
56
64
|
"main"
|
|
@@ -60,17 +68,17 @@ module Rwm
|
|
|
60
68
|
files = Set.new
|
|
61
69
|
|
|
62
70
|
# 1. Committed changes: base branch vs HEAD
|
|
63
|
-
committed =
|
|
64
|
-
committed.lines.each { |l| files << l.chomp }
|
|
71
|
+
committed, _, status = Open3.capture3("git", "-C", workspace.root, "diff", "--name-only", "#{base_branch}...HEAD")
|
|
72
|
+
committed.lines.each { |l| files << l.chomp } if status.success?
|
|
65
73
|
|
|
66
74
|
unless @committed_only
|
|
67
75
|
# 2. Staged changes (not yet committed)
|
|
68
|
-
staged =
|
|
69
|
-
staged.lines.each { |l| files << l.chomp }
|
|
76
|
+
staged, _, status = Open3.capture3("git", "-C", workspace.root, "diff", "--name-only", "--cached")
|
|
77
|
+
staged.lines.each { |l| files << l.chomp } if status.success?
|
|
70
78
|
|
|
71
79
|
# 3. Unstaged working directory changes
|
|
72
|
-
unstaged =
|
|
73
|
-
unstaged.lines.each { |l| files << l.chomp }
|
|
80
|
+
unstaged, _, status = Open3.capture3("git", "-C", workspace.root, "diff", "--name-only")
|
|
81
|
+
unstaged.lines.each { |l| files << l.chomp } if status.success?
|
|
74
82
|
end
|
|
75
83
|
|
|
76
84
|
files.reject(&:empty?).to_a
|
data/lib/rwm/cli.rb
CHANGED
|
@@ -40,6 +40,8 @@ module Rwm
|
|
|
40
40
|
return 0
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
check_required_tools
|
|
44
|
+
|
|
43
45
|
# Expand task shortcuts: `rwm test` → `rwm run test`
|
|
44
46
|
if TASK_SHORTCUTS.include?(command_name)
|
|
45
47
|
@argv.unshift(command_name)
|
|
@@ -64,6 +66,15 @@ module Rwm
|
|
|
64
66
|
|
|
65
67
|
private
|
|
66
68
|
|
|
69
|
+
def check_required_tools
|
|
70
|
+
%w[git bundle].each do |tool|
|
|
71
|
+
unless system("which", tool, out: File::NULL, err: File::NULL)
|
|
72
|
+
$stderr.puts "Error: #{tool} is not installed or not in PATH."
|
|
73
|
+
exit 1
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
67
78
|
def print_help
|
|
68
79
|
puts <<~HELP
|
|
69
80
|
rwm #{Rwm::VERSION} — Ruby Workspace Manager
|
data/lib/rwm/gemfile.rb
CHANGED
|
@@ -12,12 +12,16 @@
|
|
|
12
12
|
# rwm_lib "auth"
|
|
13
13
|
|
|
14
14
|
require "bundler"
|
|
15
|
+
require "open3"
|
|
15
16
|
|
|
16
17
|
module Rwm
|
|
17
18
|
module GemfileDsl
|
|
18
19
|
def rwm_workspace_root
|
|
19
|
-
@rwm_workspace_root ||=
|
|
20
|
+
@rwm_workspace_root ||= begin
|
|
21
|
+
out, _, status = Open3.capture3("git", "rev-parse", "--show-toplevel")
|
|
22
|
+
root = status.success? ? out.strip : ""
|
|
20
23
|
raise "rwm: not inside a git repository" if root.empty?
|
|
24
|
+
root
|
|
21
25
|
end
|
|
22
26
|
end
|
|
23
27
|
|
data/lib/rwm/task_cache.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require "digest"
|
|
4
4
|
require "fileutils"
|
|
5
5
|
require "json"
|
|
6
|
-
require "
|
|
6
|
+
require "open3"
|
|
7
7
|
|
|
8
8
|
module Rwm
|
|
9
9
|
class TaskCache
|
|
@@ -63,12 +63,12 @@ module Rwm
|
|
|
63
63
|
digest.update(File.read(file))
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
# Include dependency content hashes (transitive invalidation)
|
|
66
|
+
# Include dependency content hashes (transitive invalidation).
|
|
67
|
+
# If a dependency is missing, let it raise — a stale graph should
|
|
68
|
+
# not silently produce incorrect cache hits.
|
|
67
69
|
@graph.dependencies(package.name).sort.each do |dep_name|
|
|
68
70
|
dep_pkg = @workspace.find_package(dep_name)
|
|
69
71
|
digest.update(content_hash(dep_pkg))
|
|
70
|
-
rescue PackageNotFoundError
|
|
71
|
-
next
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
@content_hashes[package.name] = digest.hexdigest
|
|
@@ -78,8 +78,8 @@ module Rwm
|
|
|
78
78
|
def cache_declarations(package)
|
|
79
79
|
return @cache_declarations[package.name] if @cache_declarations.key?(package.name)
|
|
80
80
|
|
|
81
|
-
output =
|
|
82
|
-
@cache_declarations[package.name] = if
|
|
81
|
+
output, _, status = Open3.capture3("bundle", "exec", "rake", "rwm:cache_config", chdir: package.path)
|
|
82
|
+
@cache_declarations[package.name] = if status.success? && !output.strip.empty?
|
|
83
83
|
JSON.parse(output.strip)
|
|
84
84
|
else
|
|
85
85
|
{}
|
data/lib/rwm/version.rb
CHANGED
data/lib/rwm/workspace.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "open3"
|
|
4
|
+
|
|
3
5
|
module Rwm
|
|
4
6
|
class Workspace
|
|
5
7
|
RWM_DIR = ".rwm"
|
|
@@ -15,7 +17,8 @@ module Rwm
|
|
|
15
17
|
# Find the workspace root via git
|
|
16
18
|
def self.find(start_dir = Dir.pwd)
|
|
17
19
|
dir = File.expand_path(start_dir)
|
|
18
|
-
git_root =
|
|
20
|
+
git_root, _, status = Open3.capture3("git", "-C", dir, "rev-parse", "--show-toplevel")
|
|
21
|
+
git_root = status.success? ? git_root.chomp : ""
|
|
19
22
|
|
|
20
23
|
raise WorkspaceNotFoundError if git_root.empty?
|
|
21
24
|
|