-
Notifications
You must be signed in to change notification settings - Fork 7
/
Thorfile
86 lines (70 loc) · 2.01 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
$:.push File.expand_path("../lib", __FILE__)
require 'ruby-wmi/version'
class Default < Thor
class_option :verbose,
:type => :boolean,
:aliases => "-v",
:default => false
desc "build", "Build the ruby-wmi gem"
def build
invoke :clean
sh("gem build -V '#{source_root.join("ruby-wmi.gemspec")}'", source_root)
FileUtils.mv(Dir.glob("*.gem"), "pkg/")
rescue => e
say e, :red
exit 1
end
desc "clean", "Clean the project"
def clean
FileUtils.mkdir_p(pkg_path)
Dir[pkg_path.join("*")].each { |f| FileUtils.rm(f, :force => true) }
end
desc "release", "Create a tag from the gem version, build, and push the ruby-wmi gem to rubygems"
def release
unless clean?
say "There are files that need to be committed first.", :red
exit 1
end
invoke :clean
invoke :build
tag_version {
sh("gem push #{pkg_path.join("ruby-wmi-#{RubyWMI::VERSION}.gem")}")
}
end
private
def clean?
sh_with_excode("git diff --exit-code")[1] == 0
end
def pkg_path
source_root.join("pkg")
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
def source_root
Pathname.new File.dirname(File.expand_path(__FILE__))
end
def tag_version
sh "git tag -a -m \"Version #{RubyWMI::VERSION}\" #{RubyWMI::VERSION}"
say "Tagged: #{RubyWMI::VERSION}", :green
yield if block_given?
sh "git push --tags"
rescue => e
say "Untagging: #{RubyWMI::VERSION} due to error", :red
sh_with_excode "git tag -d #{RubyWMI::VERSION}"
say e, :red
exit 1
end
end