-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRakefile
More file actions
178 lines (139 loc) · 4.35 KB
/
Copy pathRakefile
File metadata and controls
178 lines (139 loc) · 4.35 KB
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
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'rake/clean'
require 'lib/postview'
# Helpers
# =============================================================================
def rdoc(*args)
@rdoc ||= if Gem.available? "hanna"
["hanna", "--fmt", "html", "--accessor", "option_accessor=RW"]
else
["rdoc"]
end
@rdoc += args
sh @rdoc.join(" ")
end
def test(*args)
@test ||= (Gem.available? "turn") ? ["turn"] : ["testrb", "-v"]
@test += args
sh @test.join(" ")
end
def manifest
@manifest ||= `git ls-files`.split("\n").sort.reject do |out|
out =~ /^\./ || out =~ /^doc/
end.map do |file|
" #{file.inspect}"
end.join(",\n")
end
def history
@history ||= `git log master --date=short --format='%d;%cd;%s;%b;'`
end
def version
@version ||= Postview.version
end
def gemspec
@gemspec ||= Struct.new(:spec, :file).new
@gemspec.file ||= Pathname.new("postview.gemspec")
@gemspec.spec ||= eval @gemspec.file.read
@gemspec
end
# Documentation
# =============================================================================
namespace :doc do
CLOBBER << FileList["doc/*"]
file "doc/api/index.html" => FileList["lib/**/*.rb", "README.md", "CHANGELOG"] do |filespec|
rm_rf "doc"
rdoc "--op", "doc/api",
"--charset", "utf8",
"--main", "'Postview'",
"--title", "'Postview API Documentation'",
"--inline-source",
"--promiscuous",
"--line-numbers",
filespec.prerequisites.join(" ")
end
desc "Build API documentation (doc/api)"
task :api => "doc/api/index.html"
desc "Creates/updates CHANGELOG file."
task :changelog do |spec|
File.open("CHANGELOG", "w+") do |changelog|
history.scan(/(.*?);(.*?);(.*?);(.*?);/m) do |tag, date, subject, content|
tag.gsub! /[\n\( ].*?:[\) ]|,.*,.*[\)\n ]|[\)\n ]/m, ""
tag = tag.empty? ? "v0.0.0" : "v#{tag}"
changelog << "== #{tag} - #{date} - #{subject}\n"
changelog << "\n#{content}\n"
end
end
puts "Successfully updated CHANGELOG file"
end
end
# Versioning
# =============================================================================
namespace :version do
major, minor, patch, build = version.tag.split(".").map{ |key| key.to_i } << 0
desc "Dump major version"
task :major do
version.tag = "#{major+=1}.0.0"
version.save!
puts version.to_hash.to_yaml
end
desc "Dump minor version"
task :minor do
version.tag = "#{major}.#{minor+=1}.0"
version.save!
puts version.to_hash.to_yaml
end
desc "Dump patch version"
task :patch do
version.tag = "#{major}.#{minor}.#{patch+=1}"
version.save!
puts version.to_hash.to_yaml
end
desc "Dump build version"
task :build do
version.tag = "#{major}.#{minor}.#{patch}.#{build+=1}"
version.save!
puts version.to_hash.to_yaml
end
end
task :version => "version:build"
# RubyGems
# =============================================================================
namespace :gem do
file gemspec.file => FileList["{lib,test}/**", "Rakefile"] do
spec = gemspec.file.read
spec.sub! /spec\.version\s*=\s*".*?"/, "spec.version = #{version.tag.inspect}"
spec.sub! /spec\.date\s*=\s*".*?"/, "spec.date = #{version.date.to_s.inspect}"
spec.sub! /spec\.files\s*=\s*\[.*?\]/m, "spec.files = [\n#{manifest}\n ]"
gemspec.file.open("w+") { |file| file << spec }
puts "Successfully update #{gemspec.file} file"
end
desc "Build gem package #{gemspec.spec.file_name}"
task :build => gemspec.file do
sh "gem build #{gemspec.file}"
end
desc "Deploy gem package to GemCutter.org"
task :deploy => :build do
sh "gem push #{gemspec.spec.file_name}"
end
desc "Install gem package #{gemspec.spec.file_name}"
task :install => :build do
sh "gem install #{gemspec.spec.file_name} --local"
end
desc "Uninstall gem package #{gemspec.spec.file_name}"
task :uninstall do
sh "gem uninstall #{gemspec.spec.name} --version #{gemspec.spec.version}"
end
end
# Test
# =============================================================================
desc "Run tests"
task :test, [:pattern] do |spec, args|
if args[:pattern]
test "test/#{args[:pattern]}*_test.rb"
else
test "test/*_test.rb"
end
end
# Default
# =============================================================================
task :default => "test"