raykit 0.0.540 → 0.0.542
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +25 -25
- data/bin/raykit +6 -6
- data/lib/raykit/auto_setup.rb +69 -69
- data/lib/raykit/command.rb +374 -374
- data/lib/raykit/conan/buildinfo.rb +69 -69
- data/lib/raykit/conanpackage.rb +49 -49
- data/lib/raykit/configuration.rb +53 -53
- data/lib/raykit/console.rb +310 -310
- data/lib/raykit/default_content.rb +8 -8
- data/lib/raykit/default_content.txt +219 -219
- data/lib/raykit/dir.rb +127 -127
- data/lib/raykit/dotnet.rb +174 -174
- data/lib/raykit/environment.rb +115 -115
- data/lib/raykit/filesystem.rb +34 -34
- data/lib/raykit/git/commit.rb +16 -16
- data/lib/raykit/git/directory.rb +280 -273
- data/lib/raykit/git/files.rb +46 -46
- data/lib/raykit/git/repositories.rb +89 -89
- data/lib/raykit/git/repository.rb +362 -362
- data/lib/raykit/installer.rb +17 -17
- data/lib/raykit/log.rb +80 -80
- data/lib/raykit/logevent.rb +29 -29
- data/lib/raykit/logger.rb +100 -100
- data/lib/raykit/logging.rb +57 -57
- data/lib/raykit/markdown.rb +21 -21
- data/lib/raykit/msbuild.rb +54 -54
- data/lib/raykit/nugetpackage.rb +54 -54
- data/lib/raykit/nunit.rb +13 -13
- data/lib/raykit/project.rb +343 -343
- data/lib/raykit/rake.rb +39 -39
- data/lib/raykit/runner.rb +42 -42
- data/lib/raykit/secrets.rb +38 -38
- data/lib/raykit/sourceImport.rb +76 -76
- data/lib/raykit/sourceImports.rb +43 -43
- data/lib/raykit/string.rb +18 -18
- data/lib/raykit/symbols.rb +115 -115
- data/lib/raykit/tasks.rb +91 -91
- data/lib/raykit/text.rb +32 -32
- data/lib/raykit/timer.rb +31 -31
- data/lib/raykit/version.rb +95 -95
- data/lib/raykit/vstest.rb +24 -24
- data/lib/raykit/wix.rb +61 -61
- data/lib/raykit/wt.rb +28 -28
- data/lib/raykit/zip.rb +73 -73
- data/lib/raykit.rb +140 -140
- metadata +2 -2
data/lib/raykit/git/commit.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Raykit
|
4
|
-
module Git
|
5
|
-
# Functionality to manage a git commit
|
6
|
-
class Commit
|
7
|
-
attr_accessor :url, :branch, :commit_id
|
8
|
-
|
9
|
-
def initialize(url, branch, commit_id)
|
10
|
-
@url = url
|
11
|
-
@branch = branch
|
12
|
-
@commit_id = commit_id
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raykit
|
4
|
+
module Git
|
5
|
+
# Functionality to manage a git commit
|
6
|
+
class Commit
|
7
|
+
attr_accessor :url, :branch, :commit_id
|
8
|
+
|
9
|
+
def initialize(url, branch, commit_id)
|
10
|
+
@url = url
|
11
|
+
@branch = branch
|
12
|
+
@commit_id = commit_id
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/raykit/git/directory.rb
CHANGED
@@ -1,273 +1,280 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Raykit
|
4
|
-
module Git
|
5
|
-
# Functionality to manage a local clone of a git repository
|
6
|
-
class Directory
|
7
|
-
# The directory name of the local repository clone
|
8
|
-
attr_accessor :directory
|
9
|
-
|
10
|
-
@repository
|
11
|
-
|
12
|
-
def initialize(directory)
|
13
|
-
@directory = directory
|
14
|
-
end
|
15
|
-
|
16
|
-
def outstanding_commit?
|
17
|
-
Dir.chdir(directory) do
|
18
|
-
return false if !File.exist?(".git")
|
19
|
-
if user_can_commit
|
20
|
-
return !`git status`.include?("nothing to commit,")
|
21
|
-
else
|
22
|
-
return false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def detached?
|
28
|
-
Dir.chdir(directory) do
|
29
|
-
status = `git status`.strip
|
30
|
-
if status.include?("detached")
|
31
|
-
true
|
32
|
-
else
|
33
|
-
false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def pull
|
39
|
-
Dir.chdir(directory) do
|
40
|
-
diff = `git diff`.strip
|
41
|
-
status = `git status`.strip
|
42
|
-
PROJECT.run("git pull", false) if diff.length.zero? && status.include?("nothing to commit")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def rake(task)
|
47
|
-
unless Dir.exist?(@directory)
|
48
|
-
puts "directory not found."
|
49
|
-
return 1
|
50
|
-
end
|
51
|
-
debug = false
|
52
|
-
sub_dir = "work"
|
53
|
-
sub_dir = "make" if @directory.include?("/make/")
|
54
|
-
rake_log = repository.get_dev_dir("log") + "/#{sub_dir}.rake.#{task}.json"
|
55
|
-
|
56
|
-
puts "log filename #{rake_log}" if debug
|
57
|
-
if File.exist?(rake_log) && (File.mtime(rake_log) > last_modified_time)
|
58
|
-
puts "using logged data" if debug
|
59
|
-
cmd = Raykit::Command.parse(File.read(rake_log))
|
60
|
-
cmd.summary
|
61
|
-
return
|
62
|
-
end
|
63
|
-
|
64
|
-
Dir.chdir(@directory) do
|
65
|
-
if File.exist?("rakefile.rb")
|
66
|
-
cmd = Raykit::Command.new("rake #{task}")
|
67
|
-
cmd.summary
|
68
|
-
FileUtils.mkdir_p(File.dirname(rake_log))
|
69
|
-
File.open(rake_log, "w") { |f| f.write(JSON.generate(cmd.to_hash)) }
|
70
|
-
else
|
71
|
-
puts "rakefile.rb not found"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def last_modified_time
|
77
|
-
Dir.chdir(@directory) do
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
if
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
#
|
88
|
-
#
|
89
|
-
last_modified_time
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
|
112
|
-
|
113
|
-
return
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
files
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
def
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
def
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
def
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
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
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raykit
|
4
|
+
module Git
|
5
|
+
# Functionality to manage a local clone of a git repository
|
6
|
+
class Directory
|
7
|
+
# The directory name of the local repository clone
|
8
|
+
attr_accessor :directory
|
9
|
+
|
10
|
+
@repository
|
11
|
+
|
12
|
+
def initialize(directory)
|
13
|
+
@directory = directory
|
14
|
+
end
|
15
|
+
|
16
|
+
def outstanding_commit?
|
17
|
+
Dir.chdir(directory) do
|
18
|
+
return false if !File.exist?(".git")
|
19
|
+
if user_can_commit
|
20
|
+
return !`git status`.include?("nothing to commit,")
|
21
|
+
else
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def detached?
|
28
|
+
Dir.chdir(directory) do
|
29
|
+
status = `git status`.strip
|
30
|
+
if status.include?("detached")
|
31
|
+
true
|
32
|
+
else
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def pull
|
39
|
+
Dir.chdir(directory) do
|
40
|
+
diff = `git diff`.strip
|
41
|
+
status = `git status`.strip
|
42
|
+
PROJECT.run("git pull", false) if diff.length.zero? && status.include?("nothing to commit")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def rake(task)
|
47
|
+
unless Dir.exist?(@directory)
|
48
|
+
puts "directory not found."
|
49
|
+
return 1
|
50
|
+
end
|
51
|
+
debug = false
|
52
|
+
sub_dir = "work"
|
53
|
+
sub_dir = "make" if @directory.include?("/make/")
|
54
|
+
rake_log = repository.get_dev_dir("log") + "/#{sub_dir}.rake.#{task}.json"
|
55
|
+
|
56
|
+
puts "log filename #{rake_log}" if debug
|
57
|
+
if File.exist?(rake_log) && (File.mtime(rake_log) > last_modified_time)
|
58
|
+
puts "using logged data" if debug
|
59
|
+
cmd = Raykit::Command.parse(File.read(rake_log))
|
60
|
+
cmd.summary
|
61
|
+
return
|
62
|
+
end
|
63
|
+
|
64
|
+
Dir.chdir(@directory) do
|
65
|
+
if File.exist?("rakefile.rb")
|
66
|
+
cmd = Raykit::Command.new("rake #{task}")
|
67
|
+
cmd.summary
|
68
|
+
FileUtils.mkdir_p(File.dirname(rake_log))
|
69
|
+
File.open(rake_log, "w") { |f| f.write(JSON.generate(cmd.to_hash)) }
|
70
|
+
else
|
71
|
+
puts "rakefile.rb not found"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def last_modified_time
|
77
|
+
Dir.chdir(@directory) do
|
78
|
+
|
79
|
+
begin
|
80
|
+
# Find the most recently modified file
|
81
|
+
most_recent_file = Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
|
82
|
+
|
83
|
+
# Use File.mtime if a file was found, otherwise handle the nil case
|
84
|
+
if most_recent_file
|
85
|
+
last_modified_time = File.mtime(most_recent_file)
|
86
|
+
else
|
87
|
+
# Handle the case where no files are found. This could be setting a default value,
|
88
|
+
# raising a custom error, or any other appropriate action depending on your needs.
|
89
|
+
# For example, setting last_modified_time to Time.now or raising a custom error.
|
90
|
+
last_modified_time = Time.now # Or any other appropriate action
|
91
|
+
end
|
92
|
+
rescue Errno::ENAMETOOLONG => e
|
93
|
+
puts "Error: #{e.message}"
|
94
|
+
last_modified_time = Time.now # Or any other appropriate action
|
95
|
+
end
|
96
|
+
|
97
|
+
#File.mtime(Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def last_modified_filename
|
102
|
+
Dir.chdir(@directory) do
|
103
|
+
# TODO: consider handling the case where glob can fail because of filename length
|
104
|
+
# Errno::ENAMETOOLONG: File name too long @ dir_s_glob - /Users/username/...
|
105
|
+
#
|
106
|
+
begin
|
107
|
+
# Use Dir.glob to find all files, select the actual files, find the one with the latest modification time, and return its name
|
108
|
+
files = Dir.glob("**/*.*").select { |f| File.file?(f) }
|
109
|
+
|
110
|
+
# Find the file with the latest modification time
|
111
|
+
latest_file = files.max_by { |f| File.mtime(f) }
|
112
|
+
|
113
|
+
return latest_file
|
114
|
+
|
115
|
+
#Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
|
116
|
+
rescue Errno::ENAMETOOLONG => e
|
117
|
+
puts "Error: #{e.message}"
|
118
|
+
# return the first src file found
|
119
|
+
src_files.each { |f| return f if File.file?(f) }
|
120
|
+
#return handle_long_filename_error
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# git ls-tree -r master --name-only
|
126
|
+
def src_files
|
127
|
+
files = Array.new
|
128
|
+
Dir.chdir(@directory) do
|
129
|
+
`git ls-tree -r #{branch} --name-only`.each_line { |line|
|
130
|
+
file = line.strip
|
131
|
+
files << file if file.length > 0 && File.exist?(file)
|
132
|
+
}
|
133
|
+
end
|
134
|
+
files
|
135
|
+
end
|
136
|
+
|
137
|
+
def last_modified_src_time
|
138
|
+
Dir.chdir(@directory) do
|
139
|
+
last_file = self.src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
|
140
|
+
last_file ? File.mtime(last_file) : Time.at(0) # Return a default time if no file is found
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
#def last_modified_src_time
|
145
|
+
# #File.mtim(src_files.max_by { |f| File.mtime(f) }#
|
146
|
+
# Dir.chdir(@directory) do
|
147
|
+
# File.mtime(self.src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
|
148
|
+
# end
|
149
|
+
#end
|
150
|
+
|
151
|
+
def last_modified_src_file
|
152
|
+
Dir.chdir(@directory) do
|
153
|
+
# Select the source files that are actual files, not directories
|
154
|
+
src_files.select { |f| File.file?(f) }
|
155
|
+
# Find the max by modification time
|
156
|
+
.max_by { |f| File.mtime(f) }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def last_modified_artifact_time
|
161
|
+
self.last_modified_time
|
162
|
+
end
|
163
|
+
|
164
|
+
# The latest tag for a branch of the repository
|
165
|
+
def latest_tag(_branch)
|
166
|
+
Dir.chdir(directory) do
|
167
|
+
return `git describe --abbrev=0`.strip
|
168
|
+
end
|
169
|
+
""
|
170
|
+
end
|
171
|
+
|
172
|
+
def get_tag_commit_id(name)
|
173
|
+
cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
|
174
|
+
if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
|
175
|
+
cmd.output.strip
|
176
|
+
else
|
177
|
+
""
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def has_tag(name)
|
182
|
+
cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
|
183
|
+
if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
|
184
|
+
true
|
185
|
+
else
|
186
|
+
false
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_sha(filename)
|
191
|
+
if File.exist?(filename)
|
192
|
+
Digest::SHA256.file(filename).hexdigest.to_s
|
193
|
+
else
|
194
|
+
"#{filename} not found"
|
195
|
+
end
|
196
|
+
# ''
|
197
|
+
end
|
198
|
+
|
199
|
+
def user_name
|
200
|
+
`git config --get user.name`.strip
|
201
|
+
end
|
202
|
+
|
203
|
+
def user_email
|
204
|
+
`git config --get user.email`.strip
|
205
|
+
end
|
206
|
+
|
207
|
+
def user_can_commit
|
208
|
+
return false if user_name.length.zero?
|
209
|
+
return false if user_email.length.zero?
|
210
|
+
|
211
|
+
true
|
212
|
+
end
|
213
|
+
|
214
|
+
def branch
|
215
|
+
Dir.chdir(directory) do
|
216
|
+
scan = `git branch`.scan(/\*\s([\w.-]+)/)
|
217
|
+
return scan[0][0].to_s if !scan.nil? && scan.length.positive? && scan[0].length.positive?
|
218
|
+
end
|
219
|
+
"master"
|
220
|
+
end
|
221
|
+
|
222
|
+
def repository
|
223
|
+
@repository = Raykit::Git::Repository.new(remote) if @repository.nil?
|
224
|
+
@repository
|
225
|
+
end
|
226
|
+
|
227
|
+
def remote
|
228
|
+
if Dir.exist?(directory)
|
229
|
+
Dir.chdir(directory) do
|
230
|
+
return Command.new("git config --get remote.origin.url").run.output.strip if Dir.exist?(".git")
|
231
|
+
end
|
232
|
+
end
|
233
|
+
""
|
234
|
+
end
|
235
|
+
|
236
|
+
def tag_version(version)
|
237
|
+
if has_tag "v#{version}"
|
238
|
+
puts " git tag v#{version} already exists"
|
239
|
+
else
|
240
|
+
if outstanding_commit?
|
241
|
+
raise "outstanding commit, will not tag"
|
242
|
+
else
|
243
|
+
puts " git tag v#{version} does not exist"
|
244
|
+
run("git tag -a v#{version} -m\"version #{version}\"")
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def get_unique_ruby_constants
|
250
|
+
# Define the regular expression pattern
|
251
|
+
pattern = /\b([A-Z][A-Z0-9_]*)\b\s*=/
|
252
|
+
|
253
|
+
constants = []
|
254
|
+
|
255
|
+
# Loop through each .rb file in the specified directory
|
256
|
+
Dir.glob("#{directory}/**/*.rb").each do |file|
|
257
|
+
# Read the contents of the file
|
258
|
+
content = File.read(file)
|
259
|
+
|
260
|
+
# Scan the content for constants and add the matches to the array.
|
261
|
+
content.scan(pattern) do |match|
|
262
|
+
# Add matched constant name to the constants array.
|
263
|
+
constants << match[0]
|
264
|
+
end
|
265
|
+
# Scan the content for constants and add the matches to the array
|
266
|
+
#constants.concat(content.scan(pattern))
|
267
|
+
end
|
268
|
+
|
269
|
+
# Return unique constants
|
270
|
+
constants.uniq
|
271
|
+
end
|
272
|
+
|
273
|
+
#def setup
|
274
|
+
# DEFAULT_SUBDIRECTORIES.each do |subdirectory|
|
275
|
+
# FileUtils.mkdir_p(subdirectory)
|
276
|
+
# end
|
277
|
+
#end
|
278
|
+
end # class Directory
|
279
|
+
end # module Git
|
280
|
+
end # module Raykit
|