|
| 1 | +#!/usr/bin/env ruby |
| 2 | +require 'fileutils' |
| 3 | +include FileUtils |
| 4 | + |
| 5 | +commands = [ |
| 6 | + 'mysql -e "create database activerecord_unittest;"', |
| 7 | + 'mysql -e "create database activerecord_unittest2;"', |
| 8 | + 'psql -c "create database activerecord_unittest;" -U postgres', |
| 9 | + 'psql -c "create database activerecord_unittest2;" -U postgres' |
| 10 | +] |
| 11 | + |
| 12 | +commands.each do |command| |
| 13 | + system("#{command} > /dev/null 2>&1") |
| 14 | +end |
| 15 | + |
| 16 | +class Build |
| 17 | + MAP = { |
| 18 | + 'railties' => 'railties', |
| 19 | + 'ap' => 'actionpack', |
| 20 | + 'am' => 'actionmailer', |
| 21 | + 'amo' => 'activemodel', |
| 22 | + 'ares' => 'activeresource', |
| 23 | + 'as' => 'activesupport', |
| 24 | + 'ar' => 'activerecord' |
| 25 | + } |
| 26 | + |
| 27 | + attr_reader :component, :options |
| 28 | + |
| 29 | + def initialize(component, options = {}) |
| 30 | + @component = component |
| 31 | + @options = options |
| 32 | + end |
| 33 | + |
| 34 | + def run!(options = {}) |
| 35 | + self.options.update(options) |
| 36 | + Dir.chdir(dir) do |
| 37 | + announce(heading) |
| 38 | + ENV['IM'] = identity_map?.inspect |
| 39 | + rake(*tasks) |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + def announce(heading) |
| 44 | + puts "\n\e[1;33m[Travis CI] #{heading}\e[m\n" |
| 45 | + end |
| 46 | + |
| 47 | + def heading |
| 48 | + heading = [gem] |
| 49 | + heading << "with #{adapter} IM #{identity_map? ? 'enabled' : 'disabled'}" if activerecord? |
| 50 | + heading << "in isolation" if isolated? |
| 51 | + heading.join(' ') |
| 52 | + end |
| 53 | + |
| 54 | + def tasks |
| 55 | + if activerecord? |
| 56 | + ['mysql:rebuild_databases', "#{adapter}:#{'isolated_' if isolated?}test"] |
| 57 | + else |
| 58 | + ["test#{':isolated' if isolated?}"] |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + def key |
| 63 | + key = [gem] |
| 64 | + key << adapter if activerecord? |
| 65 | + key << 'IM' if identity_map? |
| 66 | + key << 'isolated' if isolated? |
| 67 | + key.join(':') |
| 68 | + end |
| 69 | + |
| 70 | + def activerecord? |
| 71 | + gem == 'activerecord' |
| 72 | + end |
| 73 | + |
| 74 | + def identity_map? |
| 75 | + options[:identity_map] |
| 76 | + end |
| 77 | + |
| 78 | + def isolated? |
| 79 | + options[:isolated] |
| 80 | + end |
| 81 | + |
| 82 | + def gem |
| 83 | + MAP[component.split(':').first] |
| 84 | + end |
| 85 | + alias :dir :gem |
| 86 | + |
| 87 | + def adapter |
| 88 | + component.split(':').last |
| 89 | + end |
| 90 | + |
| 91 | + def rake(*tasks) |
| 92 | + tasks.each do |task| |
| 93 | + cmd = "bundle exec rake #{task}" |
| 94 | + puts "Running command: #{cmd}" |
| 95 | + return false unless system(cmd) |
| 96 | + end |
| 97 | + true |
| 98 | + end |
| 99 | +end |
| 100 | + |
| 101 | +results = {} |
| 102 | + |
| 103 | +ENV['GEM'].split(',').each do |gem| |
| 104 | + [false, true].each do |isolated| |
| 105 | + next if gem == 'railties' && isolated |
| 106 | + |
| 107 | + build = Build.new(gem, :isolated => isolated) |
| 108 | + results[build.key] = build.run! |
| 109 | + |
| 110 | + if build.activerecord? |
| 111 | + build.options[:identity_map] = true |
| 112 | + results[build.key] = build.run! |
| 113 | + end |
| 114 | + end |
| 115 | +end |
| 116 | + |
| 117 | +# puts |
| 118 | +# puts "Build environment:" |
| 119 | +# puts " #{`cat /etc/issue`}" |
| 120 | +# puts " #{`uname -a`}" |
| 121 | +# puts " #{`ruby -v`}" |
| 122 | +# puts " #{`mysql --version`}" |
| 123 | +# # puts " #{`pg_config --version`}" |
| 124 | +# puts " SQLite3: #{`sqlite3 -version`}" |
| 125 | +# `gem env`.each_line {|line| print " #{line}"} |
| 126 | +# puts " Bundled gems:" |
| 127 | +# `bundle show`.each_line {|line| print " #{line}"} |
| 128 | +# puts " Local gems:" |
| 129 | +# `gem list`.each_line {|line| print " #{line}"} |
| 130 | + |
| 131 | +failures = results.select { |key, value| value == false } |
| 132 | + |
| 133 | +if failures.empty? |
| 134 | + puts |
| 135 | + puts "Rails build finished sucessfully" |
| 136 | + exit(true) |
| 137 | +else |
| 138 | + puts |
| 139 | + puts "Rails build FAILED" |
| 140 | + puts "Failed components: #{failures.map { |component| component.first }.join(', ')}" |
| 141 | + exit(false) |
| 142 | +end |
0 commit comments