Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 150 lines (125 sloc) 3.722 kb
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
1 require 'rubygems'
518385c @mojombo switch ot using Jeweler for packaging tasks, and up to version 1.0.0
mojombo authored
2 require 'rake'
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
3 require 'date'
518385c @mojombo switch ot using Jeweler for packaging tasks, and up to version 1.0.0
mojombo authored
4
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
5 #############################################################################
6 #
7 # Helper functions
8 #
9 #############################################################################
518385c @mojombo switch ot using Jeweler for packaging tasks, and up to version 1.0.0
mojombo authored
10
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
11 def name
12 @name ||= Dir['*.gemspec'].first.split('.').first
634396b @mojombo initial grit setup
mojombo authored
13 end
14
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
15 def version
16 line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17 line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
518385c @mojombo switch ot using Jeweler for packaging tasks, and up to version 1.0.0
mojombo authored
18 end
19
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
20 def date
21 Date.today.to_s
22 end
0826e1a @mojombo update history and rakefile for 1.1.1
mojombo authored
23
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
24 def rubyforge_project
25 name
26 end
0826e1a @mojombo update history and rakefile for 1.1.1
mojombo authored
27
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
28 def gemspec_file
29 "#{name}.gemspec"
30 end
0826e1a @mojombo update history and rakefile for 1.1.1
mojombo authored
31
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
32 def gem_file
33 "#{name}-#{version}.gem"
34 end
0826e1a @mojombo update history and rakefile for 1.1.1
mojombo authored
35
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
36 def replace_header(head, header_name)
37 head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
0826e1a @mojombo update history and rakefile for 1.1.1
mojombo authored
38 end
39
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
40 #############################################################################
41 #
42 # Standard tasks
43 #
44 #############################################################################
45
518385c @mojombo switch ot using Jeweler for packaging tasks, and up to version 1.0.0
mojombo authored
46 task :default => :test
47
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
48 require 'rake/testtask'
49 Rake::TestTask.new(:test) do |test|
0a80ba2 @cehoffman Ruby 1.9 compatibility
cehoffman authored
50 test.libs << 'lib' << 'test' << '.'
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
51 test.pattern = 'test/**/test_*.rb'
52 test.verbose = true
53 end
54
55 desc "Generate RCov test coverage and open in your browser"
56 task :coverage do
57 require 'rcov'
58 sh "rm -fr coverage"
59 sh "rcov test/test_*.rb"
60 sh "open coverage/index.html"
61 end
62
63 require 'rake/rdoctask'
64 Rake::RDocTask.new do |rdoc|
65 rdoc.rdoc_dir = 'rdoc'
66 rdoc.title = "#{name} #{version}"
67 rdoc.rdoc_files.include('README*')
68 rdoc.rdoc_files.include('lib/**/*.rb')
69 end
518385c @mojombo switch ot using Jeweler for packaging tasks, and up to version 1.0.0
mojombo authored
70
2c6af5a @mojombo implement Repo.commits
mojombo authored
71 desc "Open an irb session preloaded with this library"
72 task :console do
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
73 sh "irb -rubygems -r ./lib/#{name}.rb"
ebdf471 @mojombo add Repo.blob
mojombo authored
74 end
75
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
76 #############################################################################
77 #
78 # Custom tasks (add your own tasks here)
79 #
80 #############################################################################
6c38e55 @mojombo rake site
mojombo authored
81
82 desc "Upload site to Rubyforge"
83 task :site do
84 sh "scp -r doc/* mojombo@grit.rubyforge.org:/var/www/gforge-projects/grit"
a6015ed @Voker57 Fixed gem builing
Voker57 authored
85 end
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
86
87 #############################################################################
88 #
89 # Packaging tasks
90 #
91 #############################################################################
92
93 task :release => :build do
94 unless `git branch` =~ /^\* master$/
95 puts "You must be on the master branch to release!"
96 exit!
97 end
98 sh "git commit --allow-empty -a -m 'Release #{version}'"
99 sh "git tag v#{version}"
100 sh "git push origin master"
d568d80 @mojombo Fix release tag pushing.
mojombo authored
101 sh "git push origin v#{version}"
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
102 sh "gem push pkg/#{name}-#{version}.gem"
103 end
104
105 task :build => :gemspec do
106 sh "mkdir -p pkg"
107 sh "gem build #{gemspec_file}"
108 sh "mv #{gem_file} pkg"
109 end
110
111 task :gemspec => :validate do
112 # read spec file and split out manifest section
113 spec = File.read(gemspec_file)
114 head, manifest, tail = spec.split(" # = MANIFEST =\n")
115
116 # replace name version and date
117 replace_header(head, :name)
118 replace_header(head, :version)
119 replace_header(head, :date)
120 #comment this out if your rubyforge_project has a different name
121 replace_header(head, :rubyforge_project)
122
123 # determine file list from git ls-files
124 files = `git ls-files`.
125 split("\n").
126 sort.
127 reject { |file| file =~ /^\./ }.
47ab25c @mojombo Exclude test dir from gem.
mojombo authored
128 reject { |file| file =~ /^(rdoc|pkg|test)/ }.
c0f0b4f @mojombo Update to use RakeGem.
mojombo authored
129 map { |file| " #{file}" }.
130 join("\n")
131
132 # piece file back together and write
133 manifest = " s.files = %w[\n#{files}\n ]\n"
134 spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135 File.open(gemspec_file, 'w') { |io| io.write(spec) }
136 puts "Updated #{gemspec_file}"
137 end
138
139 task :validate do
140 libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
141 unless libfiles.empty?
142 puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
143 exit!
144 end
145 unless Dir['VERSION*'].empty?
146 puts "A `VERSION` file at root level violates Gem best practices."
147 exit!
148 end
149 end
Something went wrong with that request. Please try again.