Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 123 lines (101 sloc) 3.15 kb
e34cc43 @therubymug Modernize gem deployment
authored
1 #############################################################################
2 #
3 # Helper functions
4 #
5 #############################################################################
6
7 def name
8 @name ||= Dir['*.gemspec'].first.split('.').first
9 end
10
11 def version
12 line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
13 line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
14 end
15
16 def date
17 Date.today.to_s
18 end
19
20 def gemspec_file
21 "#{name}.gemspec"
22 end
23
24 def gem_file
25 "#{name}-#{version}.gem"
26 end
27
28 def replace_header(head, header_name)
29 head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
30 end
31
32 #############################################################################
33 #
34 # Standard tasks
35 #
36 #############################################################################
37
38 require 'rspec'
7b6cbb3 Bump rspec to 2.6.0
Rogelio J. Samour authored
39 require 'rspec/core/rake_task'
9218dc2 @therubymug Add default rake task
authored
40
e34cc43 @therubymug Modernize gem deployment
authored
41 desc "Run all specs"
42 task RSpec::Core::RakeTask.new('spec')
43
44 task :default => "spec"
45
46 desc "Open an irb session preloaded with this library"
47 task :console do
48 sh "irb -rubygems -r ./lib/#{name}.rb"
49 end
50
51 #############################################################################
52 #
53 # Custom tasks (add your own tasks here)
54 #
55 #############################################################################
56
57
58 #############################################################################
59 #
60 # Packaging tasks
61 #
62 #############################################################################
63
64 desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
65 task :release => :build do
66 unless `git branch` =~ /^\* master$/
67 puts "You must be on the master branch to release!"
68 exit!
69 end
70 sh "git commit --allow-empty -a -m 'Release #{version}'"
71 sh "git tag v#{version}"
72 sh "git push origin master"
73 sh "git push origin v#{version}"
74 sh "gem push pkg/#{name}-#{version}.gem"
75 end
76
77 desc "Build #{gem_file} into the pkg directory"
78 task :build => :gemspec do
79 sh "mkdir -p pkg"
80 sh "gem build #{gemspec_file}"
81 sh "mv #{gem_file} pkg"
82 end
83
84 desc "Generate #{gemspec_file}"
85 task :gemspec => :validate do
86 # read spec file and split out manifest section
87 spec = File.read(gemspec_file)
88 head, manifest, tail = spec.split(" # = MANIFEST =\n")
89
90 # replace name version and date
91 replace_header(head, :name)
92 replace_header(head, :version)
93 replace_header(head, :date)
94
95 # determine file list from git ls-files
96 files = `git ls-files`.
97 split("\n").
98 sort.
99 reject { |file| file =~ /^\./ }.
100 reject { |file| file =~ /^(rdoc|pkg)/ }.
101 map { |file| " #{file}" }.
102 join("\n")
103
104 # piece file back together and write
105 manifest = " s.files = %w[\n#{files}\n ]\n"
106 spec = [head, manifest, tail].join(" # = MANIFEST =\n")
107 File.open(gemspec_file, 'w') { |io| io.write(spec) }
108 puts "Updated #{gemspec_file}"
109 end
110
111 desc "Validate #{gemspec_file}"
112 task :validate do
113 libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
114 unless libfiles.empty?
115 puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
116 exit!
117 end
118 unless Dir['VERSION*'].empty?
119 puts "A `VERSION` file at root level violates Gem best practices."
120 exit!
121 end
122 end
Something went wrong with that request. Please try again.