heroku_deploy 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{heroku_deploy}
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ross Hale", "Chris Lemcke"]
@@ -23,13 +23,19 @@ Gem::Specification.new do |s|
23
23
  "heroku_deploy.gemspec",
24
24
  "lib/heroku_deploy.rb",
25
25
  "lib/heroku_deploy/tasks.rb",
26
- "lib/tasks/heroku_deploy.rake"
26
+ "lib/tasks/heroku_deploy.rake",
27
+ "test/heroku_deploy_test.rb",
28
+ "test/test_helper.rb"
27
29
  ]
28
30
  s.homepage = %q{http://github.com/lottay/heroku_deploy}
29
31
  s.rdoc_options = ["--charset=UTF-8"]
30
32
  s.require_paths = ["lib"]
31
33
  s.rubygems_version = %q{1.3.7}
32
34
  s.summary = %q{initial import}
35
+ s.test_files = [
36
+ "test/heroku_deploy_test.rb",
37
+ "test/test_helper.rb"
38
+ ]
33
39
 
34
40
  if s.respond_to? :specification_version then
35
41
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -10,17 +10,22 @@ class Rake::Application
10
10
  end
11
11
 
12
12
  class HerokuDeploy
13
+ attr_accessor :staging_app, :production_app
14
+
15
+ def initialize( options = {} )
16
+ @staging_app = options.delete(:staging_app)
17
+ @production_app = options.delete(:production_app)
18
+ end
13
19
 
14
20
  class Tasks < ::Rake::TaskLib
15
- attr_accessor :heroku_deploy, :staging_app, :production_app
21
+ attr_accessor :heroku_deploy
16
22
 
17
23
  def initialize( options = {} )
18
24
  Rake.application.heroku_deploy_tasks = self
19
25
 
20
- @staging_app = options.delete(:staging_app)
21
- @production_app = options.delete(:production_app)
22
- @heroku_deploy = HerokuDeploy.new
23
-
26
+ @heroku_deploy = HerokuDeploy.new( :staging_app => options.delete(:staging_app),
27
+ :production_app => options.delete(:production_app))
28
+
24
29
  define
25
30
  end
26
31
 
@@ -28,72 +33,23 @@ class HerokuDeploy
28
33
  namespace :heroku_deploy do
29
34
  desc 'Setup branches and apps on heroku'
30
35
  task :setup => :environment do
31
-
32
- puts ""
33
- puts "Creating staging branch"
34
- puts ""
35
- `git branch staging`
36
- `git push origin origin/master:refs/heads/staging`
37
-
38
- puts ""
39
- puts "Creating production branch"
40
- puts ""
41
- `git branch production`
42
- `git push origin origin/master:refs/heads/production`
43
-
44
- `git checkout master`
45
-
46
- puts ""
47
- puts "Creating #{staging_app} Heroku app"
48
- puts ""
49
- `heroku app:create #{staging_app}`
50
- `heroku addons:add bundles:single --app #{staging_app}`
51
-
52
- puts ""
53
- puts "Creating #{production_app} Heroku app"
54
- puts ""
55
- `heroku app:create #{production_app}`
56
- `heroku addons:add bundles:single --app #{production_app}`
57
-
58
- puts ""
59
- puts "Setup Complete!"
60
- puts ""
61
-
36
+ heroku_deploy.setup
62
37
  end
63
38
 
64
39
  desc 'Deploy changes to staging'
65
40
  task :staging => :environment do
66
-
67
- heroku_deploy.backup( staging_app )
68
-
69
- puts "Deploying to Staging"
70
- heroku_deploy.merge( "master", "staging" )
71
-
72
- heroku_deploy.push_to 'staging', staging_app
73
- puts ""
74
- puts "Staging Deployed!"
75
- puts ""
41
+ heroku_deploy.staging
76
42
  end
77
43
 
78
44
  desc 'Deploy changes to production'
79
45
  task :production => :environment do
80
-
81
- heroku_deploy.backup( production_app )
82
-
83
- puts "Deploying to Production"
84
- heroku_deploy.merge( "staging", "production" )
85
-
86
- heroku_deploy.push_to 'production', production_app
87
-
88
- puts ""
89
- puts "Production Deployed!"
90
- puts ""
46
+ heroku_deploy.production
91
47
  end
92
48
 
93
49
  namespace :backup do
94
50
  desc 'Backup and download the staging code and database in a heroku bundle'
95
51
  task :staging => :environment do
96
- heroku_deploy.backup staging_app
52
+ heroku_deploy.backup_staging
97
53
  end
98
54
 
99
55
  desc 'Backup and download the production code and database in a heroku bundle'
@@ -101,11 +57,77 @@ class HerokuDeploy
101
57
  heroku_deploy.backup production_app
102
58
  end
103
59
  end
104
-
105
60
  end
106
61
  end
107
62
  end
108
63
 
64
+ def setup
65
+ puts ""
66
+ puts "Creating staging branch"
67
+ puts ""
68
+ `git branch staging`
69
+ `git push origin origin/master:refs/heads/staging`
70
+
71
+ puts ""
72
+ puts "Creating production branch"
73
+ puts ""
74
+ `git branch production`
75
+ `git push origin origin/master:refs/heads/production`
76
+
77
+ `git checkout master`
78
+
79
+ puts ""
80
+ puts "Creating #{staging_app} Heroku app"
81
+ puts ""
82
+ `heroku app:create #{staging_app}`
83
+ `heroku addons:add bundles:single --app #{staging_app}`
84
+
85
+ puts ""
86
+ puts "Creating #{production_app} Heroku app"
87
+ puts ""
88
+ `heroku app:create #{production_app}`
89
+ `heroku addons:add bundles:single --app #{production_app}`
90
+
91
+ puts ""
92
+ puts "Setup Complete!"
93
+ puts ""
94
+ end
95
+
96
+ def staging
97
+ backup staging_app
98
+
99
+ puts "Deploying to Staging"
100
+ merge "master", "staging"
101
+
102
+ push_to 'staging', staging_app
103
+ puts ""
104
+ puts "Staging Deployed!"
105
+ puts ""
106
+ end
107
+
108
+ def production
109
+ backup production_app
110
+
111
+ puts "Deploying to Production"
112
+ merge "staging", "production"
113
+
114
+ push_to 'production', production_app
115
+
116
+ puts ""
117
+ puts "Production Deployed!"
118
+ puts ""
119
+ end
120
+
121
+ def backup_staging
122
+ backup staging_app
123
+ end
124
+
125
+ def backup_production
126
+ backup production_app
127
+ end
128
+
129
+ private
130
+
109
131
  def merge(from_branch, to_branch)
110
132
  puts "Merging #{from_branch} with #{to_branch}"
111
133
 
@@ -145,7 +167,7 @@ class HerokuDeploy
145
167
  def backup( app )
146
168
  puts ""
147
169
  puts "Beginning Backup"
148
- timestamp = Time.now.to_s(:number)
170
+ timestamp = Time.now.strftime("%Y%m%d%H%M%S")
149
171
  old_bundle = `heroku bundles --app #{app}`.split.first
150
172
 
151
173
  `heroku bundles:destroy #{old_bundle} --app #{app}`
@@ -166,14 +188,12 @@ class HerokuDeploy
166
188
 
167
189
  puts "New Bundle Downloaded: #{app}-#{timestamp}.tar.gz"
168
190
  end
169
-
191
+
170
192
  puts "Backup Complete!"
171
193
  puts ""
172
194
 
173
195
  end
174
196
 
175
- protected
176
-
177
197
  def bundle_not_yet_captured?( app )
178
198
  `heroku bundles --app #{app}`.include?(" capturing ")
179
199
  end
@@ -182,4 +202,6 @@ class HerokuDeploy
182
202
  `heroku bundles --app #{app}`.include?(" complete ")
183
203
  end
184
204
 
205
+
206
+
185
207
  end
data/lib/heroku_deploy.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  class HerokuDeploy
2
2
  autoload :Tasks, 'heroku_deploy/tasks'
3
+ autoload :HerokuDeploy, 'heroku_deploy/tasks'
3
4
  end
4
5
 
5
6
 
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ require 'rake'
4
+ class HerokuDeployTest < Test::Unit::TestCase
5
+ include Rake
6
+
7
+ context 'Initializing HerokuDeploy::Tasks' do
8
+ setup do
9
+ @tasks = HerokuDeploy::Tasks.new( :staging_app => "example-staging", :production_app => "example" )
10
+ end
11
+
12
+ teardown do
13
+ Task.clear
14
+ end
15
+
16
+ should 'set self as the application-wide jeweler tasks' do
17
+ assert_same @tasks, Rake.application.heroku_deploy_tasks
18
+ end
19
+
20
+ context "HerokuDeploy instance" do
21
+
22
+ setup do
23
+ @heroku_deploy = @tasks.heroku_deploy
24
+ stub(@heroku_deploy).__double_definition_create__.call(:`) { "" }
25
+ stub(@heroku_deploy).puts
26
+ stub(@heroku_deploy).bundle_not_yet_captured? { false }
27
+ stub(@heroku_deploy).bundle_captured? { true }
28
+ end
29
+
30
+ should "assign staging_app" do
31
+ assert_equal "example-staging", @heroku_deploy.staging_app
32
+ end
33
+
34
+ should "assign production_app" do
35
+ assert_equal "example", @heroku_deploy.production_app
36
+ end
37
+
38
+ should "invoke setup" do
39
+ @heroku_deploy.setup
40
+ end
41
+
42
+ should "invoke staging" do
43
+ @heroku_deploy.staging
44
+ end
45
+
46
+ should "invoke production" do
47
+ @heroku_deploy.production
48
+ end
49
+
50
+ should "invoke backup_staging" do
51
+ @heroku_deploy.backup_staging
52
+ end
53
+
54
+ should "invoke backup_production" do
55
+ @heroku_deploy.backup_production
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,13 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+
4
+ require 'rake'
5
+ require 'shoulda'
6
+ require 'rr'
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
8
+ require 'heroku_deploy'
9
+
10
+
11
+ class Test::Unit::TestCase
12
+ include RR::Adapters::TestUnit unless include?(RR::Adapters::TestUnit)
13
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_deploy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 12
10
- version: 0.0.12
9
+ - 13
10
+ version: 0.0.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ross Hale
@@ -50,6 +50,8 @@ files:
50
50
  - lib/heroku_deploy.rb
51
51
  - lib/heroku_deploy/tasks.rb
52
52
  - lib/tasks/heroku_deploy.rake
53
+ - test/heroku_deploy_test.rb
54
+ - test/test_helper.rb
53
55
  has_rdoc: true
54
56
  homepage: http://github.com/lottay/heroku_deploy
55
57
  licenses: []
@@ -84,5 +86,6 @@ rubygems_version: 1.3.7
84
86
  signing_key:
85
87
  specification_version: 3
86
88
  summary: initial import
87
- test_files: []
88
-
89
+ test_files:
90
+ - test/heroku_deploy_test.rb
91
+ - test/test_helper.rb