Created
May 29, 2012 14:55
-
-
Save iafonov/2828887 to your computer and use it in GitHub Desktop.
Smart cucumber test runner for Jenkins CI
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
require 'fileutils' | |
BUILDS_PATH = '/var/lib/jenkins/jobs/secret_project/builds' | |
# list of build directories | |
builds = Dir.entries(BUILDS_PATH).select{|dir| dir =~ /^\d{1,4}$/}.map{|dir| dir.to_i}.sort | |
stats = builds.inject({}) do |stats, build_number| | |
`grep -r "cucumber" #{File.join(BUILDS_PATH, build_number.to_s)}`.each do |line| | |
line.match /workspace\/(.*?)\:(\d*).*Scenario: (.*)/ | |
next if $1.nil? | |
if stats.has_key? $1 | |
stats[$1][:count] += 1 # failures count | |
stats[$1][:weight] += (build_number.to_f / builds.size) # failures 'weight' | |
else | |
stats[$1] = {:count => 0, :feature => $1, :line => $2, :scenario => $3, :weight => 0} | |
end | |
end | |
stats | |
end | |
top_failing = stats.sort_by{|k, v| v[:weight]}. | |
select{|line| FileTest.exists?(line[1][:feature]) }. | |
reverse.first(5).map{|line| line[1]} | |
exec "bundle exec cucumber --tags ~@wip -r features/ #{top_failing.map{|line| line[:feature]}.join(" ")}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment