makit 0.0.99 → 0.0.111
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/README.md +41 -0
- data/exe/makit +5 -0
- data/lib/makit/apache.rb +7 -11
- data/lib/makit/cli/build_commands.rb +500 -0
- data/lib/makit/cli/generators/base_generator.rb +74 -0
- data/lib/makit/cli/generators/dotnet_generator.rb +50 -0
- data/lib/makit/cli/generators/generator_factory.rb +49 -0
- data/lib/makit/cli/generators/node_generator.rb +50 -0
- data/lib/makit/cli/generators/ruby_generator.rb +77 -0
- data/lib/makit/cli/generators/rust_generator.rb +50 -0
- data/lib/makit/cli/generators/templates/dotnet_templates.rb +167 -0
- data/lib/makit/cli/generators/templates/node_templates.rb +161 -0
- data/lib/makit/cli/generators/templates/ruby/gemfile.rb +26 -0
- data/lib/makit/cli/generators/templates/ruby/gemspec.rb +40 -0
- data/lib/makit/cli/generators/templates/ruby/main_lib.rb +33 -0
- data/lib/makit/cli/generators/templates/ruby/rakefile.rb +35 -0
- data/lib/makit/cli/generators/templates/ruby/readme.rb +63 -0
- data/lib/makit/cli/generators/templates/ruby/test.rb +39 -0
- data/lib/makit/cli/generators/templates/ruby/test_helper.rb +29 -0
- data/lib/makit/cli/generators/templates/ruby/version.rb +29 -0
- data/lib/makit/cli/generators/templates/rust_templates.rb +128 -0
- data/lib/makit/cli/main.rb +48 -19
- data/lib/makit/cli/project_commands.rb +868 -0
- data/lib/makit/cli/repository_commands.rb +661 -0
- data/lib/makit/cli/utility_commands.rb +521 -0
- data/lib/makit/command_runner.rb +187 -128
- data/lib/makit/commands/compatibility.rb +365 -0
- data/lib/makit/commands/factory.rb +359 -0
- data/lib/makit/commands/middleware/base.rb +73 -0
- data/lib/makit/commands/middleware/cache.rb +248 -0
- data/lib/makit/commands/middleware/command_logger.rb +323 -0
- data/lib/makit/commands/middleware/unified_logger.rb +243 -0
- data/lib/makit/commands/middleware/validator.rb +269 -0
- data/lib/makit/commands/request.rb +254 -0
- data/lib/makit/commands/result.rb +323 -0
- data/lib/makit/commands/runner.rb +317 -0
- data/lib/makit/commands/strategies/base.rb +160 -0
- data/lib/makit/commands/strategies/synchronous.rb +134 -0
- data/lib/makit/commands.rb +24 -3
- data/lib/makit/configuration/gitlab_helper.rb +60 -0
- data/lib/makit/configuration/project.rb +127 -0
- data/lib/makit/configuration/rakefile_helper.rb +43 -0
- data/lib/makit/configuration/step.rb +34 -0
- data/lib/makit/configuration.rb +14 -0
- data/lib/makit/content/default_gitignore.rb +4 -2
- data/lib/makit/content/default_rakefile.rb +4 -2
- data/lib/makit/content/gem_rakefile.rb +4 -2
- data/lib/makit/context.rb +1 -0
- data/lib/makit/data.rb +9 -10
- data/lib/makit/directories.rb +48 -52
- data/lib/makit/directory.rb +38 -52
- data/lib/makit/docs/files.rb +5 -10
- data/lib/makit/docs/rake.rb +16 -20
- data/lib/makit/dotnet/cli.rb +65 -0
- data/lib/makit/dotnet/project.rb +153 -0
- data/lib/makit/dotnet/solution.rb +38 -0
- data/lib/makit/dotnet/solution_classlib.rb +239 -0
- data/lib/makit/dotnet/solution_console.rb +264 -0
- data/lib/makit/dotnet/solution_maui.rb +354 -0
- data/lib/makit/dotnet/solution_wasm.rb +275 -0
- data/lib/makit/dotnet/solution_wpf.rb +304 -0
- data/lib/makit/dotnet.rb +54 -171
- data/lib/makit/email.rb +46 -17
- data/lib/makit/environment.rb +22 -19
- data/lib/makit/examples/runner.rb +370 -0
- data/lib/makit/exceptions.rb +45 -0
- data/lib/makit/fileinfo.rb +3 -5
- data/lib/makit/files.rb +12 -16
- data/lib/makit/gems.rb +40 -39
- data/lib/makit/git/cli.rb +54 -0
- data/lib/makit/git/repository.rb +90 -0
- data/lib/makit/git.rb +44 -91
- data/lib/makit/gitlab_runner.rb +0 -1
- data/lib/makit/humanize.rb +31 -23
- data/lib/makit/indexer.rb +15 -24
- data/lib/makit/logging/configuration.rb +305 -0
- data/lib/makit/logging/format_registry.rb +84 -0
- data/lib/makit/logging/formatters/base.rb +39 -0
- data/lib/makit/logging/formatters/console_formatter.rb +127 -0
- data/lib/makit/logging/formatters/json_formatter.rb +65 -0
- data/lib/makit/logging/formatters/plain_text_formatter.rb +71 -0
- data/lib/makit/logging/formatters/text_formatter.rb +64 -0
- data/lib/makit/logging/log_request.rb +115 -0
- data/lib/makit/logging/logger.rb +159 -0
- data/lib/makit/logging/sinks/base.rb +91 -0
- data/lib/makit/logging/sinks/console.rb +72 -0
- data/lib/makit/logging/sinks/file_sink.rb +92 -0
- data/lib/makit/logging/sinks/structured.rb +129 -0
- data/lib/makit/logging/sinks/unified_file_sink.rb +303 -0
- data/lib/makit/logging.rb +452 -37
- data/lib/makit/markdown.rb +18 -18
- data/lib/makit/mp/basic_object_mp.rb +5 -4
- data/lib/makit/mp/command_mp.rb +5 -5
- data/lib/makit/mp/command_request.mp.rb +3 -2
- data/lib/makit/mp/project_mp.rb +85 -96
- data/lib/makit/mp/string_mp.rb +245 -73
- data/lib/makit/nuget.rb +27 -25
- data/lib/makit/port.rb +25 -27
- data/lib/makit/process.rb +127 -29
- data/lib/makit/protoc.rb +27 -24
- data/lib/makit/rake/cli.rb +196 -0
- data/lib/makit/rake.rb +6 -6
- data/lib/makit/ruby/cli.rb +185 -0
- data/lib/makit/ruby.rb +25 -0
- data/lib/makit/secrets.rb +18 -18
- data/lib/makit/serializer.rb +29 -27
- data/lib/makit/services/builder.rb +186 -0
- data/lib/makit/services/error_handler.rb +226 -0
- data/lib/makit/services/repository_manager.rb +229 -0
- data/lib/makit/services/validator.rb +112 -0
- data/lib/makit/setup/classlib.rb +53 -0
- data/lib/makit/setup/gem.rb +250 -0
- data/lib/makit/setup/runner.rb +40 -0
- data/lib/makit/show.rb +16 -16
- data/lib/makit/storage.rb +32 -37
- data/lib/makit/symbols.rb +12 -0
- data/lib/makit/task_hooks.rb +125 -0
- data/lib/makit/task_info.rb +63 -21
- data/lib/makit/tasks/at_exit.rb +13 -0
- data/lib/makit/tasks/build.rb +18 -0
- data/lib/makit/tasks/clean.rb +11 -0
- data/lib/makit/tasks/hook_manager.rb +239 -0
- data/lib/makit/tasks/init.rb +47 -0
- data/lib/makit/tasks/integrate.rb +15 -0
- data/lib/makit/tasks/pull_incoming.rb +12 -0
- data/lib/makit/tasks/setup.rb +6 -0
- data/lib/makit/tasks/sync.rb +11 -0
- data/lib/makit/tasks/task_monkey_patch.rb +79 -0
- data/lib/makit/tasks.rb +5 -150
- data/lib/makit/test_cache.rb +239 -0
- data/lib/makit/v1/makit.v1_pb.rb +34 -35
- data/lib/makit/v1/makit.v1_services_pb.rb +2 -0
- data/lib/makit/version.rb +1 -57
- data/lib/makit/wix.rb +23 -23
- data/lib/makit/yaml.rb +18 -6
- data/lib/makit.rb +2 -261
- metadata +109 -145
- data/lib/makit/cli/clean.rb +0 -14
- data/lib/makit/cli/clone.rb +0 -59
- data/lib/makit/cli/init.rb +0 -38
- data/lib/makit/cli/make.rb +0 -54
- data/lib/makit/cli/new.rb +0 -37
- data/lib/makit/cli/nuget_cache.rb +0 -38
- data/lib/makit/cli/pull.rb +0 -31
- data/lib/makit/cli/setup.rb +0 -71
- data/lib/makit/cli/work.rb +0 -21
- data/lib/makit/content/default_gitignore.txt +0 -222
data/lib/makit/rake.rb
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
module Makit
|
5
5
|
# This class provide methods for working with the system Environment.
|
6
6
|
#
|
7
|
-
class
|
7
|
+
class RakeHelper
|
8
8
|
def self.rake_repository(url, task_name)
|
9
9
|
local_path = File.join(Makit::Directories::HOME, "code", "work", Makit::Directories.get_relative_directory(url))
|
10
|
-
if
|
10
|
+
if Dir.exist?(local_path)
|
11
11
|
Dir.chdir(local_path) do
|
12
|
-
puts "
|
12
|
+
puts " #{local_path.to_s.colorize(:grey)}"
|
13
13
|
"git pull".run
|
14
14
|
end
|
15
15
|
else
|
@@ -17,9 +17,9 @@ module Makit
|
|
17
17
|
`git clone #{url} #{local_path}`
|
18
18
|
end
|
19
19
|
Dir.chdir(local_path) do
|
20
|
-
puts "
|
20
|
+
puts " #{local_path.to_s.colorize(:grey)}"
|
21
21
|
"rake #{task_name}".run
|
22
22
|
end
|
23
23
|
end
|
24
|
-
end
|
25
|
-
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Makit
|
4
|
+
class Ruby
|
5
|
+
class CLI
|
6
|
+
# Get the current Ruby version using the 'ruby' CLI
|
7
|
+
def self.current_version
|
8
|
+
version_output = `ruby --version 2>/dev/null`.strip
|
9
|
+
raise "Ruby is not installed or not available in PATH" if version_output.empty?
|
10
|
+
|
11
|
+
# Extract version number from output like "ruby 3.2.0p123 (2023-01-01 revision abc123) [x86_64-darwin22]"
|
12
|
+
version_match = version_output.match(/ruby (\d+\.\d+\.\d+)/)
|
13
|
+
if version_match
|
14
|
+
version_match[1]
|
15
|
+
else
|
16
|
+
# Fallback: return the full version string if parsing fails
|
17
|
+
version_output
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get detailed Ruby version information
|
22
|
+
def self.version_info
|
23
|
+
version_output = `ruby --version 2>/dev/null`.strip
|
24
|
+
raise "Ruby is not installed or not available in PATH" if version_output.empty?
|
25
|
+
|
26
|
+
{
|
27
|
+
full_version: version_output,
|
28
|
+
version: current_version,
|
29
|
+
patch_level: extract_patch_level(version_output),
|
30
|
+
release_date: extract_release_date(version_output),
|
31
|
+
platform: extract_platform(version_output),
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# Check if Ruby is installed and available
|
36
|
+
def self.installed?
|
37
|
+
system("ruby --version > /dev/null 2>&1")
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get the Ruby executable path
|
41
|
+
def self.executable_path
|
42
|
+
`which ruby 2>/dev/null`.strip
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get Ruby configuration information
|
46
|
+
def self.config
|
47
|
+
return {} unless installed?
|
48
|
+
|
49
|
+
config_output = `ruby -e "puts RbConfig::CONFIG" 2>/dev/null`
|
50
|
+
return {} if config_output.empty?
|
51
|
+
|
52
|
+
config = {}
|
53
|
+
config_output.lines.each do |line|
|
54
|
+
key, value = line.strip.split("=", 2)
|
55
|
+
config[key] = value if key && value
|
56
|
+
end
|
57
|
+
config
|
58
|
+
end
|
59
|
+
|
60
|
+
# Get Ruby platform information
|
61
|
+
def self.platform
|
62
|
+
return nil unless installed?
|
63
|
+
|
64
|
+
`ruby -e "puts RUBY_PLATFORM" 2>/dev/null`.strip
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get Ruby engine information
|
68
|
+
def self.engine
|
69
|
+
return nil unless installed?
|
70
|
+
|
71
|
+
engine_info = `ruby -e "puts RUBY_ENGINE" 2>/dev/null`.strip
|
72
|
+
engine_version = `ruby -e "puts RUBY_ENGINE_VERSION" 2>/dev/null`.strip
|
73
|
+
|
74
|
+
{
|
75
|
+
name: engine_info,
|
76
|
+
version: engine_version,
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
# Get Ruby installation directory
|
81
|
+
def self.installation_dir
|
82
|
+
return nil unless installed?
|
83
|
+
|
84
|
+
`ruby -e "puts RbConfig::CONFIG['prefix']" 2>/dev/null`.strip
|
85
|
+
end
|
86
|
+
|
87
|
+
# Get Ruby library directories
|
88
|
+
def self.library_dirs
|
89
|
+
return [] unless installed?
|
90
|
+
|
91
|
+
lib_dirs = `ruby -e "puts RbConfig::CONFIG['libdir']" 2>/dev/null`.strip
|
92
|
+
arch_lib_dirs = `ruby -e "puts RbConfig::CONFIG['archdir']" 2>/dev/null`.strip
|
93
|
+
|
94
|
+
[lib_dirs, arch_lib_dirs].compact.uniq
|
95
|
+
end
|
96
|
+
|
97
|
+
# Get Ruby gem directories
|
98
|
+
def self.gem_dirs
|
99
|
+
return [] unless installed?
|
100
|
+
|
101
|
+
gem_dirs_output = `ruby -e "puts Gem.path" 2>/dev/null`
|
102
|
+
return [] if gem_dirs_output.empty?
|
103
|
+
|
104
|
+
gem_dirs_output.strip.split("\n")
|
105
|
+
end
|
106
|
+
|
107
|
+
# Get Ruby load path
|
108
|
+
def self.load_path
|
109
|
+
return [] unless installed?
|
110
|
+
|
111
|
+
load_path_output = `ruby -e "puts $LOAD_PATH" 2>/dev/null`
|
112
|
+
return [] if load_path_output.empty?
|
113
|
+
|
114
|
+
load_path_output.strip.split("\n")
|
115
|
+
end
|
116
|
+
|
117
|
+
# Check if a specific Ruby version is available
|
118
|
+
def self.version_available?(version)
|
119
|
+
return false unless installed?
|
120
|
+
|
121
|
+
current = current_version
|
122
|
+
case version
|
123
|
+
when /^(\d+)\.(\d+)\.(\d+)$/
|
124
|
+
major = ::Regexp.last_match(1).to_i
|
125
|
+
minor = ::Regexp.last_match(2).to_i
|
126
|
+
patch = ::Regexp.last_match(3).to_i
|
127
|
+
current_major, current_minor, current_patch = current.split(".").map(&:to_i)
|
128
|
+
|
129
|
+
if major != current_major
|
130
|
+
major == current_major
|
131
|
+
elsif minor != current_minor
|
132
|
+
minor == current_minor
|
133
|
+
else
|
134
|
+
patch == current_patch
|
135
|
+
end
|
136
|
+
when /^(\d+)\.(\d+)$/
|
137
|
+
major = ::Regexp.last_match(1).to_i
|
138
|
+
minor = ::Regexp.last_match(2).to_i
|
139
|
+
current_major, current_minor = current.split(".").map(&:to_i)
|
140
|
+
major == current_major && minor == current_minor
|
141
|
+
when /^(\d+)$/
|
142
|
+
major = ::Regexp.last_match(1).to_i
|
143
|
+
current_major = current.split(".").first.to_i
|
144
|
+
major == current_major
|
145
|
+
else
|
146
|
+
false
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# Get Ruby environment summary
|
151
|
+
def self.environment_summary
|
152
|
+
return { error: "Ruby is not installed" } unless installed?
|
153
|
+
|
154
|
+
{
|
155
|
+
version: current_version,
|
156
|
+
full_version: version_info[:full_version],
|
157
|
+
platform: platform,
|
158
|
+
engine: engine,
|
159
|
+
executable_path: executable_path,
|
160
|
+
installation_dir: installation_dir,
|
161
|
+
gem_dirs: gem_dirs,
|
162
|
+
library_dirs: library_dirs,
|
163
|
+
}
|
164
|
+
end
|
165
|
+
|
166
|
+
# Extract patch level from version string
|
167
|
+
def self.extract_patch_level(version_string)
|
168
|
+
match = version_string.match(/p(\d+)/)
|
169
|
+
match ? match[1] : nil
|
170
|
+
end
|
171
|
+
|
172
|
+
# Extract release date from version string
|
173
|
+
def self.extract_release_date(version_string)
|
174
|
+
match = version_string.match(/\((\d{4}-\d{2}-\d{2})/)
|
175
|
+
match ? match[1] : nil
|
176
|
+
end
|
177
|
+
|
178
|
+
# Extract platform from version string
|
179
|
+
def self.extract_platform(version_string)
|
180
|
+
match = version_string.match(/\[([^\]]+)\]/)
|
181
|
+
match ? match[1] : nil
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
data/lib/makit/ruby.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "ruby/cli"
|
4
|
+
|
5
|
+
module Makit
|
6
|
+
class Ruby
|
7
|
+
# Main Ruby module for Makit
|
8
|
+
# Provides Ruby-related functionality and utilities
|
9
|
+
|
10
|
+
# Get current Ruby version (convenience method)
|
11
|
+
def self.version
|
12
|
+
CLI.current_version
|
13
|
+
end
|
14
|
+
|
15
|
+
# Check if Ruby is installed (convenience method)
|
16
|
+
def self.installed?
|
17
|
+
CLI.installed?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get Ruby environment information (convenience method)
|
21
|
+
def self.info
|
22
|
+
CLI.environment_summary
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/makit/secrets.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Makit
|
2
4
|
class Secrets
|
3
5
|
def add(key, value)
|
4
|
-
secrets_hash = get_secrets_hash
|
6
|
+
secrets_hash = get_secrets_hash
|
5
7
|
secrets_hash[key] = value
|
6
8
|
save_secrets_hash(secrets_hash)
|
7
9
|
end
|
8
10
|
|
9
11
|
def remove(key)
|
10
|
-
secrets_hash = get_secrets_hash
|
12
|
+
secrets_hash = get_secrets_hash
|
11
13
|
secrets_hash.delete(key)
|
12
14
|
save_secrets_hash(secrets_hash)
|
13
15
|
end
|
14
16
|
|
15
17
|
def has_key?(key)
|
16
|
-
secrets_hash = get_secrets_hash
|
17
|
-
|
18
|
+
secrets_hash = get_secrets_hash
|
19
|
+
secrets_hash.key?(key)
|
18
20
|
end
|
19
21
|
|
20
22
|
def get(key)
|
21
|
-
secrets_hash = get_secrets_hash
|
22
|
-
|
23
|
+
secrets_hash = get_secrets_hash
|
24
|
+
secrets_hash[key]
|
23
25
|
end
|
24
26
|
|
25
27
|
def set(key, value)
|
26
|
-
secrets_hash = get_secrets_hash
|
28
|
+
secrets_hash = get_secrets_hash
|
27
29
|
secrets_hash[key] = value
|
28
30
|
save_secrets_hash(secrets_hash)
|
29
31
|
end
|
30
32
|
|
31
|
-
def get_secrets_filename
|
32
|
-
|
33
|
+
def get_secrets_filename
|
34
|
+
"#{Makit::Directories::ROOT}/secrets.json"
|
33
35
|
end
|
34
36
|
|
35
|
-
def get_secrets_hash
|
36
|
-
secrets_file = get_secrets_filename
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
return {}
|
42
|
-
end
|
37
|
+
def get_secrets_hash
|
38
|
+
secrets_file = get_secrets_filename
|
39
|
+
return {} unless File.exist?(secrets_file)
|
40
|
+
|
41
|
+
text = File.read(secrets_file)
|
42
|
+
JSON.parse(text)
|
43
43
|
end
|
44
44
|
|
45
45
|
def save_secrets_hash(hash)
|
46
|
-
secrets_file = get_secrets_filename
|
46
|
+
secrets_file = get_secrets_filename
|
47
47
|
# pretty print the hash
|
48
48
|
File.open(secrets_file, "w") { |f| f.puts JSON.pretty_generate(hash) }
|
49
49
|
end
|
data/lib/makit/serializer.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "google/protobuf"
|
3
4
|
# This module provides classes for the Makit gem.
|
4
5
|
module Makit
|
5
6
|
module Proto3Formats
|
6
|
-
JSON = 0,
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
JSON = [0,
|
8
|
+
PRETTY_JSON = 1,
|
9
|
+
YAML = 2,
|
10
|
+
BINARY = 3].freeze
|
10
11
|
end
|
11
12
|
|
12
13
|
# This class provide methods for serializing and deserializing objects.
|
@@ -22,11 +23,9 @@ module Makit
|
|
22
23
|
when ".yml"
|
23
24
|
File.write(filename, Makit::Serializer.new(Makit::Proto3Formats::YAML).serialize(object))
|
24
25
|
when ".pb"
|
25
|
-
File.
|
26
|
-
file.write(Makit::Serializer.new(Makit::Proto3Formats::BINARY).serialize(object))
|
27
|
-
end
|
26
|
+
File.binwrite(filename, Makit::Serializer.new(Makit::Proto3Formats::BINARY).serialize(object))
|
28
27
|
|
29
|
-
#File.write(filename, Makit::Serializer.new(Makit::Proto3Formats::BINARY).serialize(object))
|
28
|
+
# File.write(filename, Makit::Serializer.new(Makit::Proto3Formats::BINARY).serialize(object))
|
30
29
|
else
|
31
30
|
raise "unsupported file extension: #{extension}"
|
32
31
|
end
|
@@ -40,7 +39,7 @@ module Makit
|
|
40
39
|
when ".yml"
|
41
40
|
Makit::Serializer.new(Makit::Proto3Formats::YAML).deserialize(type, File.read(filename))
|
42
41
|
when ".pb"
|
43
|
-
data = File.
|
42
|
+
data = File.binread(filename)
|
44
43
|
Makit::Serializer.new(Makit::Proto3Formats::BINARY).deserialize(type, data)
|
45
44
|
else
|
46
45
|
raise "unsupported file extension: #{extension}"
|
@@ -56,24 +55,23 @@ module Makit
|
|
56
55
|
# Serialize an object to a byte[] or a string
|
57
56
|
def serialize(object)
|
58
57
|
raise "Object is nil" if object.nil?
|
59
|
-
raise "object is not of type ::Google::Protobuf::MessageExts"
|
58
|
+
raise "object is not of type ::Google::Protobuf::MessageExts" unless object.is_a? ::Google::Protobuf::MessageExts
|
60
59
|
|
61
60
|
case @format_maps[::Google::Protobuf::MessageExts]
|
62
61
|
when Proto3Formats::JSON
|
63
|
-
#puts "Serializing to protobuf json format"
|
62
|
+
# puts "Serializing to protobuf json format"
|
64
63
|
object.to_json
|
65
64
|
when Proto3Formats::PRETTY_JSON
|
66
|
-
#puts "Serializing to protobuf pretty json format"
|
65
|
+
# puts "Serializing to protobuf pretty json format"
|
67
66
|
json = object.to_json
|
68
|
-
|
69
|
-
pretty_json
|
67
|
+
JSON.pretty_generate(JSON.parse(json))
|
70
68
|
when Proto3Formats::YAML
|
71
|
-
#puts "Serializing to protobuf yaml format"
|
69
|
+
# puts "Serializing to protobuf yaml format"
|
72
70
|
data = JSON.parse(object.to_json)
|
73
71
|
data.to_yaml.sub(/^---\n/, "")
|
74
72
|
when Proto3Formats::BINARY
|
75
|
-
#puts "Serializing to protobuf binary format"
|
76
|
-
|
73
|
+
# puts "Serializing to protobuf binary format"
|
74
|
+
object.to_proto
|
77
75
|
else
|
78
76
|
raise "Unknown serialization format"
|
79
77
|
end
|
@@ -82,34 +80,38 @@ module Makit
|
|
82
80
|
# Deserialize a byte[] or a string to an object
|
83
81
|
def deserialize(type, data)
|
84
82
|
raise "data is nil" if data.nil?
|
83
|
+
|
85
84
|
case @format_maps[::Google::Protobuf::MessageExts]
|
86
85
|
when Proto3Formats::JSON
|
87
|
-
raise "data is not of type string"
|
86
|
+
raise "data is not of type string" unless data.is_a? String
|
87
|
+
|
88
88
|
json = data
|
89
|
-
#puts "Deserializing from protobuf json format into type #{type}"
|
89
|
+
# puts "Deserializing from protobuf json format into type #{type}"
|
90
90
|
# use the from_json method to deserialize the object
|
91
91
|
type.decode_json(json)
|
92
92
|
when Proto3Formats::PRETTY_JSON
|
93
|
-
raise "data is not of type string"
|
93
|
+
raise "data is not of type string" unless data.is_a? String
|
94
|
+
|
94
95
|
json = data
|
95
|
-
#puts "Deserializing from protobuf pretty json format into type #{type}"
|
96
|
+
# puts "Deserializing from protobuf pretty json format into type #{type}"
|
96
97
|
# use the from_json method to deserialize the object
|
97
98
|
type.decode_json(json)
|
98
99
|
when Proto3Formats::YAML
|
99
|
-
raise "data is not of type string"
|
100
|
+
raise "data is not of type string" unless data.is_a? String
|
101
|
+
|
100
102
|
yaml = data
|
101
103
|
# convert yaml to json
|
102
104
|
json = JSON.pretty_generate(YAML.safe_load(yaml))
|
103
|
-
#puts "Deserializing from protobuf yaml format into type #{type}"
|
105
|
+
# puts "Deserializing from protobuf yaml format into type #{type}"
|
104
106
|
type.decode_json(json)
|
105
107
|
when Proto3Formats::BINARY
|
106
|
-
#raise "data is not of type byte[]" if !data.is_a? Array
|
108
|
+
# raise "data is not of type byte[]" if !data.is_a? Array
|
107
109
|
bytes = data
|
108
|
-
#puts "Deserializing from protobuf binary format into type #{type}"
|
110
|
+
# puts "Deserializing from protobuf binary format into type #{type}"
|
109
111
|
type.decode(bytes)
|
110
112
|
else
|
111
113
|
raise "Unknown serialization format"
|
112
114
|
end
|
113
115
|
end
|
114
|
-
end
|
115
|
-
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "validator"
|
4
|
+
require_relative "repository_manager"
|
5
|
+
|
6
|
+
module Makit
|
7
|
+
module Services
|
8
|
+
# Service class responsible for build operations and make processes
|
9
|
+
# Handles the complex build workflow including repository setup and execution
|
10
|
+
class Builder
|
11
|
+
class << self
|
12
|
+
# Build a repository at a specific commit
|
13
|
+
#
|
14
|
+
# @param url [String] the git repository URL
|
15
|
+
# @param commit [String] the commit hash or "latest" for the most recent commit
|
16
|
+
# @param force [Boolean] whether to force rebuild even if cached result exists
|
17
|
+
# @return [Makit::V1::MakeResult] the build result with all command outputs
|
18
|
+
def make_repository(url, commit, force: false)
|
19
|
+
Validator.validate_url_parameter(url)
|
20
|
+
Validator.validate_commit_parameter(commit)
|
21
|
+
|
22
|
+
log_filename = get_log_filename(url, commit)
|
23
|
+
|
24
|
+
return load_existing_result(log_filename) if should_load_existing_result?(log_filename, force, commit)
|
25
|
+
|
26
|
+
execute_make_process(url, commit, log_filename)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Ensure .gitignore exists in the current directory
|
30
|
+
def ensure_gitignore
|
31
|
+
return if File.exist?(".gitignore")
|
32
|
+
|
33
|
+
Makit::LOGGER.info("added .gitignore file")
|
34
|
+
File.open(".gitignore", "w") do |file|
|
35
|
+
file.puts Makit::Content::GITIGNORE
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Get the log filename for storing build results
|
42
|
+
def get_log_filename(url, commit)
|
43
|
+
File.join(
|
44
|
+
Directories.get_log_directory(url),
|
45
|
+
commit,
|
46
|
+
"#{Makit::RUNTIME_IDENTIFIER}.#{Makit::DEVICE}.json"
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Check if we should load an existing cached result
|
51
|
+
def should_load_existing_result?(log_filename, force, commit)
|
52
|
+
File.exist?(log_filename) && !force && commit != Validator::COMMIT_LATEST
|
53
|
+
end
|
54
|
+
|
55
|
+
# Load existing build result from cache
|
56
|
+
def load_existing_result(log_filename)
|
57
|
+
Makit::V1::MakeResult.decode_json(File.read(log_filename))
|
58
|
+
rescue StandardError
|
59
|
+
FileUtils.rm(log_filename)
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
# Execute the complete make process
|
64
|
+
def execute_make_process(url, commit, log_filename)
|
65
|
+
commands = []
|
66
|
+
begin
|
67
|
+
commands = setup_repository_for_build(url, commit, log_filename)
|
68
|
+
make_result = build_make_result(url, commit, commands)
|
69
|
+
save_make_result(make_result, log_filename)
|
70
|
+
make_result
|
71
|
+
rescue StandardError => e
|
72
|
+
handle_make_error(e, url, commit, commands)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Set up repository for build process
|
77
|
+
def setup_repository_for_build(url, commit, log_filename)
|
78
|
+
commands = initialize_repository_commands(url)
|
79
|
+
|
80
|
+
clone_dir = RepositoryManager.validate_clone_directory(url)
|
81
|
+
resolved_commit = resolve_commit_reference(commit, clone_dir, commands, log_filename, url)
|
82
|
+
prepare_make_directory(url, resolved_commit, clone_dir, commands)
|
83
|
+
|
84
|
+
commands
|
85
|
+
end
|
86
|
+
|
87
|
+
# Initialize repository commands (clone or pull)
|
88
|
+
def initialize_repository_commands(url)
|
89
|
+
RepositoryManager.clone_or_pull_repository(url).flatten
|
90
|
+
end
|
91
|
+
|
92
|
+
# Resolve commit reference (handle "latest" commit)
|
93
|
+
def resolve_commit_reference(commit, clone_dir, commands, log_filename, url)
|
94
|
+
return commit unless commit == Validator::COMMIT_LATEST
|
95
|
+
|
96
|
+
latest_commit = RepositoryManager.get_latest_commit(clone_dir, commands)
|
97
|
+
# Update log filename with resolved commit hash
|
98
|
+
log_filename.replace(
|
99
|
+
File.join(
|
100
|
+
Directories.get_log_directory(url),
|
101
|
+
latest_commit,
|
102
|
+
"#{Makit::RUNTIME_IDENTIFIER}.#{Makit::DEVICE}.json"
|
103
|
+
)
|
104
|
+
)
|
105
|
+
latest_commit
|
106
|
+
end
|
107
|
+
|
108
|
+
# Prepare make directory with repository clone
|
109
|
+
def prepare_make_directory(url, commit, clone_dir, commands)
|
110
|
+
make_dir = Directories.get_make_commit_directory(url, commit)
|
111
|
+
FileUtils.rm_rf(make_dir)
|
112
|
+
|
113
|
+
clone_command = Makit::RUNNER.execute("git clone #{clone_dir} #{make_dir}")
|
114
|
+
commands << clone_command
|
115
|
+
|
116
|
+
return if Dir.exist?(make_dir)
|
117
|
+
|
118
|
+
raise Makit::CloneError, "failed to clone repository: #{url} to #{make_dir}"
|
119
|
+
end
|
120
|
+
|
121
|
+
# Build the make result by executing all build steps
|
122
|
+
def build_make_result(url, commit, commands)
|
123
|
+
Dir.chdir(Directories.get_make_commit_directory(url, commit)) do
|
124
|
+
execute_git_commands(commit, commands)
|
125
|
+
execute_build_commands(commands)
|
126
|
+
|
127
|
+
make_result = create_make_result_object(url, commit)
|
128
|
+
commands.flatten.each { |command| make_result.commands << command }
|
129
|
+
make_result
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Execute git-specific commands for the build
|
134
|
+
def execute_git_commands(commit, commands)
|
135
|
+
commands << Makit::RUNNER.execute("git reset --hard #{commit}")
|
136
|
+
commands << Makit::RUNNER.execute("git log -n 1")
|
137
|
+
end
|
138
|
+
|
139
|
+
# Execute build commands (bundle, rake, etc.)
|
140
|
+
def execute_build_commands(commands)
|
141
|
+
commands << Makit::RUNNER.execute("bundle install") if File.exist?("Gemfile")
|
142
|
+
|
143
|
+
return unless File.exist?("Rakefile") || File.exist?("rakefile.rb")
|
144
|
+
|
145
|
+
commands << Makit::RUNNER.execute("rake default")
|
146
|
+
end
|
147
|
+
|
148
|
+
# Create the make result object
|
149
|
+
def create_make_result_object(url, commit)
|
150
|
+
Makit::V1::MakeResult.new(
|
151
|
+
repository: url,
|
152
|
+
commit: commit,
|
153
|
+
branch: "?",
|
154
|
+
tag: "?",
|
155
|
+
device: Makit::DEVICE,
|
156
|
+
runtime_identifier: Makit::RUNTIME_IDENTIFIER,
|
157
|
+
)
|
158
|
+
end
|
159
|
+
|
160
|
+
# Save make result to file
|
161
|
+
def save_make_result(make_result, log_filename)
|
162
|
+
FileUtils.mkdir_p(File.dirname(log_filename))
|
163
|
+
File.write(log_filename, make_result.to_json)
|
164
|
+
end
|
165
|
+
|
166
|
+
# Handle make process errors
|
167
|
+
def handle_make_error(error, url, commit, commands)
|
168
|
+
message_parts = [
|
169
|
+
"error raised attempting to make repository: #{url} commit: #{commit}",
|
170
|
+
"",
|
171
|
+
error.message,
|
172
|
+
error.backtrace.join("\\n"),
|
173
|
+
"",
|
174
|
+
"commands:",
|
175
|
+
]
|
176
|
+
|
177
|
+
commands.flatten.each do |command|
|
178
|
+
message_parts << Makit::Humanize.get_command_details(command)
|
179
|
+
end
|
180
|
+
|
181
|
+
raise Makit::BuildError, message_parts.join("\\n")
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|