raykit 0.0.527 → 0.0.529

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +25 -25
  4. data/bin/raykit +6 -6
  5. data/lib/raykit/auto_setup.rb +69 -69
  6. data/lib/raykit/command.rb +374 -374
  7. data/lib/raykit/conan/buildinfo.rb +69 -69
  8. data/lib/raykit/conanpackage.rb +49 -49
  9. data/lib/raykit/configuration.rb +53 -53
  10. data/lib/raykit/console.rb +310 -310
  11. data/lib/raykit/default_content.rb +227 -227
  12. data/lib/raykit/dir.rb +96 -96
  13. data/lib/raykit/dotnet.rb +174 -174
  14. data/lib/raykit/environment.rb +115 -115
  15. data/lib/raykit/filesystem.rb +34 -34
  16. data/lib/raykit/git/commit.rb +16 -16
  17. data/lib/raykit/git/directory.rb +244 -220
  18. data/lib/raykit/git/files.rb +46 -46
  19. data/lib/raykit/git/repositories.rb +89 -89
  20. data/lib/raykit/git/repository.rb +362 -362
  21. data/lib/raykit/installer.rb +17 -17
  22. data/lib/raykit/log.rb +80 -80
  23. data/lib/raykit/logevent.rb +29 -29
  24. data/lib/raykit/logger.rb +100 -100
  25. data/lib/raykit/logging.rb +57 -57
  26. data/lib/raykit/markdown.rb +21 -21
  27. data/lib/raykit/msbuild.rb +54 -54
  28. data/lib/raykit/nugetpackage.rb +54 -54
  29. data/lib/raykit/nunit.rb +13 -13
  30. data/lib/raykit/project.rb +343 -343
  31. data/lib/raykit/rake.rb +39 -39
  32. data/lib/raykit/runner.rb +42 -42
  33. data/lib/raykit/secrets.rb +38 -38
  34. data/lib/raykit/sourceImport.rb +76 -76
  35. data/lib/raykit/sourceImports.rb +43 -43
  36. data/lib/raykit/string.rb +18 -18
  37. data/lib/raykit/symbols.rb +115 -115
  38. data/lib/raykit/tasks.rb +91 -91
  39. data/lib/raykit/text.rb +32 -32
  40. data/lib/raykit/timer.rb +31 -31
  41. data/lib/raykit/version.rb +95 -95
  42. data/lib/raykit/vstest.rb +24 -24
  43. data/lib/raykit/wix.rb +61 -61
  44. data/lib/raykit/wt.rb +28 -28
  45. data/lib/raykit/zip.rb +73 -73
  46. data/lib/raykit.rb +135 -132
  47. metadata +1 -1
@@ -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
@@ -1,220 +1,244 @@
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
- File.mtime(Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
79
- end
80
- end
81
-
82
- # git ls-tree -r master --name-only
83
- def src_files
84
- files = Array.new
85
- Dir.chdir(@directory) do
86
- `git ls-tree -r #{branch} --name-only`.each_line { |line|
87
- file = line.strip
88
- files << file if file.length > 0
89
- }
90
- end
91
- files
92
- end
93
-
94
- def last_modified_src_time
95
- Dir.chdir(@directory) do
96
- File.mtime(src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
97
- end
98
- end
99
-
100
- def last_modified_artifact_time
101
- self.last_modified_time
102
- end
103
-
104
- # The latest tag for a branch of the repository
105
- def latest_tag(_branch)
106
- Dir.chdir(directory) do
107
- return `git describe --abbrev=0`.strip
108
- end
109
- ""
110
- end
111
-
112
- def get_tag_commit_id(name)
113
- cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
114
- if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
115
- cmd.output.strip
116
- else
117
- ""
118
- end
119
- end
120
-
121
- def has_tag(name)
122
- cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
123
- if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
124
- true
125
- else
126
- false
127
- end
128
- end
129
-
130
- def get_sha(filename)
131
- if File.exist?(filename)
132
- Digest::SHA256.file(filename).hexdigest.to_s
133
- else
134
- "#{filename} not found"
135
- end
136
- # ''
137
- end
138
-
139
- def user_name
140
- `git config --get user.name`.strip
141
- end
142
-
143
- def user_email
144
- `git config --get user.email`.strip
145
- end
146
-
147
- def user_can_commit
148
- return false if user_name.length.zero?
149
- return false if user_email.length.zero?
150
-
151
- true
152
- end
153
-
154
- def branch
155
- Dir.chdir(directory) do
156
- scan = `git branch`.scan(/\*\s([\w.-]+)/)
157
- return scan[0][0].to_s if !scan.nil? && scan.length.positive? && scan[0].length.positive?
158
- end
159
- "master"
160
- end
161
-
162
- def repository
163
- @repository = Raykit::Git::Repository.new(remote) if @repository.nil?
164
- @repository
165
- end
166
-
167
- def remote
168
- if Dir.exist?(directory)
169
- Dir.chdir(directory) do
170
- return Command.new("git config --get remote.origin.url").run.output.strip if Dir.exist?(".git")
171
- end
172
- end
173
- ""
174
- end
175
-
176
- def tag_version(version)
177
- if has_tag "v#{version}"
178
- puts " git tag v#{version} already exists"
179
- else
180
- if outstanding_commit?
181
- raise "outstanding commit, will not tag"
182
- else
183
- puts " git tag v#{version} does not exist"
184
- run("git tag -a v#{version} -m\"version #{version}\"")
185
- end
186
- end
187
- end
188
-
189
- def get_unique_ruby_constants
190
- # Define the regular expression pattern
191
- pattern = /\b([A-Z][A-Z0-9_]*)\b\s*=/
192
-
193
- constants = []
194
-
195
- # Loop through each .rb file in the specified directory
196
- Dir.glob("#{directory}/**/*.rb").each do |file|
197
- # Read the contents of the file
198
- content = File.read(file)
199
-
200
- # Scan the content for constants and add the matches to the array.
201
- content.scan(pattern) do |match|
202
- # Add matched constant name to the constants array.
203
- constants << match[0]
204
- end
205
- # Scan the content for constants and add the matches to the array
206
- #constants.concat(content.scan(pattern))
207
- end
208
-
209
- # Return unique constants
210
- constants.uniq
211
- end
212
-
213
- #def setup
214
- # DEFAULT_SUBDIRECTORIES.each do |subdirectory|
215
- # FileUtils.mkdir_p(subdirectory)
216
- # end
217
- #end
218
- end # class Directory
219
- end # module Git
220
- end # module Raykit
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
+ File.mtime(Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
79
+ end
80
+ end
81
+
82
+ def last_modified_filename
83
+ Dir.chdir(@directory) do
84
+ # Use Dir.glob to find all files, select the actual files, find the one with the latest modification time, and return its name
85
+ Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
86
+ end
87
+ end
88
+
89
+ # git ls-tree -r master --name-only
90
+ def src_files
91
+ files = Array.new
92
+ Dir.chdir(@directory) do
93
+ `git ls-tree -r #{branch} --name-only`.each_line { |line|
94
+ file = line.strip
95
+ files << file if file.length > 0 && File.exist?(file)
96
+ }
97
+ end
98
+ files
99
+ end
100
+
101
+ def last_modified_src_time
102
+ Dir.chdir(@directory) do
103
+ last_file = self.src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
104
+ last_file ? File.mtime(last_file) : Time.at(0) # Return a default time if no file is found
105
+ end
106
+ end
107
+
108
+ #def last_modified_src_time
109
+ # #File.mtim(src_files.max_by { |f| File.mtime(f) }#
110
+ # Dir.chdir(@directory) do
111
+ # File.mtime(self.src_files.select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
112
+ # end
113
+ #end
114
+
115
+ def last_modified_src_file
116
+ Dir.chdir(@directory) do
117
+ # Select the source files that are actual files, not directories
118
+ src_files.select { |f| File.file?(f) }
119
+ # Find the max by modification time
120
+ .max_by { |f| File.mtime(f) }
121
+ end
122
+ end
123
+
124
+ def last_modified_artifact_time
125
+ self.last_modified_time
126
+ end
127
+
128
+ # The latest tag for a branch of the repository
129
+ def latest_tag(_branch)
130
+ Dir.chdir(directory) do
131
+ return `git describe --abbrev=0`.strip
132
+ end
133
+ ""
134
+ end
135
+
136
+ def get_tag_commit_id(name)
137
+ cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
138
+ if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
139
+ cmd.output.strip
140
+ else
141
+ ""
142
+ end
143
+ end
144
+
145
+ def has_tag(name)
146
+ cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run
147
+ if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
148
+ true
149
+ else
150
+ false
151
+ end
152
+ end
153
+
154
+ def get_sha(filename)
155
+ if File.exist?(filename)
156
+ Digest::SHA256.file(filename).hexdigest.to_s
157
+ else
158
+ "#{filename} not found"
159
+ end
160
+ # ''
161
+ end
162
+
163
+ def user_name
164
+ `git config --get user.name`.strip
165
+ end
166
+
167
+ def user_email
168
+ `git config --get user.email`.strip
169
+ end
170
+
171
+ def user_can_commit
172
+ return false if user_name.length.zero?
173
+ return false if user_email.length.zero?
174
+
175
+ true
176
+ end
177
+
178
+ def branch
179
+ Dir.chdir(directory) do
180
+ scan = `git branch`.scan(/\*\s([\w.-]+)/)
181
+ return scan[0][0].to_s if !scan.nil? && scan.length.positive? && scan[0].length.positive?
182
+ end
183
+ "master"
184
+ end
185
+
186
+ def repository
187
+ @repository = Raykit::Git::Repository.new(remote) if @repository.nil?
188
+ @repository
189
+ end
190
+
191
+ def remote
192
+ if Dir.exist?(directory)
193
+ Dir.chdir(directory) do
194
+ return Command.new("git config --get remote.origin.url").run.output.strip if Dir.exist?(".git")
195
+ end
196
+ end
197
+ ""
198
+ end
199
+
200
+ def tag_version(version)
201
+ if has_tag "v#{version}"
202
+ puts " git tag v#{version} already exists"
203
+ else
204
+ if outstanding_commit?
205
+ raise "outstanding commit, will not tag"
206
+ else
207
+ puts " git tag v#{version} does not exist"
208
+ run("git tag -a v#{version} -m\"version #{version}\"")
209
+ end
210
+ end
211
+ end
212
+
213
+ def get_unique_ruby_constants
214
+ # Define the regular expression pattern
215
+ pattern = /\b([A-Z][A-Z0-9_]*)\b\s*=/
216
+
217
+ constants = []
218
+
219
+ # Loop through each .rb file in the specified directory
220
+ Dir.glob("#{directory}/**/*.rb").each do |file|
221
+ # Read the contents of the file
222
+ content = File.read(file)
223
+
224
+ # Scan the content for constants and add the matches to the array.
225
+ content.scan(pattern) do |match|
226
+ # Add matched constant name to the constants array.
227
+ constants << match[0]
228
+ end
229
+ # Scan the content for constants and add the matches to the array
230
+ #constants.concat(content.scan(pattern))
231
+ end
232
+
233
+ # Return unique constants
234
+ constants.uniq
235
+ end
236
+
237
+ #def setup
238
+ # DEFAULT_SUBDIRECTORIES.each do |subdirectory|
239
+ # FileUtils.mkdir_p(subdirectory)
240
+ # end
241
+ #end
242
+ end # class Directory
243
+ end # module Git
244
+ end # module Raykit
@@ -1,46 +1,46 @@
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 Files
7
- @url
8
- @commit_id
9
-
10
- def initialize(url, commit_id)
11
- @url = url
12
- @commit_id = commit_id
13
- end
14
-
15
- def clean
16
- FileUtils.rm_rf(commit_path) if Dir.exist?(commit_path)
17
- end
18
-
19
- def get(name)
20
- puts "commit_path(): #{commit_path}"
21
- unless Dir.exist?(commit_path)
22
- puts "cloning commit path..."
23
- clone = Raykit::Command.new("git clone #{@url} #{commit_path}")
24
- puts clone.output
25
- puts clone.error
26
- Dir.chdir(commit_path) do
27
- checkout = Raykit::Command.new("git checkout #{@commit_id}")
28
- end
29
- end
30
-
31
- return filename(name) if File.exist?(filename(name))
32
-
33
- ""
34
- end
35
-
36
- def commit_path
37
- Dir.tmpdir + File::SEPARATOR + "Raykit.Git.Files" + File::SEPARATOR + @url.gsub("://",
38
- ".") + File::SEPARATOR + @commit_id
39
- end
40
-
41
- def filename(name)
42
- commit_path + File::SEPARATOR + name
43
- end
44
- end
45
- end
46
- end
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 Files
7
+ @url
8
+ @commit_id
9
+
10
+ def initialize(url, commit_id)
11
+ @url = url
12
+ @commit_id = commit_id
13
+ end
14
+
15
+ def clean
16
+ FileUtils.rm_rf(commit_path) if Dir.exist?(commit_path)
17
+ end
18
+
19
+ def get(name)
20
+ puts "commit_path(): #{commit_path}"
21
+ unless Dir.exist?(commit_path)
22
+ puts "cloning commit path..."
23
+ clone = Raykit::Command.new("git clone #{@url} #{commit_path}")
24
+ puts clone.output
25
+ puts clone.error
26
+ Dir.chdir(commit_path) do
27
+ checkout = Raykit::Command.new("git checkout #{@commit_id}")
28
+ end
29
+ end
30
+
31
+ return filename(name) if File.exist?(filename(name))
32
+
33
+ ""
34
+ end
35
+
36
+ def commit_path
37
+ Dir.tmpdir + File::SEPARATOR + "Raykit.Git.Files" + File::SEPARATOR + @url.gsub("://",
38
+ ".") + File::SEPARATOR + @commit_id
39
+ end
40
+
41
+ def filename(name)
42
+ commit_path + File::SEPARATOR + name
43
+ end
44
+ end
45
+ end
46
+ end