Skip to content

Commit

Permalink
Publish code coverage to Code Climate from Travis.
Browse files Browse the repository at this point in the history
  * Do not multi-thread unit tests while running coverage, as the threads will clobber each others' data.
  * The coverage will only publish for the master branch, not develop.
  • Loading branch information
Adam Stegman authored and Kris Hicks committed Jun 11, 2014
1 parent c7cca1f commit 442089c
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 14 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ rvm:
- ruby-1.9.3

env:
- TASKS="travis:install_go spec:unit"
# limit unit test threads to 1 to avoid SimpleCov race conditions:
# https://github.com/colszowka/simplecov/issues/305
- COVERAGE=true BOSH_MAX_THREADS=1 TASKS="travis:install_go spec:unit ci:publish_coverage_report"

- DB=mysql TASKS="spec:integration:ruby_agent"
- DB=postgres TASKS="spec:integration:ruby_agent"

# Go agent integration tests do not need to test every DB flavor
# since integration tests above already tested them
- TASKS="travis:install_go spec:integration:go_agent"

addons:
code_climate:
# master branch
repo_token: c5256f87295d0bf77f092dfa5f037b17ef17439c7342209256258084a54e410f
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ group :development, :test do
gem 'ci_reporter'
gem 'webmock'
gem 'fakefs'
gem 'simplecov'
gem 'simplecov-rcov'
# simplecov 0.8.x has an exit code bug: https://github.com/colszowka/simplecov/issues/281
gem 'simplecov', '~> 0.7.1'
gem 'codeclimate-test-reporter', require: false
gem 'vcr'

# Explicitly do not require serverspec dependency
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ GEM
builder (3.1.4)
ci_reporter (1.8.4)
builder (>= 2.1.2)
codeclimate-test-reporter (0.3.0)
simplecov (>= 0.7.1, < 1.0.0)
crack (0.3.2)
daemons (1.1.9)
diff-lcs (1.2.5)
Expand Down Expand Up @@ -322,7 +324,7 @@ GEM
mime-types (1.23)
minitar (0.5.4)
mixlib-shellout (1.1.0)
multi_json (1.7.8)
multi_json (1.10.1)
mysql2 (0.3.11)
nats (0.4.28)
daemons (>= 1.1.5)
Expand Down Expand Up @@ -412,8 +414,6 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
simplecov-rcov (0.2.3)
simplecov (>= 0.4.1)
sinatra (1.4.3)
rack (~> 1.4)
rack-protection (~> 1.4)
Expand Down Expand Up @@ -477,6 +477,7 @@ DEPENDENCIES
bosh_vsphere_cpi!
bosh_warden_cpi!
ci_reporter
codeclimate-test-reporter
fakefs
foodcritic
git-duet
Expand All @@ -501,8 +502,7 @@ DEPENDENCIES
rugged
serverspec
simple_blobstore_server!
simplecov
simplecov-rcov
simplecov (~> 0.7.1)
specinfra
sqlite3
timecop
Expand Down
7 changes: 7 additions & 0 deletions bosh-dev/lib/bosh/dev/tasks/ci.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
namespace :ci do
desc "Publish the code coverage report"
task :publish_coverage_report do
require 'codeclimate-test-reporter'
SimpleCov.formatter = CodeClimate::TestReporter::Formatter
SimpleCov::ResultMerger.merged_result.format!
end

desc 'Publish CI pipeline gems to S3'
task :publish_pipeline_gems do
require 'bosh/dev/build'
Expand Down
10 changes: 6 additions & 4 deletions bosh-dev/lib/bosh/dev/tasks/spec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,24 @@ namespace :spec do
trap('INT') { exit }

builds = Dir['*'].select { |f| File.directory?(f) && File.exists?("#{f}/spec") }
builds -= ['bat']
builds -= %w(bat)

cpi_builds = Dir['*'].select { |f| File.directory?(f) && f.end_with?("_cpi") }
cpi_builds = builds.select { |f| File.directory?(f) && f.end_with?("_cpi") }

spec_logs = Dir.mktmpdir

puts "Logging spec results in #{spec_logs}"

Bosh::ThreadPool.new(max_threads: 10, logger: Logger.new('/dev/null')).wrap do |pool|
max_threads = ENV.fetch('BOSH_MAX_THREADS', 10).to_i
Bosh::ThreadPool.new(max_threads: max_threads, logger: Logger.new('/dev/null')).wrap do |pool|
builds.each do |build|
pool.process do
log_file = "#{spec_logs}/#{build}.log"
rspec_files = cpi_builds.include?(build) ? "spec/unit/" : "spec/"
rspec_cmd = "rspec --tty -c -f p #{rspec_files}"

if system("cd #{build} && #{rspec_cmd} > #{log_file} 2>&1")
# inject command name so coverage results for each component don't clobber others
if system({'BOSH_BUILD_NAME' => build}, "cd #{build} && #{rspec_cmd} > #{log_file} 2>&1")
puts "----- BEGIN #{build}"
puts " #{rspec_cmd}"
print File.read(log_file)
Expand Down
4 changes: 4 additions & 0 deletions bosh-director/.simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SimpleCov.configure do
add_filter '/db/'
add_filter '/spec/'
end
3 changes: 2 additions & 1 deletion bosh_warden_cpi/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rspec'
require File.expand_path('../../../spec/shared_spec_helper', __FILE__)

require 'logger'
require 'tmpdir'
require 'cloud'
Expand Down
14 changes: 13 additions & 1 deletion spec/shared_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# This file is included by every sub-project's spec_helper
require 'rspec'

if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start do
root File.expand_path('../..', __FILE__)
merge_timeout 3600
# command name is injected by the spec.rake runner
if ENV['BOSH_BUILD_NAME']
command_name ENV['BOSH_BUILD_NAME']
end
end
end

require 'rspec'
RSpec.configure do |config|
config.deprecation_stream = StringIO.new

Expand Down
Binary file added vendor/cache/codeclimate-test-reporter-0.3.0.gem
Binary file not shown.
Binary file added vendor/cache/multi_json-1.10.1.gem
Binary file not shown.
Binary file removed vendor/cache/multi_json-1.7.8.gem
Binary file not shown.
Binary file removed vendor/cache/simplecov-rcov-0.2.3.gem
Binary file not shown.

0 comments on commit 442089c

Please sign in to comment.