forked from drslump/Protobuf-PHP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
163 lines (122 loc) · 3.75 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
# encoding: utf-8
namespace :pear do
support_files = ['README.md', 'LICENSE', 'protoc-gen-php.php', 'protoc-gen-php.bat']
tpl_file = 'package.pear'
xml_file = 'library/package.xml'
desc "Generate package.xml"
task :xml => [:clean] do |t, args|
unless ENV['version'] then
puts 'Version number not given. Use "pear:xml version=1.0"'
exit 1
end
# Get template contents
text = File.read(tpl_file, :encoding => "UTF-8")
# Replace the version, date and time
text = text.gsub("{VERSION}", ENV['version'])
text = text.gsub('{DATE}', Time.now.strftime('%Y-%m-%d'))
text = text.gsub('{TIME}', Time.now.strftime('%H:%M:%S'))
# Include source files
dirs = []
Dir.glob('library/**/*.*') do |file|
file[0, 'library/'.length] = ''
dirs << '<file name="' + file + '" role="php">'
dirs << '<tasks:replace from="@package_version@" to="version" type="package-info" />'
dirs << '</file>'
end
text = text.gsub('{DIRS}', dirs.join("\n"))
# Generate a new pear package.xml
xml = File.new(xml_file, 'w')
xml.syswrite(text);
xml.close();
end
desc "Build a release"
task :package => ['doc:build', :xml] do
# Copy supporting files to the package root
support_files.each do |file|
cp file, "library/#{file}"
end
begin
sh "pear package -n #{xml_file}"
rescue Exception => e
puts "Rolling back..."
Rake::Task['pear:clean'].execute
raise
end
Rake::Task['pear:clean'].execute
end
desc "Clean up"
task :clean do
puts "Cleaning up..."
# Remove package.xml
rm_f xml_file
# Remove supporting files
support_files.each { |file| rm_f "library/#{file}" }
end
end
namespace :phar do
phar_file = "protobuf.phar"
desc "Build a phar archive"
task :build do
unless ENV['version'] then
puts 'Version number not given. Use "phar:build version=1.0"'
exit 1
end
puts "Creating a temporary directory with the files..."
# Create a temporary directory
tmp_dest = "/tmp/phar-#{Time.now.to_i}"
mkdir_p tmp_dest
# Copy library files there
cp_r "library/", tmp_dest
# Process copied files, replacing @package_version@
version = ENV['version'] + '-phar'
FileList["#{tmp_dest}/**/*.php"].each do |fpath|
puts fpath
sh "sed -i.bak 's/@package_version@/#{version}/g' #{fpath}"
end
puts "Launching phar builder..."
sh "phar pack -f #{phar_file} -s protoc-gen-php.php -c bz2 -h sha1 #{tmp_dest}/library"
puts "Cleaning up temporary directory..."
rm_r tmp_dest
end
desc "Clean up"
task :clean do
puts "Cleaning up..."
# Remove the phar file
rm_f phar_file
end
end
namespace :doc do
desc "Generate manual"
task :build do
version = ENV['version']
ENV['RONN_MANUAL'] = "Protobuf-PHP #{version}"
ENV['RONN_ORGANIZATION'] = "Ivan -DrSlump- Montes"
sh "ronn -w -s toc -r5 --markdown man/*.ronn"
end
desc 'Publish to github pages'
task :github => 'doc:build' do
require 'git'
require 'logger'
remote = `git remote show origin`
.split(%r{\n}) # Ruby 1.9 only has grep() on Array
.grep(/Push.*URL/)
.first[/git@.*/]
files = [
'protoc-gen-php.1.html',
'protobuf-php.3.html',
'protobuf-php.5.html',
]
root = "/tmp/checkout-#{Time.now.to_i}"
g = Git.clone(remote, root, :log => Logger.new(STDOUT))
# Make sure this actually switches branches.
g.checkout(g.branch('gh-pages'))
files.each {|file|
cp "man/#{file}", "#{root}/."
g.add(file)
}
g.commit('Regenerating Github Pages.')
# PUSH!
g.push(g.remote('origin'), g.branch('gh-pages'))
puts '--> GitHub Pages Commit and Push successful.'
end
end