Try to adapt to new route destination detection
[busui.git] / lib / Protobuf-PHP / 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
# 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 :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