forked from papersmart/vanity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
190 lines (160 loc) · 5.61 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
require "rake/testtask"
require 'appraisal'
# -- Building stuff --
spec = Gem::Specification.load(Dir["*.gemspec"].first)
desc "Build the Gem"
task :build do
sh "gem build #{spec.name}.gemspec"
end
desc "Install #{spec.name} locally"
task :install=>:build do
sudo = "sudo" unless File.writable?( Gem::ConfigMap[:bindir])
sh "#{sudo} gem install #{spec.name}-#{spec.version}.gem"
end
desc "Push new release to gemcutter and git tag"
task :push=>["test:all", "build"] do
sh "git push"
puts "Tagging version #{spec.version} .."
sh "git tag v#{spec.version}"
sh "git push --tag"
puts "Building and pushing gem .."
sh "gem push #{spec.name}-#{spec.version}.gem"
end
# -- Testing stuff --
desc "Test everything"
task "test:all"=>"test:adapters"
# Ruby versions we're testing with.
RUBIES = %w{1.8.7 1.9.2}
# Use rake test:rubies to run all combination of tests (see test:adapters) using
# all the versions of Ruby specified in RUBIES. Or to test a specific version of
# Ruby, rake test:rubies[1.8.7].
#
# This task uses RVM to install all the Ruby versions it needs, and creates a
# vanity gemset in each one that includes Bundler and all the gems specified in
# Gemfile. If anything goes south you can always wipe these gemsets or uninstall
# these Rubies and start over.
desc "Test using multiple versions of Ruby"
task "test:rubies", :ruby do |t, args|
rubies = args.ruby ? [args.ruby] : RUBIES
rubies.each do |ruby|
puts "** Setup #{ruby}"
sh "env rvm_install_on_use_flag=1 rvm_gemset_create_on_use_flag=1 rvm use #{ruby}@vanity"
sh "rvm #{ruby}@vanity rake test:setup"
puts
puts "** Test using #{ruby}"
sh "rvm #{ruby}@vanity -S bundle exec rake test:adapters #{'--trace' if Rake.application.options.trace}"
end
end
task "test:setup" do
# Intended to be used from test:rubies, within specific RVM context.
begin # Make sure we got Bundler installed.
require "bundler"
rescue LoadError
sh "gem install bundler"
end
begin # Make sure we got all the dependencies
sh "bundle exec ruby -e puts > /dev/null"
rescue
sh "bundle install"
end
end
# These are all the adapters we're going to test with.
ADAPTERS = %w{redis mongodb mysql}
desc "Test using different back-ends"
task "test:adapters", :adapter do |t, args|
adapters = args.adapter ? [args.adapter] : ADAPTERS
adapters.each do |adapter|
puts "** Testing #{adapter} adapter"
sh "rake appraisal test DB=#{adapter} #{'--trace' if Rake.application.options.trace}"
end
end
# Run the test suit.
task :default=>:test
desc "Run all tests"
Rake::TestTask.new do |task|
task.test_files = FileList['test/**/*_test.rb']
if Rake.application.options.trace
#task.warning = true
task.verbose = true
elsif Rake.application.options.silent
task.ruby_opts << "-W0"
else
task.verbose = true
end
task.ruby_opts << "-I."
end
task(:clobber) { rm_rf "tmp" }
# -- Documenting stuff --
begin
require "yard"
YARD::Rake::YardocTask.new(:yardoc) do |task|
task.files = FileList["lib/**/*.rb"].exclude("lib/vanity/backport.rb")
task.options = "--output", "html/api", "--title", "Vanity #{spec.version}", "--main", "README.rdoc", "--files", "CHANGELOG"
end
rescue LoadError
end
desc "Jekyll generates the main documentation (sans API)"
task(:jekyll) { sh "jekyll", "doc", "html" }
file "html/vanity.pdf"=>:jekyll do |t|
pages = %w{index metrics ab_testing rails email identity configuring contributing}.map{ |p| "html/#{p}.html" }
args = %w{--disable-javascript --outline --title Vanity --header-html doc/_layouts/_header.html --print-media-type}
args.concat %w{--margin-left 20 --margin-right 20 --margin-top 20 --margin-bottom 20 --header-spacing 5}
args.concat pages << t.name
sh "wkhtmltopdf", *args
end
file "html/vanity-api.zip"=>:yardoc do |t|
Dir.chdir "html" do
sh "zip vanity-api.zip -r api"
end
end
desc "Create documentation in docs directory (including API)"
task :docs=>[:jekyll, :yardoc, "html/vanity-api.zip", "html/vanity.pdf"]
desc "Remove temporary files and directories"
task(:clobber) { rm_rf "html" ; rm_rf ".yardoc" }
desc "Publish documentation to vanity.labnotes.org"
task :publish=>[:clobber, :docs] do
sh "rsync -cr --del --progress html/ labnotes.org:/var/www/vanity/"
end
# -- Misc --
task :report do
$LOAD_PATH.unshift "lib"
require "vanity"
require "timecop"
Vanity.playground.load_path = "test/experiments"
Vanity.playground.experiments.values.each(&:destroy)
Vanity.playground.metrics.values.each(&:destroy!)
Vanity.playground.reload!
# Control 182 35 19.23% N/A
# Treatment A 180 45 25.00% 1.33
# Treatment B 189 28 14.81% -1.13
# Treatment C 188 61 32.45% 2.94
Vanity.playground.experiment(:null_abc).instance_eval do
fake nil=>[182,35], :red=>[180,45], :green=>[189,28], :blue=>[188,61]
@created_at = (Date.today - 40).to_time
@completed_at = (Date.today - 35).to_time
end
Vanity.playground.experiment(:age_and_zipcode).instance_eval do
fake false=>[80,35], true=>[84,32]
@created_at = (Date.today - 30).to_time
@completed_at = (Date.today - 15).to_time
end
Vanity.context = Object.new
Vanity.context.instance_eval { def vanity_identity ; 0 ; end }
signups = 50
(Date.today - 90..Date.today).each do |date|
Timecop.travel date do
signups += rand(15) - 5
Vanity.playground.track! :signups, signups
end
end
cheers, yawns = 0, 0
(Date.today - 80..Date.today).each do |date|
Timecop.travel date do
cheers = cheers - 5 + rand(20)
Vanity.playground.track! :yawns, cheers
yawns = yawns - 5 + rand(30)
Vanity.playground.track! :cheers, yawns
end
end
Vanity::Commands.report ENV["OUTPUT"]
end