|
Maxious
|
1 |
# encoding: utf-8 |
|
|
2 |
namespace :pear do |
|
|
3 |
|
|
|
4 |
support_files = ['README.md', 'LICENSE', 'protoc-gen-php.php', 'protoc-gen-php.bat'] |
|
|
5 |
tpl_file = 'package.pear' |
|
|
6 |
xml_file = 'library/package.xml' |
|
|
7 |
|
|
|
8 |
desc "Generate package.xml" |
|
|
9 |
task :xml => [:clean] do |t, args| |
|
|
10 |
unless ENV['version'] then |
|
|
11 |
puts 'Version number not given. Use "pear:xml version=1.0"' |
|
|
12 |
exit 1 |
|
|
13 |
end |
|
|
14 |
|
|
|
15 |
# Get template contents |
|
|
16 |
text = File.read(tpl_file, :encoding => "UTF-8") |
|
|
17 |
# Replace the version, date and time |
|
|
18 |
text = text.gsub("{VERSION}", ENV['version']) |
|
|
19 |
text = text.gsub('{DATE}', Time.now.strftime('%Y-%m-%d')) |
|
|
20 |
text = text.gsub('{TIME}', Time.now.strftime('%H:%M:%S')) |
|
|
21 |
|
|
|
22 |
# Include source files |
|
|
23 |
dirs = [] |
|
|
24 |
Dir.glob('library/**/*.*') do |file| |
|
|
25 |
file[0, 'library/'.length] = '' |
|
|
26 |
dirs << '<file name="' + file + '" role="php">' |
|
|
27 |
dirs << '<tasks:replace from="@package_version@" to="version" type="package-info" />' |
|
|
28 |
dirs << '</file>' |
|
|
29 |
end |
|
|
30 |
|
|
|
31 |
text = text.gsub('{DIRS}', dirs.join("\n")) |
|
|
32 |
|
|
|
33 |
# Generate a new pear package.xml |
|
|
34 |
xml = File.new(xml_file, 'w') |
|
|
35 |
xml.syswrite(text); |
|
|
36 |
xml.close(); |
|
|
37 |
end |
|
|
38 |
|
|
|
39 |
desc "Build a release" |
|
|
40 |
task :package => ['doc:build', :xml] do |
|
|
41 |
|
|
|
42 |
# Copy supporting files to the package root |
|
|
43 |
|
|
|
44 |
support_files.each do |file| |
|
|
45 |
cp file, "library/#{file}" |
|
|
46 |
end |
|
|
47 |
|
|
|
48 |
begin |
|
|
49 |
sh "pear package -n #{xml_file}" |
|
|
50 |
rescue Exception => e |
|
|
51 |
puts "Rolling back..." |
|
|
52 |
Rake::Task['pear:clean'].execute |
|
|
53 |
raise |
|
|
54 |
end |
|
|
55 |
|
|
|
56 |
Rake::Task['pear:clean'].execute |
|
|
57 |
end |
|
|
58 |
|
|
|
59 |
desc "Clean up" |
|
|
60 |
task :clean do |
|
|
61 |
puts "Cleaning up..." |
|
|
62 |
|
|
|
63 |
# Remove package.xml |
|
|
64 |
rm_f xml_file |
|
|
65 |
|
|
|
66 |
# Remove supporting files |
|
|
67 |
support_files.each { |file| rm_f "library/#{file}" } |
|
|
68 |
end |
|
|
69 |
|
|
|
70 |
end |
|
|
71 |
|
|
|
72 |
namespace :doc do |
|
|
73 |
|
|
|
74 |
desc "Generate manual" |
|
|
75 |
task :build do |
|
|
76 |
version = ENV['version'] |
|
|
77 |
ENV['RONN_MANUAL'] = "Protobuf-PHP #{version}" |
|
|
78 |
ENV['RONN_ORGANIZATION'] = "Ivan -DrSlump- Montes" |
|
|
79 |
sh "ronn -w -s toc -r5 --markdown man/*.ronn" |
|
|
80 |
end |
|
|
81 |
|
|
|
82 |
desc 'Publish to github pages' |
|
|
83 |
task :github => 'doc:build' do |
|
|
84 |
require 'git' |
|
|
85 |
require 'logger' |
|
|
86 |
|
|
|
87 |
remote = `git remote show origin` |
|
|
88 |
.split(%r{\n}) # Ruby 1.9 only has grep() on Array |
|
|
89 |
.grep(/Push.*URL/) |
|
|
90 |
.first[/git@.*/] |
|
|
91 |
|
|
|
92 |
files = [ |
|
|
93 |
'protoc-gen-php.1.html', |
|
|
94 |
'protobuf-php.3.html', |
|
|
95 |
'protobuf-php.5.html', |
|
|
96 |
] |
|
|
97 |
|
|
|
98 |
root = "/tmp/checkout-#{Time.now.to_i}" |
|
|
99 |
g = Git.clone(remote, root, :log => Logger.new(STDOUT)) |
|
|
100 |
|
|
|
101 |
# Make sure this actually switches branches. |
|
|
102 |
g.checkout(g.branch('gh-pages')) |
|
|
103 |
|
|
|
104 |
files.each {|file| |
|
|
105 |
cp "man/#{file}", "#{root}/." |
|
|
106 |
g.add(file) |
|
|
107 |
} |
|
|
108 |
|
|
|
109 |
g.commit('Regenerating Github Pages.') |
|
|
110 |
|
|
|
111 |
# PUSH! |
|
|
112 |
g.push(g.remote('origin'), g.branch('gh-pages')) |
|
|
113 |
|
|
|
114 |
puts '--> GitHub Pages Commit and Push successful.' |
|
|
115 |
end |
|
|
116 |
|
|
|
117 |
end |
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|