Permalink
Newer
Older
100644 224 lines (188 sloc) 5.97 KB
jyurek
Dec 18, 2007
1
require 'rake'
2
require 'rake/testtask'
3
require 'rubygems/package_task'
4
begin
5
require 'cucumber/rake/task'
6
rescue LoadError
7
$stderr.puts "Please install cucumber: `gem install cucumber`"
8
exit 1
9
end
10
require './lib/airbrake/version'
jyurek
Dec 18, 2007
11
12
FEATURES = ["sinatra","rack","metal","user_informer","rake"]
jyurek
Dec 18, 2007
14
desc 'Default: run unit tests.'
15
task :default => [:test, "cucumber:rails:all"] + FEATURES
jyurek
Dec 18, 2007
16
Aug 10, 2011
17
desc "Clean out the tmp directory"
18
task :clean do
19
exec "rm -rf tmp"
20
end
21
22
desc 'Test the airbrake gem.'
jyurek
Dec 18, 2007
23
Rake::TestTask.new(:test) do |t|
24
t.libs << 'lib'
25
t.pattern = 'test/**/*_test.rb'
26
t.verbose = true
27
end
28
29
namespace :changeling do
30
desc "Bumps the version by a minor or patch version, depending on what was passed in."
31
task :bump, :part do |t, args|
32
# Thanks, Jeweler!
33
if Airbrake::VERSION =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
34
major = $1.to_i
35
minor = $2.to_i
36
patch = $3.to_i
37
build = $4
38
else
39
abort
40
end
41
42
case args[:part]
43
when /minor/
44
minor += 1
45
patch = 0
46
when /patch/
47
patch += 1
48
else
49
abort
50
end
51
52
version = [major, minor, patch, build].compact.join('.')
53
Jonathan Siegel Jonathan Siegel
Nov 2, 2011
54
File.open(File.join("lib", "airbrake", "version.rb"), "w") do |f|
56
module Airbrake
57
VERSION = "#{version}".freeze
58
end
59
EOF
60
end
61
end
62
63
desc "Writes out the new CHANGELOG and prepares the release"
64
task :change do
65
load 'lib/airbrake/version.rb'
66
file = "CHANGELOG"
67
old = File.read(file)
68
version = Airbrake::VERSION
69
message = "Bumping to version #{version}"
70
editor = ENV["EDITOR"] || "vim" # prefer vim if no env variable for editor is set
71
72
File.open(file, "w") do |f|
73
f.write <<EOF
74
Version #{version} - #{Time.now}
75
===============================================================================
76
77
#{`git log $(git tag | grep -v rc | tail -1)..HEAD | git shortlog`}
82
exec ["#{editor} #{file}",
83
"git commit -aqm '#{message}'",
84
"git tag -a -m '#{message}' v#{version}",
85
"echo '\n\n\033[32mMarked v#{version} /' `git show-ref -s refs/heads/master` 'for release. Run: rake changeling:push\033[0m\n\n'"].join(' && ')
86
end
87
88
desc "Bump by a minor version (1.2.3 => 1.3.0)"
89
task :minor do |t|
90
Rake::Task['changeling:bump'].invoke(t.name)
91
Rake::Task['changeling:change'].invoke
92
end
93
94
desc "Bump by a patch version, (1.2.3 => 1.2.4)"
95
task :patch do |t|
96
Rake::Task['changeling:bump'].invoke(t.name)
97
Rake::Task['changeling:change'].invoke
98
end
99
100
desc "Push the latest version and tags"
101
task :push do |t|
102
system("git push origin master")
103
system("git push origin $(git tag | grep -v rc | tail -1)")
104
end
107
begin
108
require 'yard'
109
YARD::Rake::YardocTask.new do |t|
110
t.files = ['lib/**/*.rb', 'TESTING.rdoc']
111
end
112
rescue LoadError
113
end
Jan 13, 2010
114
115
GEM_ROOT = File.dirname(__FILE__).freeze
Jan 13, 2010
116
117
desc "Clean files generated by rake tasks"
118
task :clobber => [:clobber_rdoc, :clobber_package]
119
120
LOCAL_GEM_ROOT = File.join(GEM_ROOT, 'tmp', 'local_gems').freeze
121
RAILS_VERSIONS = IO.read('SUPPORTED_RAILS_VERSIONS').strip.split("\n")
122
LOCAL_GEMS =
123
[
124
["rack","1.3.2"],
125
] +
126
RAILS_VERSIONS.collect { |version| ['rails', version] } +
127
[
128
['sham_rack', nil],
129
['capistrano', nil],
130
['sqlite3-ruby', nil],
131
["therubyracer",nil],
132
["sinatra",nil]
136
desc "Vendor test gems: Run this once to prepare your test environment"
137
task :vendor_test_gems do
138
old_gem_path = ENV['GEM_PATH']
139
old_gem_home = ENV['GEM_HOME']
140
ENV['GEM_PATH'] = LOCAL_GEM_ROOT
141
ENV['GEM_HOME'] = LOCAL_GEM_ROOT
143
LOCAL_GEMS.each do |gem_name, version|
144
gem_file_pattern = [gem_name, version || '*'].compact.join('-')
145
version_option = version ? "-v #{version}" : ''
146
pattern = File.join(LOCAL_GEM_ROOT, 'gems', "#{gem_file_pattern}")
147
existing = Dir.glob(pattern).first
148
if existing
149
puts "\nskipping #{gem_name} since it's already vendored," +
150
"remove it from the tmp directory first."
151
next
152
end
153
154
command = "gem install -i #{LOCAL_GEM_ROOT} --no-ri --no-rdoc --backtrace #{version_option} #{gem_name}"
155
puts "Vendoring #{gem_file_pattern}..."
156
unless system("#{command} 2>&1")
157
puts "Command failed: #{command}"
158
exit(1)
159
end
160
end
162
ENV['GEM_PATH'] = old_gem_path
163
ENV['GEM_HOME'] = old_gem_home
164
end
165
166
Cucumber::Rake::Task.new(:cucumber) do |t|
167
t.fork = true
168
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
169
end
170
171
task :cucumber => [:vendor_test_gems]
174
def run_rails_cucumber_task(version, additional_cucumber_args)
175
puts "Testing Rails #{version}"
176
if version.empty?
177
raise "No Rails version specified - make sure ENV['RAILS_VERSION'] is set, e.g. with `rake cucumber:rails:all`"
178
end
179
ENV['RAILS_VERSION'] = version
180
cmd = "cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} #{additional_cucumber_args} features/rails.feature features/rails_with_js_notifier.feature"
181
puts "Running command: #{cmd}"
182
system(cmd)
185
def define_rails_cucumber_tasks(additional_cucumber_args = '')
187
RAILS_VERSIONS.each do |version|
188
desc "Test integration of the gem with Rails #{version}"
189
task version => [:vendor_test_gems] do
190
exit 1 unless run_rails_cucumber_task(version, additional_cucumber_args)
191
end
192
end
193
194
desc "Test integration of the gem with all Rails versions"
195
task :all do
196
results = RAILS_VERSIONS.map do |version|
197
run_rails_cucumber_task(version, additional_cucumber_args)
198
end
199
200
exit 1 unless results.all?
201
end
204
205
namespace :cucumber do
206
namespace :wip do
207
define_rails_cucumber_tasks('--tags @wip')
208
end
209
210
define_rails_cucumber_tasks
211
212
rule /#{"(" + FEATURES.join("|") + ")"}/ do |t|
213
framework = t.name
214
desc "Test integration of the gem with #{framework}"
215
task framework.to_sym do
216
puts "Testing #{framework.split(":").last}..."
217
cmd = "cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features/#{framework.split(":").last}.feature"
218
puts "Running command: #{cmd}"
219
system(cmd)
220
end
221
end
222
223
end