makit 0.0.5 → 0.0.6
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/makit/apache.rb +32 -32
- data/lib/makit/cli/clean.rb +14 -14
- data/lib/makit/cli/clone.rb +59 -59
- data/lib/makit/cli/init.rb +38 -38
- data/lib/makit/cli/main.rb +33 -33
- data/lib/makit/cli/make.rb +54 -54
- data/lib/makit/cli/new.rb +37 -37
- data/lib/makit/cli/nuget_cache.rb +38 -38
- data/lib/makit/cli/pull.rb +31 -31
- data/lib/makit/cli/setup.rb +71 -71
- data/lib/makit/cli/work.rb +21 -21
- data/lib/makit/command_runner.rb +321 -318
- data/lib/makit/commands.rb +21 -21
- data/lib/makit/content/default_gitignore.rb +5 -5
- data/lib/makit/content/default_rakefile.rb +11 -11
- data/lib/makit/content/gem_rakefile.rb +14 -14
- data/lib/makit/data.rb +50 -50
- data/lib/makit/directories.rb +140 -140
- data/lib/makit/directory.rb +153 -153
- data/lib/makit/dotnet.rb +83 -83
- data/lib/makit/environment.rb +123 -123
- data/lib/makit/files.rb +47 -47
- data/lib/makit/git.rb +66 -66
- data/lib/makit/gitlab_runner.rb +60 -60
- data/lib/makit/humanize.rb +89 -89
- data/lib/makit/logging.rb +96 -96
- data/lib/makit/markdown.rb +75 -75
- data/lib/makit/mp/basic_object_mp.rb +16 -16
- data/lib/makit/mp/project_mp.rb +160 -156
- data/lib/makit/mp/string_mp.rb +107 -107
- data/lib/makit/nuget.rb +57 -57
- data/lib/makit/protoc.rb +61 -61
- data/lib/makit/serializer.rb +115 -115
- data/lib/makit/storage.rb +131 -131
- data/lib/makit/symbols.rb +149 -149
- data/lib/makit/tasks.rb +67 -67
- data/lib/makit/tree.rb +37 -37
- data/lib/makit/v1/makit.v1_pb.rb +4 -3
- data/lib/makit/v1/makit.v1_services_pb.rb +25 -25
- data/lib/makit/version.rb +12 -12
- data/lib/makit/wix.rb +95 -95
- data/lib/makit/zip.rb +17 -17
- data/lib/makit.rb +243 -243
- metadata +3 -3
data/lib/makit/command_runner.rb
CHANGED
@@ -1,318 +1,321 @@
|
|
1
|
-
require "English"
|
2
|
-
require "open3"
|
3
|
-
require "socket"
|
4
|
-
require "etc"
|
5
|
-
require "logger"
|
6
|
-
|
7
|
-
# This module provides classes for the Makit gem.
|
8
|
-
module Makit
|
9
|
-
# This class provide methods running commands.
|
10
|
-
#
|
11
|
-
class CommandRunner
|
12
|
-
attr_accessor :show_output_on_success, :log_to_artifacts, :commands
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@show_output_on_success = false
|
16
|
-
@log_to_artifacts = true
|
17
|
-
@commands = []
|
18
|
-
end
|
19
|
-
|
20
|
-
def get_cache_filename(command)
|
21
|
-
# test if the command_request is a Makit::V1::CommandRequest
|
22
|
-
#if command_request.is_a? Makit::V1::CommandRequest || command_request.is_a? Makit::V1::Command
|
23
|
-
# also replacing any path delimiters with an underscore
|
24
|
-
int_hash = Digest::SHA256.hexdigest("{command.name}.#{command.arguments.join(" ")}")
|
25
|
-
|
26
|
-
#int_hash = command_request.to_hash
|
27
|
-
hash_string = "#{int_hash}"[0, 8]
|
28
|
-
cache_filename = Makit::Directories::PROJECT_ARTIFACTS +
|
29
|
-
"/commands/cache/#{hash_string}.pb"
|
30
|
-
|
31
|
-
FileUtils.mkdir_p(File.dirname(cache_filename))
|
32
|
-
cache_filename
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
command
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
puts "
|
80
|
-
puts
|
81
|
-
puts
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
#
|
96
|
-
#
|
97
|
-
|
98
|
-
#
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
Makit::LOGGER.info(
|
122
|
-
|
123
|
-
command
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
if source.is_a?
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
hash
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
command_request
|
192
|
-
|
193
|
-
command_request.
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
result.
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
result
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
message_parts
|
242
|
-
message_parts << "
|
243
|
-
message_parts << "
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
symbol = Makit::Symbols.
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
file.puts
|
298
|
-
file.puts
|
299
|
-
file.puts
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
end
|
1
|
+
require "English"
|
2
|
+
require "open3"
|
3
|
+
require "socket"
|
4
|
+
require "etc"
|
5
|
+
require "logger"
|
6
|
+
|
7
|
+
# This module provides classes for the Makit gem.
|
8
|
+
module Makit
|
9
|
+
# This class provide methods running commands.
|
10
|
+
#
|
11
|
+
class CommandRunner
|
12
|
+
attr_accessor :show_output_on_success, :log_to_artifacts, :commands
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@show_output_on_success = false
|
16
|
+
@log_to_artifacts = true
|
17
|
+
@commands = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_cache_filename(command)
|
21
|
+
# test if the command_request is a Makit::V1::CommandRequest
|
22
|
+
#if command_request.is_a? Makit::V1::CommandRequest || command_request.is_a? Makit::V1::Command
|
23
|
+
# also replacing any path delimiters with an underscore
|
24
|
+
int_hash = Digest::SHA256.hexdigest("{command.name}.#{command.arguments.join(" ")}")
|
25
|
+
# int_hash
|
26
|
+
#int_hash = command_request.to_hash
|
27
|
+
hash_string = "#{int_hash}"[0, 8]
|
28
|
+
cache_filename = Makit::Directories::PROJECT_ARTIFACTS +
|
29
|
+
"/commands/cache/#{hash_string}.pb"
|
30
|
+
# create the directory if it does not already exist
|
31
|
+
FileUtils.mkdir_p(File.dirname(cache_filename))
|
32
|
+
cache_filename
|
33
|
+
end
|
34
|
+
|
35
|
+
# if there is a matching cached command result, that then the specified timestamp,
|
36
|
+
# then return the cached result
|
37
|
+
# otherwise run the command and save the result to a cache file
|
38
|
+
# then return the result
|
39
|
+
def cache_run(command_request, timestamp)
|
40
|
+
# combine the command name and arguments into a single string
|
41
|
+
# and use it to create a cache filename, making sure it is a valid filename,
|
42
|
+
# by replacing all characters that are not valid in a filename with an underscore
|
43
|
+
# also replacing any path delimiters with an underscore
|
44
|
+
int_hash = command_request.to_hash
|
45
|
+
hash_string = "#{int_hash}"[0, 8]
|
46
|
+
cache_filename = Makit::Directories::PROJECT_ARTIFACTS +
|
47
|
+
"/commands/#{hash_string}.pb"
|
48
|
+
#puts "cache_filename: #{cache_filename}"
|
49
|
+
|
50
|
+
#cache_filename = Makit::Directories::PROJECT_ARTIFACTS + "/commands/#{command_request.name}.#{command_request.arguments.join("_")}.#{timestamp.seconds}.pb"
|
51
|
+
if File.exist?(cache_filename)
|
52
|
+
#puts "cache file date: #{File.mtime(cache_filename)}"
|
53
|
+
if (File.mtime(cache_filename) > timestamp)
|
54
|
+
#puts "cache_filename exists and is newer than #{timestamp}"
|
55
|
+
return Makit::Serializer.open(cache_filename, Makit::V1::Command)
|
56
|
+
else
|
57
|
+
#puts "cache_filename exists, but is older than #{timestamp}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
command = run(command_request)
|
62
|
+
# make sure the cache directory exists
|
63
|
+
FileUtils.mkdir_p(File.dirname(cache_filename))
|
64
|
+
#puts "saving command to cache_filename"
|
65
|
+
Makit::Serializer.save_as(cache_filename, command)
|
66
|
+
commands.push(command)
|
67
|
+
command
|
68
|
+
end
|
69
|
+
|
70
|
+
# Run a command and return a Makit::V1::Command.
|
71
|
+
def run(command_request)
|
72
|
+
raise "Invalid command_request" unless command_request.is_a? Makit::V1::CommandRequest
|
73
|
+
command = execute(command_request)
|
74
|
+
show_output = true
|
75
|
+
exit_on_error = true
|
76
|
+
|
77
|
+
log_to_artifacts(command) if @log_to_artifacts
|
78
|
+
if command.exit_code != 0
|
79
|
+
puts Makit::CommandRunner.get_command_summary(command) + " (exit code #{command.exit_code})".colorize(:default)
|
80
|
+
puts " directory: #{command.directory}\n"
|
81
|
+
puts " duration: #{command.duration.seconds} seconds\n"
|
82
|
+
puts Makit::Humanize::indent_string(command.output, 2) if command.output.length > 0
|
83
|
+
puts Makit::Humanize::indent_string(command.error, 2) if command.error.length > 0
|
84
|
+
exit 1 if command_request.exit_on_error
|
85
|
+
else
|
86
|
+
puts Makit::CommandRunner.get_command_summary(command) + " (#{command.duration.seconds} seconds)".colorize(:cyan)
|
87
|
+
puts Makit::Humanize::indent_string(command.output, 2).colorize(:default) if show_output_on_success
|
88
|
+
end
|
89
|
+
|
90
|
+
commands.push(command)
|
91
|
+
command
|
92
|
+
end
|
93
|
+
|
94
|
+
def log_to_artifacts(command)
|
95
|
+
#dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
|
96
|
+
#FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
97
|
+
#filename_friendly_timestamp = Time.now.strftime("%Y.%m.%d_%H%M%S")
|
98
|
+
#log_filename = File.join(dir, "#{filename_friendly_timestamp}.json")
|
99
|
+
log_filename = get_cache_filename(command)
|
100
|
+
# serialize to protobuf json
|
101
|
+
json = command.to_json
|
102
|
+
pretty_json = JSON.pretty_generate(JSON.parse(json))
|
103
|
+
File.write(log_filename, pretty_json)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Run a command and return a Makit::V1::Command.
|
107
|
+
def try(args)
|
108
|
+
request = parse_command_request(args)
|
109
|
+
request.exit_on_error = false
|
110
|
+
run(request)
|
111
|
+
#run2(args, false)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Show the output of a command and return a Makit::V1::Command.
|
115
|
+
def show(args)
|
116
|
+
request = parse_args(args)
|
117
|
+
command = execute(request)
|
118
|
+
|
119
|
+
show_output = true
|
120
|
+
exit_on_error = true
|
121
|
+
Makit::LOGGER.info(Makit::CommandRunner.get_command_summary(command))
|
122
|
+
show_output = true if command.exit_code != 0
|
123
|
+
Makit::LOGGER.info(indent_string("\n#{command.output}\n#{command.error}\n".strip, 2)) if show_output
|
124
|
+
exit(command.exit_code) if exit_on_error && command.exit_code != 0 # unless process_status.success?
|
125
|
+
command
|
126
|
+
end
|
127
|
+
|
128
|
+
# Parse and return a Makit::V1::CommandRequest.
|
129
|
+
def parse_command_request(source)
|
130
|
+
return Makit::V1::CommandRequest.new(source) if source.is_a? Hash
|
131
|
+
return source if source.is_a? Makit::V1::CommandRequest
|
132
|
+
if source.is_a? String
|
133
|
+
return parse_args(source)
|
134
|
+
end
|
135
|
+
|
136
|
+
raise "Invalid source" unless source.is_a? Makit::V1::CommandRequest
|
137
|
+
end
|
138
|
+
|
139
|
+
def parse_command_request_from_hash(hash)
|
140
|
+
raise "Invalid hash" unless hash.is_a? Hash
|
141
|
+
Makit::V1::CommandRequest.new(hash)
|
142
|
+
end
|
143
|
+
|
144
|
+
def parse_command_request_from_string(source)
|
145
|
+
raise "Invalid source" unless source.is_a? String
|
146
|
+
words = source.split(" ")
|
147
|
+
hash = {
|
148
|
+
name: words.shift,
|
149
|
+
arguments: words,
|
150
|
+
exit_on_error: true,
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
# Parse the command line arguments into a Makit::V1::CommandRequest.
|
155
|
+
def parse_args(args)
|
156
|
+
#raise "No command specified" if args.empty?
|
157
|
+
if args.is_a? Makit::V1::CommandRequest
|
158
|
+
args
|
159
|
+
else
|
160
|
+
if args.is_a? String
|
161
|
+
args = args.split(" ")
|
162
|
+
if (args.length == 1)
|
163
|
+
hash = {
|
164
|
+
name: args[0],
|
165
|
+
arguments: [],
|
166
|
+
exit_on_error: true,
|
167
|
+
}
|
168
|
+
Makit::V1::CommandRequest.new(hash)
|
169
|
+
else
|
170
|
+
hash = {
|
171
|
+
name: args.shift,
|
172
|
+
arguments: args,
|
173
|
+
exit_on_error: true,
|
174
|
+
}
|
175
|
+
|
176
|
+
Makit::V1::CommandRequest.new(hash)
|
177
|
+
end
|
178
|
+
else
|
179
|
+
Makit::V1::CommandRequest.new(args)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def get_path_name(name)
|
185
|
+
# replace all characters that a not valid in a filename with an underscore
|
186
|
+
name.gsub(/[^0-9a-z]/i, "_")
|
187
|
+
end
|
188
|
+
|
189
|
+
# Given a Makit::V1::CommandRequest, execute the command and return a Makit::V1::Command.
|
190
|
+
def execute(args)
|
191
|
+
command_request = parse_args(args)
|
192
|
+
command_request.directory = Dir.pwd if command_request.directory.nil?
|
193
|
+
command_request.directory = Dir.pwd if command_request.directory.length == 0
|
194
|
+
result = Makit::V1::Command.new(name: command_request.name)
|
195
|
+
command_request.arguments.each do |arg|
|
196
|
+
result.arguments.push(arg)
|
197
|
+
end
|
198
|
+
command = "#{command_request.name} #{command_request.arguments.join(" ")}"
|
199
|
+
result.directory = command_request.directory
|
200
|
+
start = Time.now
|
201
|
+
filename_friendly_timestamp = Time.now.strftime("%Y.%m.%d_%H%M%S")
|
202
|
+
log_filename = File.join(Makit::Directories::LOG, "#{filename_friendly_timestamp}.log")
|
203
|
+
|
204
|
+
# assign a directory variable to the current working directory, if not specified,
|
205
|
+
# otherwise assign the specified directory
|
206
|
+
command_request.directory = Dir.pwd if command_request.directory.nil?
|
207
|
+
command_request.directory = Dir.pwd if command_request.directory.length == 0
|
208
|
+
raise "Invalid directory" unless Dir.exist?(command_request.directory)
|
209
|
+
|
210
|
+
result.started_at = Google::Protobuf::Timestamp.new(seconds: start.to_i, nanos: start.nsec.to_i)
|
211
|
+
############# execute the command
|
212
|
+
(output, error, exit_code) = execute_command(command, command_request.directory, command_request.timeout)
|
213
|
+
result.output = output.force_encoding("ASCII-8BIT")
|
214
|
+
result.error = error.force_encoding("ASCII-8BIT")
|
215
|
+
result.exit_code = exit_code.nil? ? 0 : exit_code
|
216
|
+
|
217
|
+
elapsed_time = Time.now - start
|
218
|
+
seconds = elapsed_time.to_i
|
219
|
+
nanos = ((elapsed_time - seconds) * 1_000_000_000).to_i
|
220
|
+
|
221
|
+
result.duration = Google::Protobuf::Duration.new(seconds: seconds, nanos: nanos)
|
222
|
+
|
223
|
+
result
|
224
|
+
end
|
225
|
+
|
226
|
+
# pure function to execute a command
|
227
|
+
# returns (stdout, stderr, exit_code) or raise an exception
|
228
|
+
def execute_command(command, directory, timeout)
|
229
|
+
original_directory = Dir.pwd
|
230
|
+
begin
|
231
|
+
output = nil
|
232
|
+
error = nil
|
233
|
+
process_status = nil
|
234
|
+
Dir.chdir(directory) do
|
235
|
+
output, error, process_status = Open3.capture3(command)
|
236
|
+
end
|
237
|
+
return [output, error, process_status.exitstatus]
|
238
|
+
rescue => e
|
239
|
+
# restore the original working directory
|
240
|
+
Dir.chdir(original_directory)
|
241
|
+
message_parts = []
|
242
|
+
message_parts << "failed to execute #{command}"
|
243
|
+
message_parts << "directory: #{directory}"
|
244
|
+
message_parts << "timeout: #{timeout}" unless timeout.nil?
|
245
|
+
message_parts << "error: #{e.message}"
|
246
|
+
message = message_parts.join("\n") + "\n"
|
247
|
+
return ["", message, 1]
|
248
|
+
#raise Makit::Error, message
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def execute_command_request(command_request)
|
253
|
+
# if the command_request is not a Makit::V1::CommandRequest, raise an error
|
254
|
+
raise "Invalid command_request" unless command_request.is_a? Makit::V1::CommandRequest
|
255
|
+
|
256
|
+
args = Array.new
|
257
|
+
command_request.arguments.each do |arg|
|
258
|
+
args.push(arg)
|
259
|
+
end
|
260
|
+
result = Makit::V1::Command.new({
|
261
|
+
name: command_request.name,
|
262
|
+
arguments: args,
|
263
|
+
started_at: Google::Protobuf::Timestamp.new({ seconds: Time.now.to_i, nanos: Time.now.nsec }),
|
264
|
+
})
|
265
|
+
|
266
|
+
begin
|
267
|
+
rescue => e
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def indent_string(input_string, indent_spaces)
|
272
|
+
indentation = " " * indent_spaces
|
273
|
+
input_string.lines.map { |line| indentation + line }.join
|
274
|
+
end
|
275
|
+
|
276
|
+
def self.get_command_summary(command)
|
277
|
+
symbol = Makit::Symbols.warning
|
278
|
+
symbol = Makit::Symbols.checkmark if !command.exit_code.nil? && command.exit_code.zero?
|
279
|
+
symbol = Makit::Symbols.error if command.exit_code != 0
|
280
|
+
summary = "#{symbol} #{command.name.colorize(:yellow)} #{command.arguments.join(" ")}"
|
281
|
+
|
282
|
+
if summary.length > 80
|
283
|
+
summary = summary.to_lines(80, command.name.length + 3)
|
284
|
+
end
|
285
|
+
|
286
|
+
summary
|
287
|
+
end
|
288
|
+
|
289
|
+
def log_rake_commands
|
290
|
+
dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
|
291
|
+
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
292
|
+
|
293
|
+
# open a text file to write to
|
294
|
+
File.open(File.join(dir, "rake.commands.txt"), "w") do |file|
|
295
|
+
#rake_commands = commands.select { |command| command.name == "rake" }
|
296
|
+
commands.each do |command|
|
297
|
+
file.puts " " + Makit::CommandRunner.get_command_summary(command).strip_color_codes
|
298
|
+
file.puts " start time: #{command.started_at}"
|
299
|
+
file.puts command.output.strip_color_codes unless command.output.strip_color_codes.strip.length == 0
|
300
|
+
file.puts command.error.strip_color_codes unless command.error.strip_color_codes.strip.length == 0
|
301
|
+
file.puts " "
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def log_slowest_commands
|
307
|
+
dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
|
308
|
+
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
309
|
+
|
310
|
+
# open a text file to write to
|
311
|
+
File.open(File.join(dir, "slow.commands.txt"), "w") do |file|
|
312
|
+
Makit::RUNNER.commands.sort_by { |command| (command.duration.seconds + (command.duration.nanos / 1_000_000_000.0)) }.reverse.first(5).each do |command|
|
313
|
+
# Convert to float representation
|
314
|
+
duration_in_float = command.duration.seconds + (command.duration.nanos / 1_000_000_000.0)
|
315
|
+
#puts " #{command.name} took #{duration_in_float} seconds"
|
316
|
+
file.puts " " + Makit::CommandRunner.get_command_summary(command).strip_color_codes + " (#{command.duration.seconds} seconds)"
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end # class CommandRunner
|
321
|
+
end # module Makit
|