-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
349 lines (301 loc) · 10.5 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
require 'date'
require 'digest/md5'
require 'fileutils'
require 'nokogiri'
basedir = "."
build = "#{basedir}/build"
source = "#{basedir}/library"
desc "Task used by Jenkins-CI"
task :jenkins => [:prepare, :lint, :composer, :test, :apidocs, :phploc, :phpcs_ci, :phpcb, :phpcpd, :pdepend, :phpmd, :phpmd_html]
desc "Task used by Travis-CI"
task :travis => [:composer, :test]
desc "Default task"
task :default => [:lint, :composer, :test, :phpcs, :apidocs, :readthedocs]
desc "Spell check and generate end user docs"
task :readthedocs do
wd = Dir.getwd
Dir.chdir("docs")
begin
sh %{make spelling}
rescue Exception
puts "Spelling error in the docs, aborting"
exit 1
end
puts "No spelling errors. Generate docs"
sh %{make html}
Dir.chdir(wd)
end
desc "Clean up and create artifact directories"
task :prepare do
FileUtils.rm_rf build
FileUtils.mkdir build
["coverage", "logs", "docs", "code-browser", "pdepend"].each do |d|
FileUtils.mkdir "#{build}/#{d}"
end
end
desc "Fetch or update composer.phar and update the dependencies"
task :composer do
if ENV["TRAVIS"] == "true"
system "composer --no-ansi update --dev"
else
if File.exists?("composer.phar")
system "php -d \"apc.enable_cli=0\" composer.phar self-update"
else
system "curl -s http://getcomposer.org/installer | php -d \"apc.enable_cli=0\""
end
system "php -d \"apc.enable_cli=0\" composer.phar --no-ansi update --dev"
end
end
desc "Generate checkstyle.xml using PHP_CodeSniffer"
task :phpcs_ci do
system "phpcs --report=checkstyle --report-file=#{build}/logs/checkstyle.xml --standard=Imbo #{source}"
end
desc "Check CS"
task :phpcs do
system "phpcs --standard=Imbo #{source}"
end
desc "Aggregate tool output with PHP_CodeBrowser"
task :phpcb do
system "phpcb --log #{build}/logs --source #{source} --output #{build}/code-browser"
end
desc "Generate pmd-cpd.xml using PHPCPD"
task :phpcpd do
system "phpcpd --log-pmd #{build}/logs/pmd-cpd.xml #{source}"
end
desc "Generate jdepend.xml and software metrics charts using PHP_Depend"
task :pdepend do
system "pdepend --jdepend-xml=#{build}/logs/jdepend.xml --jdepend-chart=#{build}/pdepend/dependencies.svg --overview-pyramid=#{build}/pdepend/overview-pyramid.svg #{source}"
end
desc "Generate pmd.xml using PHPMD (configuration in phpmd.xml)"
task :phpmd do
system "phpmd #{source} xml #{basedir}/phpmd.xml --reportfile #{build}/logs/pmd.xml"
end
desc "Generate pmd.html using PHPMD (configuration in phpmd.xml)"
task :phpmd_html do
system "phpmd #{source} html #{basedir}/phpmd.xml --reportfile #{build}/logs/pmd.html"
end
desc "Generate phploc data"
task :phploc do
system "phploc --log-csv #{build}/logs/phploc.csv --log-xml #{build}/logs/phploc.xml #{source}"
end
desc "Generate API documentation using phpdoc"
task :apidocs do
system "phpdoc -d #{source} -t #{build}/docs"
end
desc "Check syntax on all php files in the project"
task :lint do
`git ls-files "*.php"`.split("\n").each do |f|
begin
sh %{php -l #{f}}
rescue Exception
exit 1
end
end
end
desc "Run PHPUnit tests (config in phpunit.xml)"
task :test do
if ENV["TRAVIS"] == "true"
system "sudo apt-get install -y php5-sqlite libmagickcore-dev libjpeg-dev libdjvulibre-dev libmagickwand-dev"
ini_file = Hash[`php --ini`.split("\n").map {|l| l.split(/:\s+/)}]["Loaded Configuration File"]
{"imagick" => "3.1.0RC2", "mongo" => "1.2.12", "memcached" => "2.0.1", "APC" => "3.1.12"}.each { |package, version|
filename = "#{package}-#{version}.tgz"
system "wget http://pecl.php.net/get/#{filename}"
system "tar -xzf #{filename}"
system "sh -c \"cd #{filename[0..-5]} && phpize && ./configure && make && sudo make install\""
system "sudo sh -c \"echo 'extension=#{package.downcase}.so' >> #{ini_file}\""
}
system "sudo sh -c \"echo 'apc.enable_cli=on' >> #{ini_file}\""
puts "Opening phpunit.xml.dist"
document = Nokogiri::XML(File.open("phpunit.xml.dist"))
document.xpath("//phpunit/php/var[@name='MEMCACHED_HOST']").first["value"] = "127.0.0.1"
document.xpath("//phpunit/php/var[@name='MEMCACHED_PORT']").first["value"] = "11211"
document.xpath("//phpunit/logging").remove
puts "Writing edited version of phpunit.xml"
File.open("phpunit.xml", "w+") do |f|
f.write(document.to_xml)
end
end
if File.exists?("phpunit.xml")
begin
sh %{phpunit --verbose -c phpunit.xml}
rescue Exception
exit 1
end
else
puts "phpunit.xml does not exist"
exit 1
end
end
desc "Create a PEAR package"
task :pear, :version do |t, args|
version = args[:version]
if /^[\d]+\.[\d]+\.[\d]+$/ =~ version
now = DateTime.now
hash = Digest::MD5.new
xml = Nokogiri::XML::Builder.new { |xml|
xml.package(:version => "2.0", :xmlns => "http://pear.php.net/dtd/package-2.0", "xmlns:tasks" => "http://pear.php.net/dtd/tasks-1.0", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => ["http://pear.php.net/dtd/tasks-1.0", "http://pear.php.net/dtd/tasks-1.0.xsd", "http://pear.php.net/dtd/package-2.0", "http://pear.php.net/dtd/package-2.0.xsd"].join(" ")) {
xml.name "Imbo"
xml.channel "pear.starzinger.net"
xml.summary "RESTful image server"
xml.description "Imbo is a RESTful image server written in PHP. Imbo lets you store original hi-res images along with optional metadata and enables you to fast and easily fetch variations of the originals (thumbnails, resized versions, cropped versions and so forth)."
xml.lead {
xml.name "Christer Edvartsen"
xml.user "christeredvartsen"
xml.email "[email protected]"
xml.active "yes"
}
xml.developer {
xml.name "Espen Hovlandsdal"
xml.user "rexxars"
xml.email "[email protected]"
xml.active "yes"
}
xml.date now.strftime('%Y-%m-%d')
xml.time now.strftime('%H:%M:%S')
xml.version {
xml.release version
xml.api version
}
xml.stability {
xml.release "beta"
xml.api "beta"
}
xml.license "MIT", :uri => "http://www.opensource.org/licenses/mit-license.php"
xml.notes "http://github.com/imbo/imbo/blob/#{version}/README.markdown"
xml.contents {
xml.dir(:name => "/", :baseinstalldir => "Imbo") {
# Library files
`git ls-files library public config|grep -v Version.php`.split("\n").each { |f|
xml.file(:md5sum => hash.hexdigest(File.read(f)), :role => "php", :name => f)
}
# Add a replace task to the Version.php file
xml.file(:md5sum => hash.hexdigest(File.read("library/Imbo/Version.php")), :role => "php", :name => "library/Imbo/Version.php") {
xml["tasks"].replace(:from => "@package_version@", :to => "version", :type => "package-info")
}
# Doc files
["README.markdown", "LICENSE", "ChangeLog.markdown"].each { |f|
xml.file(:md5sum => hash.hexdigest(File.read(f)), :role => "doc", :name => f)
}
}
}
xml.dependencies {
xml.required {
xml.php {
xml.min "5.3.2"
}
xml.pearinstaller {
xml.min "1.9.0"
}
xml.extension {
xml.name "spl"
}
xml.extension {
xml.name "imagick"
}
xml.extension {
xml.name "mongo"
xml.min "1.2.10"
}
}
xml.optional {
xml.package {
xml.name "DoctrineDBAL"
xml.channel "http://pear.doctrine-project.org"
xml.min "2.2.2"
}
xml.extension {
xml.name "memcached"
}
xml.extension {
xml.name "apc"
}
}
}
xml.phprelease
}
}
# Write XML to package.xml
File.open("package.xml", "w") { |f|
f.write(xml.to_xml)
}
# Generate pear package
system "pear package"
# Remove tmp files
File.unlink("package.xml")
else
puts "'#{version}' is not a valid version"
exit 1
end
end
desc "Publish a PEAR package to pear.starzinger.net"
task :publish, :version do |t, args|
version = args[:version]
if /^[\d]+\.[\d]+\.[\d]+$/ =~ version
package = "Imbo-#{version}.tgz"
if File.exists?(package)
wd = Dir.getwd
system "pirum add /home/christer/dev/christeredvartsen.github.com #{package}"
Dir.chdir("/home/christer/dev/christeredvartsen.github.com")
system "git add --all"
system "git commit -a -m 'Added #{package[0..-5]}'"
system "git push"
Dir.chdir(wd)
File.unlink(package)
else
puts "#{package} does not exist. Run the pear task first to create the package"
end
else
puts "'#{version}' is not a valid version"
exit 1
end
end
desc "Tag current state of the master branch and push it to GitHub"
task :github, :version do |t, args|
version = args[:version]
if /^[\d]+\.[\d]+\.[\d]+$/ =~ version
system "git checkout master"
system "git merge develop"
system "git tag #{version}"
system "git push"
system "git push --tags"
else
puts "'#{version}' is not a valid version"
exit 1
end
end
desc "Publish API docs"
task :publish_api_docs do
system "git checkout master"
Rake::Task["apidocs"].invoke
wd = Dir.getwd
Dir.chdir("/home/christer/dev/imbo-ghpages")
system "git pull origin gh-pages"
system "cp -r #{wd}/build/docs/* ."
system "git add --all"
system "git commit -a -m 'Updated API docs [ci skip]'"
system "git push origin gh-pages"
Dir.chdir(wd)
end
desc "Release a new version (builds PEAR package, updates PEAR channel and pushes tag to GitHub)"
task :release, :version do |t, args|
version = args[:version]
if /^[\d]+\.[\d]+\.[\d]+$/ =~ version
# Syntax check
Rake::Task["lint"].invoke
# Unit tests
Rake::Task["test"].invoke
# Generate end-user docs
Rake::Task["readthedocs"].invoke
# Build PEAR package
Rake::Task["pear"].invoke(version)
# Publish to the PEAR channel
Rake::Task["publish"].invoke(version)
# Tag the current state of master and push to GitHub
Rake::Task["github"].invoke(version)
# Update the API docs and push to gh-pages
Rake::Task["publish_api_docs"].invoke
else
puts "'#{version}' is not a valid version"
exit 1
end
end