Skip to content

Instantly share code, notes, and snippets.

@mwean
Created Apr 11, 2016
Embed
What would you like to do?
List all spec failures from a given build
#!/usr/bin/env ruby -wU
require "httparty"
build_num = ARGV[0]
print "Pulling spec failures from build #{build_num}..."
summary_url = "https://circleci.com/api/v1/project/LendingHome/lendinghome-monolith/#{build_num}"
summary_response = JSON.parse(HTTParty.get(summary_url, query: { "circle-token" => ENV["CIRCLE_TOKEN"]}))
puts "done."
test_step = summary_response["steps"].find { |step| step["name"] =~ /circleci\/test/ }
project_root = `git rev-parse --show-toplevel`.strip
step_index = summary_response["steps"].index(test_step)
failed_containers = test_step["actions"].select { |action| action["failed"] }.map { |action| action["index"] }
puts "Specs failed in containers #{failed_containers.join(', ')}"
print "Pulling spec output from failed containers..."
failed_output = failed_containers.map do |container|
output_url = "https://circleci.com/api/v1/project/LendingHome/lendinghome-monolith/#{build_num}/output/#{step_index}/#{container}"
JSON.parse(HTTParty.get(output_url, query: { "circle-token" => ENV["CIRCLE_TOKEN"]}))
end
puts "done."
failed_specs = failed_output.flat_map do |output|
message = output.find { |group| group["type"] == "out" }["message"]
message.scan(%r{\[\d+mrspec \./(spec.*\.rb)[\:\[][\d\:]+\]?}).flatten
end
puts "Finding full spec paths..."
expanded_paths = Dir.chdir(project_root) do
failed_specs.uniq.flat_map do |spec|
path, _ = spec.split(/[\[\:]/)
puts "Finding #{path}..."
Dir.glob("**/#{path}")
end
end
puts
relative_paths = expanded_paths.map { |expanded_path| expanded_path.split('/', 2) }.group_by(&:first).map do |app, paths|
[app, paths.map(&:last)]
end
relative_paths.each do |app, specs|
puts "#{app.capitalize}:"
specs.each { |spec| puts " #{spec}" }
end
@mwean
Copy link
Author

mwean commented Apr 11, 2016

> list_failures 17327

Pulling spec failures from build 17327...done.
Specs failed in containers 1, 4, 5, 6, 7, 9, 10, 12, 16, 17, 18, 19, 20
Pulling spec output from failed containers...done.
Finding full spec paths...
Finding spec/services/payment_attempt_service_spec.rb...
Finding spec/features/borrower/ppe_short_form_spec.rb...
Finding spec/services/money_service_spec.rb...
Finding spec/models/loan_spec.rb...
Finding spec/services/checklist_service_spec.rb...
Finding spec/services/move_loan_service_spec.rb...
Finding spec/services/refunds_service_spec.rb...
Finding spec/mailers/reminder_mailer_spec.rb...
Finding spec/services/bnl_service_spec.rb...
Finding spec/mailers/operations_mailer_spec.rb...
Finding spec/models/loan/closing_spec.rb...
Finding spec/models/loan/checklist_item_spec.rb...
Finding spec/services/compliance/ecoa_service_spec.rb...
Finding spec/integration/servicing_notification_spec.rb...
Finding spec/services/loan_schedule_service_spec.rb...
Finding spec/views/pipelines/burndown_view_spec.rb...
Finding spec/features/servicers/remittance_spec.rb...
Finding spec/features/pipeline_spec.rb...
Finding spec/features/loan_status_spec.rb...
done.

Consumer:
  spec/services/payment_attempt_service_spec.rb
  spec/features/borrower/ppe_short_form_spec.rb
  spec/services/money_service_spec.rb
  spec/models/loan_spec.rb
  spec/services/checklist_service_spec.rb
  spec/services/move_loan_service_spec.rb
  spec/services/refunds_service_spec.rb
  spec/mailers/reminder_mailer_spec.rb
  spec/services/bnl_service_spec.rb
  spec/mailers/operations_mailer_spec.rb
  spec/models/loan/closing_spec.rb
  spec/models/loan/checklist_item_spec.rb
  spec/services/compliance/ecoa_service_spec.rb
  spec/integration/servicing_notification_spec.rb
  spec/services/loan_schedule_service_spec.rb
Ops:
  spec/mailers/operations_mailer_spec.rb
  spec/views/pipelines/burndown_view_spec.rb
  spec/features/servicers/remittance_spec.rb
  spec/features/pipeline_spec.rb
  spec/features/loan_status_spec.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment