Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
Run kumade:post_deploy if deployment succeeds.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoverlover committed Jan 30, 2012
1 parent 81eb06c commit 9679018
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ After that, it packages assets using
[Jammit](http://documentcloud.github.com/jammit/) (if it's installed), commits
them, and pushes to origin.
Then it force pushes to the correct Heroku remote, runs `rake db:migrate` on the
Heroku app, and then restarts the app.
Heroku app, and then restarts the app. If all of this succeeds, it will
also run the rake task `kumade:post_deploy` if it is defined.

If any step fails, it immediately prints an error and stops the deploy
process.
Expand Down
9 changes: 9 additions & 0 deletions lib/kumade/deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def deploy
heroku.sync
heroku.migrate_database
heroku.restart_app
post_deploy_success
rescue => deploying_error
Kumade.configuration.outputter.error("#{deploying_error.class}: #{deploying_error.message}")
ensure
Expand All @@ -33,6 +34,10 @@ def pre_deploy
sync_origin
end

def post_deploy_success
run_postdeploy_task
end

def package_assets
@packager.run
end
Expand Down Expand Up @@ -66,5 +71,9 @@ def ensure_heroku_remote_exists
def run_predeploy_task
RakeTaskRunner.new("kumade:pre_deploy").invoke
end

def run_postdeploy_task
RakeTaskRunner.new("kumade:post_deploy").invoke
end
end
end
22 changes: 22 additions & 0 deletions spec/kumade/deployer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@
end
end

describe Kumade::Deployer, "#post_deploy_success", :with_mock_outputter do
let(:rake_task_runner) { stub("RakeTaskRunner", :invoke => true) }

before do
Kumade::RakeTaskRunner.stubs(:new).with("kumade:post_deploy").returns(rake_task_runner)
end

it "calls the correct methods" do
subject.expects(:run_postdeploy_task)

subject.post_deploy_success
end

it "invokes the kumade:pre_deploy task" do
subject.post_deploy_success

Kumade::RakeTaskRunner.should have_received(:new).with("kumade:post_deploy")
rake_task_runner.should have_received(:invoke)
end
end

describe Kumade::Deployer, "#deploy", :with_mock_outputter do
let(:remote_name) { 'staging' }

Expand All @@ -39,6 +60,7 @@
subject.heroku.expects(:migrate_database)
subject.heroku.expects(:restart_app)
subject.expects(:post_deploy)
subject.expects(:post_deploy_success)

subject.deploy
end
Expand Down

0 comments on commit 9679018

Please sign in to comment.