Commit 6453e2a80f6de00d9b874027f6d93dac87938ab9

Authored by Antonio Terceiro
1 parent 9b469d9b

ci:smoke: revamp

- provide sane defaults for $HEAD and $PREV_HEAD
- list commits since $PREV_HEAD
Showing 1 changed file with 22 additions and 18 deletions   Show diff stats
lib/tasks/ci.rake
@@ -2,29 +2,33 @@ namespace :ci do @@ -2,29 +2,33 @@ namespace :ci do
2 2
3 desc 'Continuous integration smoke test' 3 desc 'Continuous integration smoke test'
4 task :smoke do 4 task :smoke do
5 - if ENV['HEAD'] && ENV['PREV_HEAD']  
6 - from = ENV['PREV_HEAD']  
7 - to = ENV['HEAD']  
8 - changed_files = `git diff --name-only #{from}..#{to}`.split  
9 5
10 - # explicitly changed tests  
11 - tests = changed_files.select { |f| f =~ /test\/.*_test\.rb$/ }  
12 - features = changed_files.select { |f| f =~ /\.feature$/ } 6 + current_branch = `git rev-parse --abbrev-ref HEAD`.strip
  7 + from = ENV['PREV_HEAD'] || "origin/#{current_branch}"
  8 + to = ENV['HEAD'] || current_branch
  9 + changed_files = `git diff --name-only #{from}..#{to}`.split
13 10
14 - # match changed code files to their respective tests  
15 - changed_files.each do |f|  
16 - if f =~ /^(app|lib)\//  
17 - basename = File.basename(f, '.rb')  
18 - Dir.glob("test/**/#{basename}_test.rb").each do |t|  
19 - tests << t unless tests.include?(t)  
20 - end 11 + unless $stdout.isatty
  12 + sh "git", "log", "--name-status", "#{from}..#{to}"
  13 + end
  14 +
  15 + # explicitly changed tests
  16 + tests = changed_files.select { |f| f =~ /test\/.*_test\.rb$/ }
  17 + features = changed_files.select { |f| f =~ /\.feature$/ }
  18 +
  19 + # match changed code files to their respective tests
  20 + changed_files.each do |f|
  21 + if f =~ /^(app|lib)\//
  22 + basename = File.basename(f, '.rb')
  23 + Dir.glob("test/**/#{basename}_test.rb").each do |t|
  24 + tests << t unless tests.include?(t)
21 end 25 end
22 end 26 end
23 -  
24 - sh 'testrb', *tests unless tests.empty?  
25 - sh 'cucumber', *features unless features.empty?  
26 - sh 'cucumber', '-p', 'selenium', *features unless features.empty?  
27 end 27 end
  28 +
  29 + sh 'testrb', *tests unless tests.empty?
  30 + sh 'cucumber', *features unless features.empty?
  31 + sh 'cucumber', '-p', 'selenium', *features unless features.empty?
28 end 32 end
29 33
30 end 34 end