lib/xcjobs/coverage.rb in xcjobs-0.1.1 vs lib/xcjobs/coverage.rb in xcjobs-0.1.2
- old
+ new
@@ -1,10 +1,11 @@
require 'rake/tasklib'
require 'json'
require 'pathname'
require 'tempfile'
require 'open3'
+require 'digest/md5'
module XCJobs
module Coverage
def self.run_gcov(configuration_temp_dir)
@@ -88,11 +89,11 @@
Dir.glob("#{base_dir}/**/*.gcov").each do |file|
File.open(file, "r") do |handle|
source_file = {}
name = ''
- source = ''
+ source_digest = nil
coverage = []
handle.each_line do |line|
match = /^[ ]*([0-9]+|-|#####):[ ]*([0-9]+):(.*)/.match(line)
next unless match.to_a.count == 4
@@ -100,13 +101,15 @@
if number.to_i == 0
key, val = /([^:]+):(.*)$/.match(text).to_a[1..2]
if key == 'Source'
name = Pathname(val).relative_path_from(Pathname(base_dir)).to_s
+ if File.exist?(val)
+ source_digest = Digest::MD5.file(val).to_s
+ end
end
else
- source << text + '\n'
coverage[number.to_i - 1] = case count.strip
when "-"
nil
when "#####"
if text.strip == '}'
@@ -117,20 +120,32 @@
else count.to_i
end
end
end
- if !is_excluded_path(name)
+ if !is_excluded_path(name) && !source_digest.nil?
source_file['name'] = name
- source_file['source'] = source
+ source_file['source_digest'] = source_digest
source_file['coverage'] = coverage
report['source_files'] << source_file
end
end
end
+ remotes = %x[git remote -v].rstrip.split(/\r?\n/).map {|line| line.chomp }.select { |line| line.include? 'fetch'}.first.split(' ')
+ report['git'] = {
+ 'head' => {
+ 'id' => %x[git --no-pager log -1 --pretty=format:%H],
+ 'author_name' => %x[git --no-pager log -1 --pretty=format:%aN],
+ 'author_email' => %x[git --no-pager log -1 --pretty=format:%ae],
+ 'committer_name' => %x[git --no-pager log -1 --pretty=format:%cN],
+ 'committer_email' => %x[git --no-pager log -1 --pretty=format:%ce],
+ 'message' => %x[git --no-pager log -1 --pretty=format:%s] },
+ 'branch' => %x[git rev-parse --abbrev-ref HEAD].strip,
+ 'remotes' => {'name' => remotes[0], 'remote' => remotes[1]} }
+
report
end
def is_excluded_path(filepath)
if filepath.start_with?('..')
@@ -157,13 +172,15 @@
return false
end
end
def write_report(report)
- temp = Tempfile.new('coveralls')
- temp.puts(report.to_json)
- temp.flush
- temp.path
+ tempdir = Pathname.new(Dir.tmpdir).join(SecureRandom.hex)
+ FileUtils.mkdir_p(tempdir)
+ tempfile = File::open(tempdir.join('coveralls.json'), "w")
+ tempfile.puts(report.to_json)
+ tempfile.flush
+ tempfile.path
end
def upload(json_file)
curl_options = ['curl', '-sSf', '-F', "json_file=@#{json_file}", 'https://coveralls.io/api/v1/jobs']
puts curl_options.join(' ')