7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/raykit/rake.rb', line 7
def self.run(remote, branch, task = "default")
repo = Raykit::Git::Repository.new(remote)
rel_dir = repo.relative_path
commit = repo.latest_commit(branch)
log_filename = "#{Environment.get_dev_dir("log")}/RayKit.Runner/#{rel_dir}/#{branch}/#{commit}.json"
if File.exist?(log_filename)
Command.parse(File.read(log_filename))
else
run_dir = "#{Environment.get_dev_dir("tmp")}/#{rel_dir}.#{branch}.#{commit}"
unless Dir.exist?(run_dir)
parent_dir = File.expand_path("..", run_dir)
FileUtils.mkdir_p(parent_dir) unless Dir.exist?(parent_dir)
cmd = Command.new("git clone #{remote} #{run_dir}")
end
Dir.chdir(run_dir) do
cmd = Command.new("rake #{task}")
parent_dir = File.dirname(log_filename)
FileUtils.mkdir_p(parent_dir) unless Dir.exist?(parent_dir)
File.open(log_filename, "w") do |f|
f.write(JSON.generate(cmd.to_hash))
end
return cmd
end
end
end
|