forked from mislav/hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
171 lines (137 loc) · 4.15 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
require 'rake/testtask'
#
# Helpers
#
def command?(util)
Rake::Task[:load_path].invoke
context = Object.new
require 'hub/context'
context.extend Hub::Context
context.send(:command?, util)
end
task :load_path do
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
end
task :check_dirty do
unless system 'git', 'diff', '--quiet', 'HEAD'
abort "Aborted: you have uncommitted changes"
end
end
#
# Tests
#
task :default => [:test, :features]
Rake::TestTask.new do |t|
t.libs << 'test'
t.ruby_opts << '-rubygems'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
task :features do
sh 'RUBYLIB=lib cucumber -f progress -t ~@wip features'
end
#
# Manual
#
if command? :ronn
desc "Show man page"
task :man => "man:build" do
exec "man man/hub.1"
end
desc "Build man pages"
task "man:build" => ["man/hub.1", "man/hub.1.html"]
extract_examples = lambda { |readme_file|
# split readme in sections
examples = File.read(readme_file).split(/^-{4,}$/)[3].strip
examples.sub!(/^.+?(###)/m, '\1') # strip intro paragraph
examples.sub!(/\n+.+\Z/, '') # remove last line
examples
}
# inject examples from README file to .ronn source
source_with_examples = lambda { |source, readme|
examples = extract_examples.call(readme)
compiled = File.read(source)
compiled.sub!('{{README}}', examples)
compiled
}
# generate man page with ronn
compile_ronn = lambda { |destination, type, contents|
File.popen("ronn --pipe --#{type} --organization=DEFUNKT --manual='Git Manual'", 'w+') { |io|
io.write contents
io.close_write
File.open(destination, 'w') { |f| f << io.read }
}
abort "ronn --#{type} conversion failed" unless $?.success?
}
file "man/hub.1" => ["man/hub.1.ronn", "README.md"] do |task|
contents = source_with_examples.call(*task.prerequisites)
compile_ronn.call(task.name, 'roff', contents)
compile_ronn.call("#{task.name}.html", 'html', contents)
end
file "man/hub.1.html" => ["man/hub.1.ronn", "README.md"] do |task|
Rake::Task["man/hub.1"].invoke
end
end
#
# Build
#
file "hub" => FileList.new("lib/hub.rb", "lib/hub/*.rb", "man/hub.1") do |task|
Rake::Task[:load_path].invoke
require 'hub/standalone'
Hub::Standalone.save(task.name)
end
desc "Build standalone script"
task :standalone => "hub"
desc "Install standalone script and man pages"
task :install => "hub" do
prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
FileUtils.mkdir_p "#{prefix}/bin"
FileUtils.cp "hub", "#{prefix}/bin", :preserve => true
FileUtils.mkdir_p "#{prefix}/share/man/man1"
FileUtils.cp "man/hub.1", "#{prefix}/share/man/man1"
end
#
# Release
#
task :release => [:pages, :gem_release, :homebrew]
desc "Copy files to gh-pages branch, but don't publish"
task :gh_pages => [:check_dirty, "hub", "man/hub.1.html"] do
cp "man/hub.1.html", "html"
sh "git checkout gh-pages"
# replace the specific shebang with a generic ruby one
sh "echo '#!/usr/bin/env' ruby > standalone"
sh "sed 1d hub >> standalone"
mv "html", "hub.1.html"
sh "git add standalone hub.1.html"
sh "git commit -m 'update standalone'"
end
desc "Publish to GitHub Pages"
task :pages => :gh_pages do
sh "git push origin gh-pages"
sh "git checkout master"
puts "Done."
end
task :gem_release do
sh "gem release -t"
end
desc "Publish to Homebrew"
task :homebrew do
require File.expand_path('../lib/hub/version', __FILE__)
Dir.chdir `brew --prefix`.chomp do
sh 'git checkout -q master'
sh 'git pull -q origin master'
formula_file = 'Library/Formula/hub.rb'
md5 = `curl -#L https://github.com/defunkt/hub/tarball/v#{Hub::VERSION} | md5`.chomp
abort unless $?.success? and md5.length == 32
formula = File.read formula_file
formula.sub! /\bv\d+(\.\d+)*/, "v#{Hub::VERSION}"
formula.sub! /\b[0-9a-f]{32}\b/, md5
File.open(formula_file, 'w') {|f| f << formula }
branch = "hub-v#{Hub::VERSION}"
sh "git checkout -q -B #{branch}"
sh "git commit -m 'upgrade hub to v#{Hub::VERSION}' -- #{formula_file}"
sh "git push -u mislav #{branch}"
sh "hub pull-request 'upgrade hub to v#{Hub::VERSION}'"
sh "git checkout -q master"
end
end