~ubuntu-branches/ubuntu/utopic/ruby-excon/utopic

« back to all changes in this revision

Viewing changes to Rakefile

  • Committer: Package Import Robot
  • Author(s): Laurent Bigonville
  • Date: 2012-03-07 16:36:21 UTC
  • Revision ID: package-import@ubuntu.com-20120307163621-bztj2b8860dxpzs7
Tags: upstream-0.10.0
ImportĀ upstreamĀ versionĀ 0.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'rubygems'
 
2
require 'rake'
 
3
require 'date'
 
4
 
 
5
#############################################################################
 
6
#
 
7
# Helper functions
 
8
#
 
9
#############################################################################
 
10
 
 
11
def name
 
12
  @name ||= Dir['*.gemspec'].first.split('.').first
 
13
end
 
14
 
 
15
def version
 
16
  line = File.read("lib/#{name}/constants.rb")[/^\s*VERSION\s*=\s*.*/]
 
17
  line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
 
18
end
 
19
 
 
20
def date
 
21
  Date.today.to_s
 
22
end
 
23
 
 
24
def rubyforge_project
 
25
  name
 
26
end
 
27
 
 
28
def gemspec_file
 
29
  "#{name}.gemspec"
 
30
end
 
31
 
 
32
def gem_file
 
33
  "#{name}-#{version}.gem"
 
34
end
 
35
 
 
36
def replace_header(head, header_name)
 
37
  head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
 
38
end
 
39
 
 
40
#############################################################################
 
41
#
 
42
# Standard tasks
 
43
#
 
44
#############################################################################
 
45
 
 
46
require 'shindo/rake'
 
47
Shindo::Rake.new
 
48
 
 
49
task :default => :tests
 
50
 
 
51
require 'rdoc/task'
 
52
Rake::RDocTask.new do |rdoc|
 
53
  rdoc.rdoc_dir = 'rdoc'
 
54
  rdoc.title = "#{name} #{version}"
 
55
  rdoc.rdoc_files.include('README*')
 
56
  rdoc.rdoc_files.include('lib/**/*.rb')
 
57
end
 
58
 
 
59
desc "Open an irb session preloaded with this library"
 
60
task :console do
 
61
  sh "irb -rubygems -r ./lib/#{name}.rb"
 
62
end
 
63
 
 
64
#############################################################################
 
65
#
 
66
# Custom tasks (add your own tasks here)
 
67
#
 
68
#############################################################################
 
69
 
 
70
 
 
71
 
 
72
#############################################################################
 
73
#
 
74
# Packaging tasks
 
75
#
 
76
#############################################################################
 
77
 
 
78
task :release => :build do
 
79
  unless `git branch` =~ /^\* master$/
 
80
    puts "You must be on the master branch to release!"
 
81
    exit!
 
82
  end
 
83
  sh "gem install pkg/#{name}-#{version}.gem"
 
84
  sh "git commit --allow-empty -a -m 'Release #{version}'"
 
85
  sh "git tag v#{version}"
 
86
  sh "git push origin master"
 
87
  sh "git push origin v#{version}"
 
88
  sh "gem push pkg/#{name}-#{version}.gem"
 
89
end
 
90
 
 
91
task :build => :gemspec do
 
92
  sh "mkdir -p pkg"
 
93
  sh "gem build #{gemspec_file}"
 
94
  sh "mv #{gem_file} pkg"
 
95
end
 
96
 
 
97
task :gemspec => :validate do
 
98
  # read spec file and split out manifest section
 
99
  spec = File.read(gemspec_file)
 
100
  head, manifest, tail = spec.split("  # = MANIFEST =\n")
 
101
 
 
102
  # replace name version and date
 
103
  replace_header(head, :name)
 
104
  replace_header(head, :version)
 
105
  replace_header(head, :date)
 
106
  #comment this out if your rubyforge_project has a different name
 
107
  replace_header(head, :rubyforge_project)
 
108
 
 
109
  # determine file list from git ls-files
 
110
  files = `git ls-files`.
 
111
    split("\n").
 
112
    sort.
 
113
    reject { |file| file =~ /^\./ }.
 
114
    reject { |file| file =~ /^(rdoc|pkg)/ }.
 
115
    map { |file| "    #{file}" }.
 
116
    join("\n")
 
117
 
 
118
  # piece file back together and write
 
119
  manifest = "  s.files = %w[\n#{files}\n  ]\n"
 
120
  spec = [head, manifest, tail].join("  # = MANIFEST =\n")
 
121
  File.open(gemspec_file, 'w') { |io| io.write(spec) }
 
122
  puts "Updated #{gemspec_file}"
 
123
end
 
124
 
 
125
task :validate do
 
126
  libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
 
127
  unless libfiles.empty?
 
128
    puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
 
129
    exit!
 
130
  end
 
131
  unless Dir['VERSION*'].empty?
 
132
    puts "A `VERSION` file at root level violates Gem best practices."
 
133
    exit!
 
134
  end
 
135
end