kumade 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Kumade [![Build Status](https://secure.travis-ci.org/thoughtbot/kumade.png)](http://travis-ci.org/gabebw/kumade)
1
+ # Kumade [![Build Status](https://secure.travis-ci.org/thoughtbot/kumade.png)](http://travis-ci.org/thoughtbot/kumade)
2
2
  Kumade is a set of basic Rake tasks for deploying to Heroku. It aims to
3
3
  provide most of what you want. Unlike other Heroku deploy gems, it is
4
4
  well-tested.
data/bin/kumade CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'kumade'
4
4
 
5
- Kumade::ThorTask.start
5
+ Kumade::Runner.run
@@ -16,7 +16,7 @@ Feature: Kumade executable
16
16
  And I create a non-Heroku remote named "bad-remote"
17
17
 
18
18
  Scenario: Pretend mode with a Heroku remote
19
- When I run `kumade deploy pretend-staging -p`
19
+ When I run `kumade pretend-staging -p`
20
20
  Then the output should contain "In Pretend Mode"
21
21
  And the output should contain:
22
22
  """
@@ -37,10 +37,26 @@ Feature: Kumade executable
37
37
  Then the output should contain "==> Deployed to: staging"
38
38
 
39
39
  Scenario: Can deploy to arbitrary environment
40
- When I run `kumade deploy bamboo`
40
+ When I run `kumade bamboo`
41
41
  Then the output should contain "==> Deploying to: bamboo"
42
42
  Then the output should match /Cannot deploy: /
43
43
 
44
44
  Scenario: Deploying to a non-Heroku remote fails
45
- When I run `kumade deploy bad-remote`
45
+ When I run `kumade bad-remote`
46
46
  Then the output should match /==> ! Cannot deploy: "bad-remote" remote does not point to Heroku/
47
+
48
+ Scenario: Deploy from another branch
49
+ When I run `git checkout -b new_branch`
50
+ When I run `kumade pretend-staging -p`
51
+ Then the output should contain:
52
+ """
53
+ ==> Git repo is clean
54
+ ==> Packaged assets with Jammit
55
+ run git push origin new_branch
56
+ ==> Pushed new_branch -> origin
57
+ run git push -f pretend-staging deploy:master
58
+ ==> Force pushed new_branch -> pretend-staging
59
+ ==> Migrated pretend-staging-app
60
+ run git checkout new_branch && git branch -D deploy
61
+ ==> Deployed to: pretend-staging
62
+ """
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_dependency('heroku')
19
+ s.add_dependency('heroku', '~> 2.0')
20
20
  s.add_dependency('thor', '~> 0.14')
21
21
 
22
22
  s.add_development_dependency('rake', '~> 0.8.7')
@@ -1,7 +1,6 @@
1
1
  require 'thor'
2
-
3
2
  require 'kumade/deployer'
4
- require 'kumade/thor_task'
3
+ require 'kumade/runner'
5
4
 
6
5
  module Kumade
7
6
  def self.app_for(environment)
@@ -7,6 +7,7 @@ module Kumade
7
7
  super()
8
8
  @environment = environment
9
9
  @pretending = pretending
10
+ @branch = current_branch
10
11
  end
11
12
 
12
13
  def deploy
@@ -24,15 +25,15 @@ module Kumade
24
25
  end
25
26
 
26
27
  def sync_github
27
- run_or_error("git push origin master",
28
- "Failed to push master -> origin")
29
- success("Pushed master -> origin")
28
+ run_or_error("git push origin #{@branch}",
29
+ "Failed to push #{@branch} -> origin")
30
+ success("Pushed #{@branch} -> origin")
30
31
  end
31
32
 
32
33
  def sync_heroku
33
34
  run_or_error("git push -f #{environment} #{DEPLOY_BRANCH}:master",
34
35
  "Failed to force push #{DEPLOY_BRANCH} -> #{environment}/master")
35
- success("Force pushed master -> #{environment}")
36
+ success("Force pushed #{@branch} -> #{environment}")
36
37
  end
37
38
 
38
39
  def heroku_migrate
@@ -43,7 +44,7 @@ module Kumade
43
44
  end
44
45
 
45
46
  def post_deploy
46
- run_or_error(["git checkout master", "git branch -D #{DEPLOY_BRANCH}"],
47
+ run_or_error(["git checkout #{@branch}", "git branch -D #{DEPLOY_BRANCH}"],
47
48
  "Failed to clean up #{DEPLOY_BRANCH} branch")
48
49
  end
49
50
 
@@ -146,20 +147,6 @@ module Kumade
146
147
  end)
147
148
  end
148
149
 
149
- def default_task_exists?
150
- `rake -s -P | grep 'rake default'`.strip.size > 0
151
- end
152
-
153
- def rake_succeeded?
154
- return true if pretending
155
-
156
- begin
157
- run "bundle exec rake"
158
- rescue
159
- false
160
- end
161
- end
162
-
163
150
  def git_dirty?
164
151
  `git diff --exit-code`
165
152
  !$?.success?
@@ -179,10 +166,6 @@ module Kumade
179
166
  config[:capture] ? `#{command}` : system("#{command}")
180
167
  end
181
168
 
182
- def announce(message)
183
- say "==> #{message}"
184
- end
185
-
186
169
  def error(message)
187
170
  say("==> ! #{message}", :red)
188
171
  exit 1
@@ -211,5 +194,9 @@ module Kumade
211
194
  `git remote` =~ /^#{remote_name}$/
212
195
  end
213
196
  end
197
+
198
+ def current_branch
199
+ `git symbolic-ref HEAD`.sub("refs/heads/", "").strip
200
+ end
214
201
  end
215
202
  end
@@ -0,0 +1,53 @@
1
+ require 'optparse'
2
+
3
+ module Kumade
4
+ class Runner
5
+ class << self
6
+ attr_reader :environment
7
+ end
8
+
9
+ def self.run(args=ARGV, out=$stdout)
10
+ @out = out
11
+ @options = parse_arguments!(args)
12
+ @environment = args.shift || 'staging'
13
+
14
+ deploy
15
+ end
16
+
17
+ def self.deploy
18
+ if pretending?
19
+ @out.puts "==> In Pretend Mode"
20
+ end
21
+ @out.puts "==> Deploying to: #{environment}"
22
+ Deployer.new(environment, pretending?).deploy
23
+ @out.puts "==> Deployed to: #{environment}"
24
+ end
25
+
26
+ def self.parse_arguments!(args)
27
+ options = {}
28
+ OptionParser.new do |opts|
29
+ opts.banner = "Usage: kumade <environment> [options]"
30
+
31
+ opts.on("-p", "--pretend", "Pretend mode: print what kumade would do") do |p|
32
+ options[:pretend] = p
33
+ end
34
+
35
+ opts.on_tail('-v', '--version', 'Show version') do
36
+ @out.puts "kumade #{Kumade::VERSION}"
37
+ exit
38
+ end
39
+
40
+ opts.on_tail('-h', '--help', 'Show this message') do
41
+ @out.puts opts
42
+ exit
43
+ end
44
+ end.parse!(args)
45
+
46
+ options
47
+ end
48
+
49
+ def self.pretending?
50
+ @options[:pretend]
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Kumade
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -38,8 +38,6 @@ describe Kumade::Deployer, "#deploy" do
38
38
  force_add_heroku_remote(remote_name, app_name)
39
39
  end
40
40
 
41
- after { remove_remote(remote_name) }
42
-
43
41
  it "calls the correct methods in order" do
44
42
  subject.stub(:run => true)
45
43
 
@@ -166,25 +164,6 @@ describe Kumade::Deployer, "#ensure_clean_git" do
166
164
  end
167
165
  end
168
166
 
169
- describe Kumade::Deployer, "#default_task_exists?" do
170
- it "returns true because a default task does exist" do
171
- subject.default_task_exists?.should be_true
172
- end
173
- end
174
-
175
- describe Kumade::Deployer, "#rake_succeeded?" do
176
- it "returns true if the default task passed" do
177
- subject.should_receive(:run).with("bundle exec rake").and_return(true)
178
-
179
- subject.rake_succeeded?.should be_true
180
- end
181
-
182
- it "returns false if the default task failed" do
183
- subject.should_receive(:run).with("bundle exec rake").and_raise("blerg")
184
- subject.rake_succeeded?.should be_false
185
- end
186
- end
187
-
188
167
  describe Kumade::Deployer, "#package_assets" do
189
168
  context "with Jammit installed" do
190
169
  it "calls package_with_jammit" do
@@ -418,8 +397,6 @@ describe Kumade::Deployer, "#heroku_migrate" do
418
397
  force_add_heroku_remote(environment, app_name)
419
398
  end
420
399
 
421
- after { remove_remote(environment) }
422
-
423
400
  it "runs db:migrate with the correct app" do
424
401
  subject.stub(:run => true)
425
402
  subject.should_receive(:heroku).
@@ -441,11 +418,6 @@ describe Kumade::Deployer, "#ensure_heroku_remote_exists" do
441
418
  `git remote add #{bad_environment} blerg@example.com`
442
419
  end
443
420
 
444
- after do
445
- remove_remote(environment)
446
- remove_remote(bad_environment)
447
- end
448
-
449
421
  context "when the remote points to Heroku" do
450
422
  subject { Kumade::Deployer.new(environment) }
451
423
 
@@ -489,7 +461,6 @@ describe Kumade::Deployer, "#remote_exists?" do
489
461
  let(:remote_name){ 'staging' }
490
462
 
491
463
  before { force_add_heroku_remote(remote_name, 'i-am-a-heroku-app') }
492
- after { remove_remote(remote_name) }
493
464
 
494
465
  it "returns true if the remote exists" do
495
466
  subject.remote_exists?(remote_name).should be_true
@@ -522,12 +493,6 @@ describe Kumade::Deployer, "#heroku" do
522
493
  end
523
494
  end
524
495
 
525
- describe Kumade::Deployer, "#announce" do
526
- it "exists" do
527
- subject.should respond_to(:announce)
528
- end
529
- end
530
-
531
496
  describe Kumade::Deployer, "#success" do
532
497
  it "exists" do
533
498
  subject.should respond_to(:success)
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kumade::Runner do
4
+ subject { Kumade::Runner }
5
+ let(:out){ StringIO.new }
6
+ let(:environment){ 'my-environment' }
7
+
8
+ %w(-p --pretend).each do |pretend_arg|
9
+ it "sets pretend mode when run with #{pretend_arg}" do
10
+ subject.stub(:deploy)
11
+
12
+ subject.run([environment, pretend_arg], out)
13
+ subject.pretending?.should be_true
14
+ end
15
+ end
16
+
17
+ it "defaults to staging" do
18
+ subject.stub(:deploy)
19
+ subject.run([], out)
20
+ subject.environment.should == 'staging'
21
+ end
22
+
23
+ it "deploys" do
24
+ Kumade::Deployer.any_instance.should_receive(:deploy)
25
+
26
+ subject.run([environment], out)
27
+ end
28
+ end
@@ -1,6 +1,8 @@
1
1
  require 'rspec'
2
2
  require 'kumade'
3
3
  require 'rake'
4
+ require 'stringio'
5
+ require 'aruba/api'
4
6
 
5
7
  module GitRemoteHelpers
6
8
  def force_add_heroku_remote(remote_name, app_name)
@@ -16,4 +18,17 @@ end
16
18
  RSpec.configure do |config|
17
19
  config.include RSpec::Mocks::Methods
18
20
  config.include GitRemoteHelpers
21
+ config.include Aruba::Api
22
+
23
+ config.around do |example|
24
+ FileUtils.rm_rf(current_dir)
25
+ FileUtils.mkdir_p(current_dir)
26
+ in_current_dir do
27
+ `git init .`
28
+ `touch .gitkeep`
29
+ `git add .`
30
+ `git commit -m First`
31
+ example.run
32
+ end
33
+ end
19
34
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumade
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gabe Berke-Williams
@@ -16,26 +16,28 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-08-05 00:00:00 -04:00
19
+ date: 2011-08-12 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: heroku
24
24
  prerelease: false
25
+ type: :runtime
25
26
  requirement: &id001 !ruby/object:Gem::Requirement
26
27
  none: false
27
28
  requirements:
28
- - - ">="
29
+ - - ~>
29
30
  - !ruby/object:Gem::Version
30
31
  hash: 3
31
32
  segments:
33
+ - 2
32
34
  - 0
33
- version: "0"
34
- type: :runtime
35
+ version: "2.0"
35
36
  version_requirements: *id001
36
37
  - !ruby/object:Gem::Dependency
37
38
  name: thor
38
39
  prerelease: false
40
+ type: :runtime
39
41
  requirement: &id002 !ruby/object:Gem::Requirement
40
42
  none: false
41
43
  requirements:
@@ -46,11 +48,11 @@ dependencies:
46
48
  - 0
47
49
  - 14
48
50
  version: "0.14"
49
- type: :runtime
50
51
  version_requirements: *id002
51
52
  - !ruby/object:Gem::Dependency
52
53
  name: rake
53
54
  prerelease: false
55
+ type: :development
54
56
  requirement: &id003 !ruby/object:Gem::Requirement
55
57
  none: false
56
58
  requirements:
@@ -62,11 +64,11 @@ dependencies:
62
64
  - 8
63
65
  - 7
64
66
  version: 0.8.7
65
- type: :development
66
67
  version_requirements: *id003
67
68
  - !ruby/object:Gem::Dependency
68
69
  name: rspec
69
70
  prerelease: false
71
+ type: :development
70
72
  requirement: &id004 !ruby/object:Gem::Requirement
71
73
  none: false
72
74
  requirements:
@@ -78,11 +80,11 @@ dependencies:
78
80
  - 6
79
81
  - 0
80
82
  version: 2.6.0
81
- type: :development
82
83
  version_requirements: *id004
83
84
  - !ruby/object:Gem::Dependency
84
85
  name: cucumber
85
86
  prerelease: false
87
+ type: :development
86
88
  requirement: &id005 !ruby/object:Gem::Requirement
87
89
  none: false
88
90
  requirements:
@@ -94,11 +96,11 @@ dependencies:
94
96
  - 0
95
97
  - 2
96
98
  version: 1.0.2
97
- type: :development
98
99
  version_requirements: *id005
99
100
  - !ruby/object:Gem::Dependency
100
101
  name: aruba
101
102
  prerelease: false
103
+ type: :development
102
104
  requirement: &id006 !ruby/object:Gem::Requirement
103
105
  none: false
104
106
  requirements:
@@ -110,11 +112,11 @@ dependencies:
110
112
  - 4
111
113
  - 3
112
114
  version: 0.4.3
113
- type: :development
114
115
  version_requirements: *id006
115
116
  - !ruby/object:Gem::Dependency
116
117
  name: jammit
117
118
  prerelease: false
119
+ type: :development
118
120
  requirement: &id007 !ruby/object:Gem::Requirement
119
121
  none: false
120
122
  requirements:
@@ -126,7 +128,6 @@ dependencies:
126
128
  - 6
127
129
  - 3
128
130
  version: 0.6.3
129
- type: :development
130
131
  version_requirements: *id007
131
132
  description: Simple rake tasks for deploying to Heroku
132
133
  email:
@@ -153,10 +154,10 @@ files:
153
154
  - kumade.gemspec
154
155
  - lib/kumade.rb
155
156
  - lib/kumade/deployer.rb
156
- - lib/kumade/thor_task.rb
157
+ - lib/kumade/runner.rb
157
158
  - lib/kumade/version.rb
158
159
  - spec/kumade/deployer_spec.rb
159
- - spec/kumade/thor_task_spec.rb
160
+ - spec/kumade/runner_spec.rb
160
161
  - spec/kumade_spec.rb
161
162
  - spec/spec_helper.rb
162
163
  has_rdoc: true
@@ -189,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
190
  requirements: []
190
191
 
191
192
  rubyforge_project:
192
- rubygems_version: 1.6.2
193
+ rubygems_version: 1.6.1
193
194
  signing_key:
194
195
  specification_version: 3
195
196
  summary: Simple rake tasks for deploying to Heroku
@@ -199,6 +200,6 @@ test_files:
199
200
  - features/step_definitions/git_steps.rb
200
201
  - features/support/env.rb
201
202
  - spec/kumade/deployer_spec.rb
202
- - spec/kumade/thor_task_spec.rb
203
+ - spec/kumade/runner_spec.rb
203
204
  - spec/kumade_spec.rb
204
205
  - spec/spec_helper.rb
@@ -1,18 +0,0 @@
1
- require 'thor'
2
-
3
- module Kumade
4
- class ThorTask < Thor
5
- default_task :deploy
6
-
7
- desc "deploy [ENV]", "Deploy to ENV (default: staging)"
8
- method_option :pretend, :aliases => "-p", :desc => "Pretend Mode - print out what kumade would do", :default => false
9
- def deploy(environment = 'staging')
10
- say("==> In Pretend Mode", :red) if options[:pretend]
11
- say "==> Deploying to: #{environment}"
12
-
13
- Deployer.new(environment, options[:pretend]).deploy
14
-
15
- say "==> Deployed to: #{environment}", :green
16
- end
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Kumade
4
- describe ThorTask, "deploy" do
5
- before { subject.stub(:say) }
6
-
7
- let(:environment){ 'bamboo' }
8
-
9
- it "calls the deploy method" do
10
- Deployer.any_instance.should_receive(:deploy)
11
- subject.deploy(environment)
12
- end
13
- end
14
- end