Skip to content
Newer
Older
100644 121 lines (99 sloc) 2.84 KB
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored Apr 6, 2010
1 require 'rubygems'
38d3ced @mike-burns Passes
mike-burns authored Apr 6, 2010
2 require 'rake'
3 require 'cucumber/rake/task'
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored Apr 7, 2010
4 require 'date'
38d3ced @mike-burns Passes
mike-burns authored Apr 6, 2010
5
6 TEST_PROJECT = 'test_project'
1b5efc0 Release 0.2.5
Harold Giménez authored Jun 1, 2011
7 SUSPENDERS_GEM_VERSION = '0.2.5'
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored Apr 7, 2010
8
9 #############################################################################
10 #
11 # Testing functions
12 #
13 #############################################################################
38d3ced @mike-burns Passes
mike-burns authored Apr 6, 2010
14
15 Cucumber::Rake::Task.new
16
17 namespace :test do
18 desc "A full suspenders app's test suite"
a1b356f @jferris Cleaned up Rakefile; fixed step definitions for Rails 3; added missin…
jferris authored Sep 27, 2010
19 task :full => ['test_project:generate', 'cucumber', 'test_project:destroy']
38d3ced @mike-burns Passes
mike-burns authored Apr 6, 2010
20 end
21
a1b356f @jferris Cleaned up Rakefile; fixed step definitions for Rails 3; added missin…
jferris authored Sep 27, 2010
22 namespace :test_project do
fc877c9 @mike-burns Optionally pull from a custom repo URL
mike-burns authored Jun 9, 2010
23 desc 'Suspend a new project. Pass REPO=... to change the Suspenders repo.'
a1b356f @jferris Cleaned up Rakefile; fixed step definitions for Rails 3; added missin…
jferris authored Sep 27, 2010
24 task :generate do
db8699b @jasonm Fixed rake test task. It should removed the test_project before creat…
jasonm authored Jul 26, 2010
25 FileUtils.rm_rf(TEST_PROJECT)
2ed092d Pass in REPO to specify the suspenders repo. Useful for tests locally…
Harold Giménez authored Jun 2, 2011
26 sh './bin/suspenders', 'create', TEST_PROJECT, ENV['REPO'].to_s
38d3ced @mike-burns Passes
mike-burns authored Apr 6, 2010
27 end
28
29 desc 'Remove a suspended project'
a1b356f @jferris Cleaned up Rakefile; fixed step definitions for Rails 3; added missin…
jferris authored Sep 27, 2010
30 task :destroy do
00e9702 delete the databases for the test project after a run
Chad Pytel authored Jul 12, 2010
31 FileUtils.cd TEST_PROJECT
32 sh "rake db:drop RAILS_ENV=development"
33 sh "rake db:drop RAILS_ENV=test"
34 FileUtils.cd '..'
38d3ced @mike-burns Passes
mike-burns authored Apr 6, 2010
35 FileUtils.rm_rf TEST_PROJECT
36 end
37 end
38
39 desc 'Run the test suite'
40 task :default => ['test:full']
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored Apr 7, 2010
41
42 #############################################################################
43 #
44 # Helper functions
45 #
46 #############################################################################
47
48 def name
49 @name ||= Dir['*.gemspec'].first.split('.').first
50 end
51
52 def version
686730c @mike-burns Rename to suspenders-gem
mike-burns authored May 14, 2010
53 SUSPENDERS_GEM_VERSION
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored Apr 7, 2010
54 end
55
56 def date
57 Date.today.to_s
58 end
59
60 def gemspec_file
61 "#{name}.gemspec"
62 end
63
64 def gem_file
65 "#{name}-#{version}.gem"
66 end
67
68 def replace_header(head, header_name)
69 head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
70 end
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 "git commit --allow-empty -a -m 'Release #{version}'"
84 sh "git tag v#{version}"
85 sh "git push origin master"
686730c @mike-burns Rename to suspenders-gem
mike-burns authored May 14, 2010
86 sh "git push --tags"
c6f5c57 @mike-burns Gemspec and rake tasks for packaging
mike-burns authored Apr 7, 2010
87 sh "gem push pkg/#{name}-#{version}.gem"
88 end
89
90 task :build => :gemspec do
91 sh "mkdir -p pkg"
92 sh "gem build #{gemspec_file}"
93 sh "mv #{gem_file} pkg"
94 end
95
96 task :gemspec do
97 # read spec file and split out manifest section
98 spec = File.read(gemspec_file)
99 head, manifest, tail = spec.split(" # = MANIFEST =\n")
100
101 # replace name version and date
102 replace_header(head, :name)
103 replace_header(head, :version)
104 replace_header(head, :date)
105
106 # determine file list from git ls-files
107 files = `git ls-files`.
108 split("\n").
109 sort.
110 reject { |file| file =~ /^\./ }.
111 reject { |file| file =~ /^(rdoc|pkg)/ }.
112 map { |file| " #{file}" }.
113 join("\n")
114
115 # piece file back together and write
116 manifest = " s.files = %w[\n#{files}\n ]\n"
117 spec = [head, manifest, tail].join(" # = MANIFEST =\n")
118 File.open(gemspec_file, 'w') { |io| io.write(spec) }
119 puts "Updated #{gemspec_file}"
120 end
Something went wrong with that request. Please try again.