forked from RiotGamesMinions/motherbrain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathThorfile
123 lines (100 loc) · 3.09 KB
/
Thorfile
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
# encoding: utf-8
$:.push File.expand_path("../lib", __FILE__)
require 'bundler'
require 'bundler/setup'
require 'thor/rake_compat'
require 'motherbrain'
MB::Logging.setup(location: '/dev/null')
class Default < Thor
include Thor::Actions
include Thor::RakeCompat
Bundler::GemHelper.install_tasks
desc "build", "Build motherbrain-#{MotherBrain::VERSION}.gem into the pkg directory"
def build
Rake::Task["build"].execute
end
desc "install", "Build and install motherbrain-#{MotherBrain::VERSION}.gem into system gems"
def install
Rake::Task["install"].execute
end
desc "release", "Create tag v#{MotherBrain::VERSION} and build and push motherbrain-#{MotherBrain::VERSION}.gem to gem in a box"
def release
Rake::Task["release"].execute
end
desc "ci", "Run all tests"
def ci
ENV['CI'] = 'true' # Travis-CI also sets this, but set it here for local testing
run "rspec --tag ~focus --color --format=progress spec"
exit $?.exitstatus unless $?.success?
run "cucumber --format progress"
exit $?.exitstatus unless $?.success?
end
desc "routes", "Print all registered REST API routes"
def routes
puts MB::API::Application.routes
end
desc "manpage", "Re-generate the man pages"
def manpage
require MB.app_root.join('man', 'man_helper')
say "Generating man page ronn source"
MB::ManHelper.generate('man/mb.1.ronn.erb', 'man/mb.1.ronn')
run "ronn man/mb.1.ronn"
end
class Cucumber < Thor
namespace :cucumber
default_task :all
desc "all", "run all tests"
def all
exec "cucumber --require features --tags ~@wip"
end
end
class Spec < Thor
namespace :spec
default_task :all
desc "all", "run all tests"
def all
exec "rspec --color --format=documentation spec"
end
desc "unit", "run only unit tests"
def unit
exec "rspec --color --format=documentation spec --tag ~type:acceptance"
end
desc "acceptance", "run only acceptance tests"
def acceptance
exec "rspec --color --format=documentation spec --tag type:acceptance"
end
end
private
def clean?
sh_with_excode("git diff --exit-code")[1] == 0
end
def tag_version
sh "git tag -a -m \"Version #{MotherBrain::VERSION}\" #{MotherBrain::VERSION}"
say "Tagged: #{MotherBrain::VERSION}", :green
yield if block_given?
sh "git push --tags"
rescue => e
say "Untagging: #{MotherBrain::VERSION} due to error", :red
sh_with_excode "git tag -d #{MotherBrain::VERSION}"
say e, :red
exit 1
end
def source_root
Pathname.new File.dirname(File.expand_path(__FILE__))
end
def sh(cmd, dir = source_root, &block)
out, code = sh_with_excode(cmd, dir, &block)
code == 0 ? out : raise(out.empty? ? "Running `#{cmd}` failed. Run this command directly for more detailed output." : out)
end
def sh_with_excode(cmd, dir = source_root, &block)
cmd << " 2>&1"
outbuf = ''
Dir.chdir(dir) {
outbuf = `#{cmd}`
if $? == 0
block.call(outbuf) if block
end
}
[ outbuf, $? ]
end
end