makit 0.0.48 → 0.0.49
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generated/makit/v1/makit.v1_pb.rb +34 -0
- data/lib/generated/makit/v1/web/link_pb.rb +20 -0
- 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 +399 -391
- 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 +200 -200
- data/lib/makit/dotnet.rb +170 -162
- data/lib/makit/environment.rb +127 -127
- data/lib/makit/fileinfo.rb +16 -16
- data/lib/makit/files.rb +47 -47
- data/lib/makit/git.rb +87 -87
- data/lib/makit/gitlab_runner.rb +60 -60
- data/lib/makit/humanize.rb +129 -129
- data/lib/makit/indexer.rb +56 -56
- 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/command_request.mp.rb +16 -16
- data/lib/makit/mp/project_mp.rb +210 -210
- data/lib/makit/mp/string_mp.rb +137 -122
- data/lib/makit/nuget.rb +57 -57
- data/lib/makit/protoc.rb +104 -104
- data/lib/makit/serializer.rb +115 -115
- data/lib/makit/show.rb +106 -108
- data/lib/makit/storage.rb +131 -131
- data/lib/makit/symbols.rb +149 -149
- data/lib/makit/tasks.rb +61 -60
- data/lib/makit/tree.rb +37 -37
- data/lib/makit/v1/makit.v1_pb.rb +33 -34
- data/lib/makit/v1/makit.v1_services_pb.rb +25 -25
- data/lib/makit/version.rb +52 -52
- data/lib/makit/wix.rb +95 -95
- data/lib/makit/zip.rb +17 -17
- data/lib/makit.rb +267 -267
- metadata +4 -2
data/lib/makit.rb
CHANGED
@@ -1,267 +1,267 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rake/clean"
|
4
|
-
require "logger"
|
5
|
-
require "json"
|
6
|
-
require "yaml"
|
7
|
-
require "google/protobuf"
|
8
|
-
|
9
|
-
#%w[generated/makit].each do |dir|
|
10
|
-
# Dir[File.join(__dir__, dir, "*.rb")].each do |file|
|
11
|
-
# require_relative file
|
12
|
-
# end
|
13
|
-
#end
|
14
|
-
if (File.exist?("protos/makit/makit.v1.proto.rb"))
|
15
|
-
require_relative "generated/makit/makit.v1_pb"
|
16
|
-
else
|
17
|
-
require_relative "makit/v1/makit.v1_pb"
|
18
|
-
end
|
19
|
-
|
20
|
-
#%w[makit makit/v1 makit/cli makit/content makit/mp].each do |dir|
|
21
|
-
%w[makit makit/cli makit/content makit/mp].each do |dir|
|
22
|
-
Dir[File.join(__dir__, dir, "*.rb")].each do |file|
|
23
|
-
require_relative file
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
module Makit
|
28
|
-
class Error < StandardError; end
|
29
|
-
|
30
|
-
# Constants
|
31
|
-
if File.exist? ".makit.project.json"
|
32
|
-
PROJECT = Makit::Serializer.open(".makit.project.json", Makit::V1::Project)
|
33
|
-
else
|
34
|
-
if File.exist? ".makit.project.yml"
|
35
|
-
PROJECT = Makit::Serializer.open(".makit.project.yml", Makit::V1::Project)
|
36
|
-
else
|
37
|
-
PROJECT = Makit::V1::Project.new
|
38
|
-
PROJECT.set_default_values
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
STARTTIME = Time.now
|
43
|
-
SHOW = Makit::Show.new
|
44
|
-
IS_GIT_REPO = Dir.exist? ".git"
|
45
|
-
DETACHED = `git status`.include?("detached")
|
46
|
-
IS_READ_ONLY = !IS_GIT_REPO || DETACHED
|
47
|
-
RUNTIME_IDENTIFIER = Makit::Environment::get_runtime_identifier
|
48
|
-
DEVICE = Socket.gethostname
|
49
|
-
LOGGER = Makit::Logging::MultiLogger.create_logger
|
50
|
-
|
51
|
-
# Git Commit and Branch/Tag constants
|
52
|
-
ENV["COMMIT_SHA"] = Makit::Git::commitsha
|
53
|
-
ENV["COMMIT_BRANCH"] = Makit::Git::branch
|
54
|
-
|
55
|
-
RUNNER = CommandRunner.new
|
56
|
-
GIT_FILE_INFOS = Makit::Git::get_file_infos
|
57
|
-
#RUNNER.log_to_artifacts = true
|
58
|
-
# Variables
|
59
|
-
log_level = Logger::INFO
|
60
|
-
package_type = Makit::V1::PackageType::GEM
|
61
|
-
commands = Makit::Commands.new
|
62
|
-
|
63
|
-
# methods
|
64
|
-
#
|
65
|
-
# initialize a git repository
|
66
|
-
def self.init(directory)
|
67
|
-
if !Dir.exist?(directory)
|
68
|
-
FileUtils.mkdir_p(directory)
|
69
|
-
end
|
70
|
-
raise Makit::Error.new("directory does not exist: #{directory}") if !Dir.exist?(directory)
|
71
|
-
Dir.chdir(directory) do
|
72
|
-
File.write(".gitignore", Makit::Content::GITIGNORE) unless File.exist?(".gitignore")
|
73
|
-
init = Makit::RUNNER.execute "git init"
|
74
|
-
if init.exit_code != 0
|
75
|
-
raise Makit::Error.new("failed to initialize local repository: #{directory}\n#{Makit::Humanize.get_command_summary(init)}")
|
76
|
-
end
|
77
|
-
init
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# clone a git repository to a local directory in Directories::CLONE
|
82
|
-
# returns the Makit::V1::Command for 'git clone ...'
|
83
|
-
def self.clone(git_repository)
|
84
|
-
commands = []
|
85
|
-
# make sure a local clone of the repository exists
|
86
|
-
clone_dir = Directories::get_clone_directory(git_repository)
|
87
|
-
if (!Dir.exist?(clone_dir))
|
88
|
-
commands << Makit::RUNNER.execute("git clone #{git_repository} #{clone_dir}")
|
89
|
-
end
|
90
|
-
commands
|
91
|
-
end
|
92
|
-
|
93
|
-
# pull the latest changes from the remote repository to a local clone in Directories::CLONE
|
94
|
-
def self.pull(git_repository)
|
95
|
-
clone_dir = Directories::get_clone_directory(git_repository)
|
96
|
-
raise Makit::Error.new("clone directory does not exist: #{clone_dir}") if !Dir.exist?(clone_dir)
|
97
|
-
Dir.chdir(clone_dir) do
|
98
|
-
request = Makit::V1::CommandRequest.new(
|
99
|
-
name: "git",
|
100
|
-
arguments: ["pull"],
|
101
|
-
directory: clone_dir,
|
102
|
-
)
|
103
|
-
pull_command = Makit::RUNNER.execute(request)
|
104
|
-
raise Makit::Error.new(Makit::Humanize::get_command_details(pull_command)) if pull_command.exit_code != 0
|
105
|
-
return pull_command
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.clone_or_pull(git_repository)
|
110
|
-
commands = []
|
111
|
-
clone_dir = Directories::get_clone_directory(git_repository)
|
112
|
-
if Dir.exist?(clone_dir)
|
113
|
-
commands << pull(git_repository)
|
114
|
-
else
|
115
|
-
commands << clone(git_repository)
|
116
|
-
end
|
117
|
-
commands
|
118
|
-
end
|
119
|
-
|
120
|
-
# log information about a specific repository
|
121
|
-
# return an array of GitLogEntry objects
|
122
|
-
def self.log(git_repository, limit, skip)
|
123
|
-
entries = []
|
124
|
-
clone_dir = Directories::get_clone_directory(git_repository)
|
125
|
-
raise Makit::Error.new("clone directory does not exist: #{clone_dir}") if !Dir.exist?(clone_dir)
|
126
|
-
Dir.chdir(clone_dir) do
|
127
|
-
log_command = Makit::RUNNER.execute("git log -n #{limit} --skip #{skip} --date=iso")
|
128
|
-
if log_command.exit_code != 0
|
129
|
-
lines = log_command.stderr.split("\n")
|
130
|
-
# iterate over the lines, generating a GitLogEntry for each commit
|
131
|
-
lines.each do |line|
|
132
|
-
if line.start_with?("commit")
|
133
|
-
commit = line.split(" ")[1]
|
134
|
-
entries << GitLogEntry.new(commit)
|
135
|
-
end
|
136
|
-
if line.start_with?("Author:")
|
137
|
-
entries.last.author = line.split(" ")[1..-1].join(" ")
|
138
|
-
end
|
139
|
-
if line.start_with?("Date:")
|
140
|
-
entries.last.date = line.split(" ")[1..-1].join(" ")
|
141
|
-
end
|
142
|
-
if line.start_with?(" ")
|
143
|
-
entries.last.message += line[4..-1]
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
entries
|
149
|
-
end
|
150
|
-
|
151
|
-
# work on a local clone of a git repository
|
152
|
-
# if the repository does not exist, clone it
|
153
|
-
# if the repository exists, pull the latest changes
|
154
|
-
# if a build command can be found, execute it and return the result Makit::V1::WorkResult
|
155
|
-
def self.work(repository)
|
156
|
-
commands = []
|
157
|
-
work_dir = Makit::Directories::get_work_directory(repository)
|
158
|
-
commands << clone_or_pull(repository)
|
159
|
-
clone_dir = Makit::Directories::get_clone_directory(repository)
|
160
|
-
if !Dir.exist?(work_dir)
|
161
|
-
# make the parent directory for work_dir if it does not exist
|
162
|
-
FileUtils.mkdir_p(File.dirname(work_dir)) unless Dir.exist?(File.dirname(work_dir))
|
163
|
-
Makit::RUNNER::execute "git clone #{clone_dir} #{work_dir}"
|
164
|
-
end
|
165
|
-
Dir.chdir(work_dir) do
|
166
|
-
# if there is no .gitignore file, create one
|
167
|
-
File.write(".gitignore", Makit::Content::GITIGNORE) unless File.exist?(".gitignore")
|
168
|
-
end
|
169
|
-
nil?
|
170
|
-
end
|
171
|
-
|
172
|
-
def self.enable_monkey_patch
|
173
|
-
%w[makit/mp].each do |dir|
|
174
|
-
Dir[File.join(__dir__, dir, "*.rb")].each do |file|
|
175
|
-
require_relative file
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
# Given a git repository URL and a commit id, create a new MakeResult object.
|
180
|
-
def self.make(url, commit, force = false)
|
181
|
-
log_filename = File.join(Directories::get_log_directory(url), commit, +"#{RUNTIME_IDENTIFIER}.#{DEVICE}.json")
|
182
|
-
if File.exist?(log_filename) && !force && commit != "latest"
|
183
|
-
begin
|
184
|
-
# deserialize the log file to a Makite::V1::MakeResult object
|
185
|
-
make_result = Makit::V1::MakeResult.decode_json(File.read(log_filename))
|
186
|
-
return make_result
|
187
|
-
rescue => e
|
188
|
-
# if deserialization fails, delete the log file and continue
|
189
|
-
FileUtils.rm(log_filename)
|
190
|
-
end
|
191
|
-
else
|
192
|
-
commands = []
|
193
|
-
begin
|
194
|
-
clone_or_pull(url).each do |command|
|
195
|
-
commands << command
|
196
|
-
end
|
197
|
-
# make sure a local clone of the repository exists
|
198
|
-
clone_dir = Directories::get_clone_directory(url)
|
199
|
-
raise Makit::Error.new("clone directory does not exist: #{clone_dir}") if !Dir.exist?(clone_dir)
|
200
|
-
|
201
|
-
if (commit == "latest")
|
202
|
-
Dir.chdir(clone_dir) do
|
203
|
-
git_log = Makit::RUNNER.execute("git log -n 1 --date=iso")
|
204
|
-
|
205
|
-
commands << git_log
|
206
|
-
# assert that the commit is valid
|
207
|
-
commit = git_log.output.match(/^commit ([0-9a-f]{40})$/i)[1]
|
208
|
-
raise Makit::Error.new("invalid commit: #{commit}") if commit.nil? || commit.empty? || !commit.match?(/\A[0-9a-f]{40}\z/i)
|
209
|
-
log_filename = File.join(Directories::get_log_directory(url), commit, +"#{RUNTIME_IDENTIFIER}.#{DEVICE}.json")
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
# clone a fresh copy of the repository to a make directory
|
214
|
-
make_dir = Directories::get_make_commit_directory(url, commit)
|
215
|
-
FileUtils.rm_rf(make_dir) if Dir.exist?(make_dir)
|
216
|
-
commands << Makit::RUNNER.execute("git clone #{clone_dir} #{make_dir}")
|
217
|
-
raise Makit::Error.new("failed to clone repository: #{url} to #{make_dir}") if !Dir.exist?(make_dir)
|
218
|
-
Dir.chdir(make_dir) do
|
219
|
-
commands << Makit::RUNNER.execute("git reset --hard #{commit}")
|
220
|
-
commands << Makit::RUNNER.execute("git log -n 1")
|
221
|
-
|
222
|
-
commands << Makit::RUNNER.execute("bundle install") if File.exist? "Gemfile"
|
223
|
-
if File.exist? ("Rakefile")
|
224
|
-
commands << Makit::RUNNER.execute("rake default")
|
225
|
-
else
|
226
|
-
commands << Makit::RUNNER.execute("rake default") if File.exist? "rakefile.rb"
|
227
|
-
end
|
228
|
-
|
229
|
-
make_result = Makit::V1::MakeResult.new(
|
230
|
-
repository: url,
|
231
|
-
commit: commit,
|
232
|
-
branch: "?",
|
233
|
-
tag: "?",
|
234
|
-
device: DEVICE,
|
235
|
-
runtime_identifier: RUNTIME_IDENTIFIER,
|
236
|
-
)
|
237
|
-
commands.flatten.each do |command|
|
238
|
-
make_result.commands << command
|
239
|
-
end
|
240
|
-
|
241
|
-
# save the MakeResult object to a log file as pretty printed json
|
242
|
-
FileUtils.mkdir_p(File.dirname(log_filename)) unless Dir.exist?(File.dirname(log_filename))
|
243
|
-
File.write(log_filename, make_result.to_json)
|
244
|
-
|
245
|
-
return make_result
|
246
|
-
end
|
247
|
-
rescue => e
|
248
|
-
message = "error raised attempting to make repository: #{url} commit: #{commit}\n\n"
|
249
|
-
message += "#{e.message}\n"
|
250
|
-
backtrace = e.backtrace.join("\n")
|
251
|
-
message += "#{backtrace}\n\n"
|
252
|
-
message += "commands:\n"
|
253
|
-
commands.flatten.each do |command|
|
254
|
-
message += Makit::Humanize::get_command_details(command)
|
255
|
-
end
|
256
|
-
raise Makit::Error.new(message)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
if !File.exist?(".gitignore")
|
263
|
-
Makit::LOGGER.info("added .gitignore file")
|
264
|
-
File.open(".gitignore", "w") do |file|
|
265
|
-
file.puts Makit::Content::GITIGNORE
|
266
|
-
end
|
267
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rake/clean"
|
4
|
+
require "logger"
|
5
|
+
require "json"
|
6
|
+
require "yaml"
|
7
|
+
require "google/protobuf"
|
8
|
+
|
9
|
+
#%w[generated/makit].each do |dir|
|
10
|
+
# Dir[File.join(__dir__, dir, "*.rb")].each do |file|
|
11
|
+
# require_relative file
|
12
|
+
# end
|
13
|
+
#end
|
14
|
+
if (File.exist?("protos/makit/makit.v1.proto.rb"))
|
15
|
+
require_relative "generated/makit/makit.v1_pb"
|
16
|
+
else
|
17
|
+
require_relative "makit/v1/makit.v1_pb"
|
18
|
+
end
|
19
|
+
|
20
|
+
#%w[makit makit/v1 makit/cli makit/content makit/mp].each do |dir|
|
21
|
+
%w[makit makit/cli makit/content makit/mp].each do |dir|
|
22
|
+
Dir[File.join(__dir__, dir, "*.rb")].each do |file|
|
23
|
+
require_relative file
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Makit
|
28
|
+
class Error < StandardError; end
|
29
|
+
|
30
|
+
# Constants
|
31
|
+
if File.exist? ".makit.project.json"
|
32
|
+
PROJECT = Makit::Serializer.open(".makit.project.json", Makit::V1::Project)
|
33
|
+
else
|
34
|
+
if File.exist? ".makit.project.yml"
|
35
|
+
PROJECT = Makit::Serializer.open(".makit.project.yml", Makit::V1::Project)
|
36
|
+
else
|
37
|
+
PROJECT = Makit::V1::Project.new
|
38
|
+
PROJECT.set_default_values
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
STARTTIME = Time.now
|
43
|
+
SHOW = Makit::Show.new
|
44
|
+
IS_GIT_REPO = Dir.exist? ".git"
|
45
|
+
DETACHED = `git status`.include?("detached")
|
46
|
+
IS_READ_ONLY = !IS_GIT_REPO || DETACHED
|
47
|
+
RUNTIME_IDENTIFIER = Makit::Environment::get_runtime_identifier
|
48
|
+
DEVICE = Socket.gethostname
|
49
|
+
LOGGER = Makit::Logging::MultiLogger.create_logger
|
50
|
+
|
51
|
+
# Git Commit and Branch/Tag constants
|
52
|
+
ENV["COMMIT_SHA"] = Makit::Git::commitsha
|
53
|
+
ENV["COMMIT_BRANCH"] = Makit::Git::branch
|
54
|
+
|
55
|
+
RUNNER = CommandRunner.new
|
56
|
+
GIT_FILE_INFOS = Makit::Git::get_file_infos
|
57
|
+
#RUNNER.log_to_artifacts = true
|
58
|
+
# Variables
|
59
|
+
log_level = Logger::INFO
|
60
|
+
package_type = Makit::V1::PackageType::GEM
|
61
|
+
commands = Makit::Commands.new
|
62
|
+
|
63
|
+
# methods
|
64
|
+
#
|
65
|
+
# initialize a git repository
|
66
|
+
def self.init(directory)
|
67
|
+
if !Dir.exist?(directory)
|
68
|
+
FileUtils.mkdir_p(directory)
|
69
|
+
end
|
70
|
+
raise Makit::Error.new("directory does not exist: #{directory}") if !Dir.exist?(directory)
|
71
|
+
Dir.chdir(directory) do
|
72
|
+
File.write(".gitignore", Makit::Content::GITIGNORE) unless File.exist?(".gitignore")
|
73
|
+
init = Makit::RUNNER.execute "git init"
|
74
|
+
if init.exit_code != 0
|
75
|
+
raise Makit::Error.new("failed to initialize local repository: #{directory}\n#{Makit::Humanize.get_command_summary(init)}")
|
76
|
+
end
|
77
|
+
init
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# clone a git repository to a local directory in Directories::CLONE
|
82
|
+
# returns the Makit::V1::Command for 'git clone ...'
|
83
|
+
def self.clone(git_repository)
|
84
|
+
commands = []
|
85
|
+
# make sure a local clone of the repository exists
|
86
|
+
clone_dir = Directories::get_clone_directory(git_repository)
|
87
|
+
if (!Dir.exist?(clone_dir))
|
88
|
+
commands << Makit::RUNNER.execute("git clone #{git_repository} #{clone_dir}")
|
89
|
+
end
|
90
|
+
commands
|
91
|
+
end
|
92
|
+
|
93
|
+
# pull the latest changes from the remote repository to a local clone in Directories::CLONE
|
94
|
+
def self.pull(git_repository)
|
95
|
+
clone_dir = Directories::get_clone_directory(git_repository)
|
96
|
+
raise Makit::Error.new("clone directory does not exist: #{clone_dir}") if !Dir.exist?(clone_dir)
|
97
|
+
Dir.chdir(clone_dir) do
|
98
|
+
request = Makit::V1::CommandRequest.new(
|
99
|
+
name: "git",
|
100
|
+
arguments: ["pull"],
|
101
|
+
directory: clone_dir,
|
102
|
+
)
|
103
|
+
pull_command = Makit::RUNNER.execute(request)
|
104
|
+
raise Makit::Error.new(Makit::Humanize::get_command_details(pull_command)) if pull_command.exit_code != 0
|
105
|
+
return pull_command
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.clone_or_pull(git_repository)
|
110
|
+
commands = []
|
111
|
+
clone_dir = Directories::get_clone_directory(git_repository)
|
112
|
+
if Dir.exist?(clone_dir)
|
113
|
+
commands << pull(git_repository)
|
114
|
+
else
|
115
|
+
commands << clone(git_repository)
|
116
|
+
end
|
117
|
+
commands
|
118
|
+
end
|
119
|
+
|
120
|
+
# log information about a specific repository
|
121
|
+
# return an array of GitLogEntry objects
|
122
|
+
def self.log(git_repository, limit, skip)
|
123
|
+
entries = []
|
124
|
+
clone_dir = Directories::get_clone_directory(git_repository)
|
125
|
+
raise Makit::Error.new("clone directory does not exist: #{clone_dir}") if !Dir.exist?(clone_dir)
|
126
|
+
Dir.chdir(clone_dir) do
|
127
|
+
log_command = Makit::RUNNER.execute("git log -n #{limit} --skip #{skip} --date=iso")
|
128
|
+
if log_command.exit_code != 0
|
129
|
+
lines = log_command.stderr.split("\n")
|
130
|
+
# iterate over the lines, generating a GitLogEntry for each commit
|
131
|
+
lines.each do |line|
|
132
|
+
if line.start_with?("commit")
|
133
|
+
commit = line.split(" ")[1]
|
134
|
+
entries << GitLogEntry.new(commit)
|
135
|
+
end
|
136
|
+
if line.start_with?("Author:")
|
137
|
+
entries.last.author = line.split(" ")[1..-1].join(" ")
|
138
|
+
end
|
139
|
+
if line.start_with?("Date:")
|
140
|
+
entries.last.date = line.split(" ")[1..-1].join(" ")
|
141
|
+
end
|
142
|
+
if line.start_with?(" ")
|
143
|
+
entries.last.message += line[4..-1]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
entries
|
149
|
+
end
|
150
|
+
|
151
|
+
# work on a local clone of a git repository
|
152
|
+
# if the repository does not exist, clone it
|
153
|
+
# if the repository exists, pull the latest changes
|
154
|
+
# if a build command can be found, execute it and return the result Makit::V1::WorkResult
|
155
|
+
def self.work(repository)
|
156
|
+
commands = []
|
157
|
+
work_dir = Makit::Directories::get_work_directory(repository)
|
158
|
+
commands << clone_or_pull(repository)
|
159
|
+
clone_dir = Makit::Directories::get_clone_directory(repository)
|
160
|
+
if !Dir.exist?(work_dir)
|
161
|
+
# make the parent directory for work_dir if it does not exist
|
162
|
+
FileUtils.mkdir_p(File.dirname(work_dir)) unless Dir.exist?(File.dirname(work_dir))
|
163
|
+
Makit::RUNNER::execute "git clone #{clone_dir} #{work_dir}"
|
164
|
+
end
|
165
|
+
Dir.chdir(work_dir) do
|
166
|
+
# if there is no .gitignore file, create one
|
167
|
+
File.write(".gitignore", Makit::Content::GITIGNORE) unless File.exist?(".gitignore")
|
168
|
+
end
|
169
|
+
nil?
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.enable_monkey_patch
|
173
|
+
%w[makit/mp].each do |dir|
|
174
|
+
Dir[File.join(__dir__, dir, "*.rb")].each do |file|
|
175
|
+
require_relative file
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
# Given a git repository URL and a commit id, create a new MakeResult object.
|
180
|
+
def self.make(url, commit, force = false)
|
181
|
+
log_filename = File.join(Directories::get_log_directory(url), commit, +"#{RUNTIME_IDENTIFIER}.#{DEVICE}.json")
|
182
|
+
if File.exist?(log_filename) && !force && commit != "latest"
|
183
|
+
begin
|
184
|
+
# deserialize the log file to a Makite::V1::MakeResult object
|
185
|
+
make_result = Makit::V1::MakeResult.decode_json(File.read(log_filename))
|
186
|
+
return make_result
|
187
|
+
rescue => e
|
188
|
+
# if deserialization fails, delete the log file and continue
|
189
|
+
FileUtils.rm(log_filename)
|
190
|
+
end
|
191
|
+
else
|
192
|
+
commands = []
|
193
|
+
begin
|
194
|
+
clone_or_pull(url).each do |command|
|
195
|
+
commands << command
|
196
|
+
end
|
197
|
+
# make sure a local clone of the repository exists
|
198
|
+
clone_dir = Directories::get_clone_directory(url)
|
199
|
+
raise Makit::Error.new("clone directory does not exist: #{clone_dir}") if !Dir.exist?(clone_dir)
|
200
|
+
|
201
|
+
if (commit == "latest")
|
202
|
+
Dir.chdir(clone_dir) do
|
203
|
+
git_log = Makit::RUNNER.execute("git log -n 1 --date=iso")
|
204
|
+
|
205
|
+
commands << git_log
|
206
|
+
# assert that the commit is valid
|
207
|
+
commit = git_log.output.match(/^commit ([0-9a-f]{40})$/i)[1]
|
208
|
+
raise Makit::Error.new("invalid commit: #{commit}") if commit.nil? || commit.empty? || !commit.match?(/\A[0-9a-f]{40}\z/i)
|
209
|
+
log_filename = File.join(Directories::get_log_directory(url), commit, +"#{RUNTIME_IDENTIFIER}.#{DEVICE}.json")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
# clone a fresh copy of the repository to a make directory
|
214
|
+
make_dir = Directories::get_make_commit_directory(url, commit)
|
215
|
+
FileUtils.rm_rf(make_dir) if Dir.exist?(make_dir)
|
216
|
+
commands << Makit::RUNNER.execute("git clone #{clone_dir} #{make_dir}")
|
217
|
+
raise Makit::Error.new("failed to clone repository: #{url} to #{make_dir}") if !Dir.exist?(make_dir)
|
218
|
+
Dir.chdir(make_dir) do
|
219
|
+
commands << Makit::RUNNER.execute("git reset --hard #{commit}")
|
220
|
+
commands << Makit::RUNNER.execute("git log -n 1")
|
221
|
+
|
222
|
+
commands << Makit::RUNNER.execute("bundle install") if File.exist? "Gemfile"
|
223
|
+
if File.exist? ("Rakefile")
|
224
|
+
commands << Makit::RUNNER.execute("rake default")
|
225
|
+
else
|
226
|
+
commands << Makit::RUNNER.execute("rake default") if File.exist? "rakefile.rb"
|
227
|
+
end
|
228
|
+
|
229
|
+
make_result = Makit::V1::MakeResult.new(
|
230
|
+
repository: url,
|
231
|
+
commit: commit,
|
232
|
+
branch: "?",
|
233
|
+
tag: "?",
|
234
|
+
device: DEVICE,
|
235
|
+
runtime_identifier: RUNTIME_IDENTIFIER,
|
236
|
+
)
|
237
|
+
commands.flatten.each do |command|
|
238
|
+
make_result.commands << command
|
239
|
+
end
|
240
|
+
|
241
|
+
# save the MakeResult object to a log file as pretty printed json
|
242
|
+
FileUtils.mkdir_p(File.dirname(log_filename)) unless Dir.exist?(File.dirname(log_filename))
|
243
|
+
File.write(log_filename, make_result.to_json)
|
244
|
+
|
245
|
+
return make_result
|
246
|
+
end
|
247
|
+
rescue => e
|
248
|
+
message = "error raised attempting to make repository: #{url} commit: #{commit}\n\n"
|
249
|
+
message += "#{e.message}\n"
|
250
|
+
backtrace = e.backtrace.join("\n")
|
251
|
+
message += "#{backtrace}\n\n"
|
252
|
+
message += "commands:\n"
|
253
|
+
commands.flatten.each do |command|
|
254
|
+
message += Makit::Humanize::get_command_details(command)
|
255
|
+
end
|
256
|
+
raise Makit::Error.new(message)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
if !File.exist?(".gitignore")
|
263
|
+
Makit::LOGGER.info("added .gitignore file")
|
264
|
+
File.open(".gitignore", "w") do |file|
|
265
|
+
file.puts Makit::Content::GITIGNORE
|
266
|
+
end
|
267
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: makit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.49
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lou Parslow
|
@@ -157,6 +157,8 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
+
- lib/generated/makit/v1/makit.v1_pb.rb
|
161
|
+
- lib/generated/makit/v1/web/link_pb.rb
|
160
162
|
- lib/makit.rb
|
161
163
|
- lib/makit/apache.rb
|
162
164
|
- lib/makit/cli/clean.rb
|
@@ -227,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
229
|
- !ruby/object:Gem::Version
|
228
230
|
version: '0'
|
229
231
|
requirements: []
|
230
|
-
rubygems_version: 3.5.
|
232
|
+
rubygems_version: 3.5.23
|
231
233
|
signing_key:
|
232
234
|
specification_version: 4
|
233
235
|
summary: CI/CD tools for Ruby developers.
|