5
6
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
32
33
|
# File 'lib/raykit/rake.rb', line 5
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))
return Command.parse(File.read(log_filename))
else
run_dir="#{Environment::get_dev_dir('tmp')}/#{rel_dir}.#{branch}.#{commit}"
if(!Dir.exist?(run_dir))
parent_dir = File.expand_path('..',run_dir)
if(!Dir.exist?(parent_dir))
FileUtils.mkdir_p(parent_dir)
end
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)
if(!Dir.exist?(parent_dir))
FileUtils.mkdir_p(parent_dir)
end
File.open(log_filename,'w'){|f|
f.write(JSON.generate(cmd.to_hash))
}
return cmd
end
end
end
|