Created
April 11, 2016 21:34
-
-
Save mwean/5638315781e681e867faf239e0375c53 to your computer and use it in GitHub Desktop.
List all spec failures from a given build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Author
mwean
commented
Apr 11, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment