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