Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 99 lines (80 sloc) 2.299 kB
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored
1 require 'rubygems'
38d3ced @mike-burns Passes
mike-burns authored
2 require 'rake'
3 require 'cucumber/rake/task'
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored
4 require 'date'
38d3ced @mike-burns Passes
mike-burns authored
5
6 TEST_PROJECT = 'test_project'
a0225bd Release 0.3.1
Harold Giménez authored
7 SUSPENDERS_GEM_VERSION = '0.3.1'
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored
8
9 #############################################################################
10 #
11 # Testing functions
12 #
13 #############################################################################
38d3ced @mike-burns Passes
mike-burns authored
14
15 Cucumber::Rake::Task.new
16
17 desc 'Run the test suite'
d900182 Remove unused rake tasks
Harold Giménez authored
18 task :default => ['cucumber']
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored
19
20 #############################################################################
21 #
22 # Helper functions
23 #
24 #############################################################################
25
26 def name
27 @name ||= Dir['*.gemspec'].first.split('.').first
28 end
29
30 def version
686730c @mike-burns Rename to suspenders-gem
mike-burns authored
31 SUSPENDERS_GEM_VERSION
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored
32 end
33
34 def date
35 Date.today.to_s
36 end
37
38 def gemspec_file
39 "#{name}.gemspec"
40 end
41
42 def gem_file
43 "#{name}-#{version}.gem"
44 end
45
46 def replace_header(head, header_name)
47 head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
48 end
49
50 #############################################################################
51 #
52 # Packaging tasks
53 #
54 #############################################################################
55
56 task :release => :build do
57 unless `git branch` =~ /^\* master$/
58 puts "You must be on the master branch to release!"
59 exit!
60 end
61 sh "git commit --allow-empty -a -m 'Release #{version}'"
62 sh "git tag v#{version}"
63 sh "git push origin master"
686730c @mike-burns Rename to suspenders-gem
mike-burns authored
64 sh "git push --tags"
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored
65 sh "gem push pkg/#{name}-#{version}.gem"
66 end
67
68 task :build => :gemspec do
69 sh "mkdir -p pkg"
70 sh "gem build #{gemspec_file}"
71 sh "mv #{gem_file} pkg"
72 end
73
74 task :gemspec do
75 # read spec file and split out manifest section
76 spec = File.read(gemspec_file)
77 head, manifest, tail = spec.split(" # = MANIFEST =\n")
78
79 # replace name version and date
80 replace_header(head, :name)
81 replace_header(head, :version)
82 replace_header(head, :date)
83
84 # determine file list from git ls-files
85 files = `git ls-files`.
86 split("\n").
87 sort.
88 reject { |file| file =~ /^\./ }.
89 reject { |file| file =~ /^(rdoc|pkg)/ }.
90 map { |file| " #{file}" }.
91 join("\n")
92
93 # piece file back together and write
94 manifest = " s.files = %w[\n#{files}\n ]\n"
95 spec = [head, manifest, tail].join(" # = MANIFEST =\n")
96 File.open(gemspec_file, 'w') { |io| io.write(spec) }
97 puts "Updated #{gemspec_file}"
98 end
Something went wrong with that request. Please try again.