Skip to content
Browse files

invoke deploy:assets rake task if it exists on deploy before committi…

…ng assets
  • Loading branch information...
1 parent 11366db commit 9dda7eee7e5c39c154c127733bfec419735f9553 @nickrivadeneira nickrivadeneira committed Aug 19, 2011
View
15 README.md
@@ -22,6 +22,7 @@ gem 'kumade'
```
## Usage
+
kumade will deploy to any Heroku remote in the repo.
For example, if you have a remote named "bamboo":
@@ -134,6 +135,20 @@ Tested against:
* MRI 1.9.2
* REE 1.8.7
+## Misc Features
+
+Want to run a task before bundling your assets on deploy? In your rails app's rake tasks, drop in:
+
+``` ruby
+namespace :deploy do
+ task :assets do
+ puts "This runs before assets are committed and pushed to the remote"
+ end
+end
+```
+
+You can hook in any custom code you want to run there before deploying!
+
## What's with the name?
Kumade ([pronunciation here](http://translate.google.com/#ja|en|熊手)) means
View
7 features/kumade_executable.feature
@@ -84,10 +84,3 @@ Feature: Kumade executable
Scenario: Jammit packager runs if Jammit is installed
When I run kumade with "pretend-staging"
Then the output from "bundle exec kumade pretend-staging" should contain "==> ! Error: Jammit::MissingConfiguration"
-
- Scenario: Jammit packager does not run if Jammit is not installed
- Given an empty Gemfile
- And I set up the Gemfile with kumade
- And I rebundle
- When I run kumade with "pretend-staging"
- Then the output from "bundle exec kumade pretend-staging" should not contain "==> ! Error: Jammit::MissingConfiguration"
View
40 features/kumade_without_jammit.feature
@@ -0,0 +1,40 @@
+@extra-timeout @creates-remote @disable-bundler
+Feature: Kumade without jammit
+
+ Background:
+ Given a directory named "executable"
+ And I cd to "executable"
+ And I set up the Gemfile with kumade
+ And I bundle
+ When I set up a git repo
+ And I create a Heroku remote for "pretend-staging-app" named "pretend-staging"
+
+ Scenario: Jammit packager does not run if Jammit is not installed
+ When I run kumade with "pretend-staging"
+ Then the output should not contain "==> ! Error: Jammit::MissingConfiguration"
+
+ Scenario: Run custom task if it exists
+ Given I write to "Rakefile" with:
+ """
+ namespace :deploy do
+ task :assets do
+ puts 'Hi!'
+ end
+ end
+ """
+ When I run kumade with "pretend-staging"
+ Then the output should contain "Running deploy:assets task"
+ And the output should contain "Hi!"
+
+ Scenario: Don't run rake task in pretend mode
+ Given I write to "Rakefile" with:
+ """
+ namespace :deploy do
+ task :assets do
+ puts 'Hi!'
+ end
+ end
+ """
+ When I run kumade with "pretend-staging -p"
+ Then the output should contain "Running deploy:assets task"
+ And the output should not contain "Hi!"
View
6 features/step_definitions/kumade_steps.rb
@@ -1,3 +1,9 @@
When /^I run kumade with "([^"]+)"$/ do |args|
When %{I run `bundle exec kumade #{args}`}
end
+
+Given /^I have loaded "([^"]+)"$/ do |file|
+ in_current_dir do
+ load(file)
+ end
+end
View
2 lib/kumade.rb
@@ -1,4 +1,6 @@
+require 'rake'
require 'thor'
+
require 'kumade/deployer'
require 'kumade/runner'
require 'kumade/railtie'
View
11 lib/kumade/deployer.rb
@@ -73,6 +73,7 @@ def ensure_clean_git
def package_assets
package_with_jammit if jammit_installed?
package_with_more if more_installed?
+ invoke_custom_task if custom_task?
end
def package_with_jammit
@@ -109,6 +110,11 @@ def package_with_more
end
end
+ def invoke_custom_task
+ success "Running deploy:assets task"
+ Rake::Task["deploy:assets"].invoke unless pretending
+ end
+
def git_add_and_commit_all_assets_in(dir)
run_or_error ["git checkout -b #{DEPLOY_BRANCH}", "git add -f #{dir}", "git commit -m 'Compiled assets'"],
"Cannot deploy: couldn't commit assets"
@@ -146,6 +152,11 @@ def more_installed?
end)
end
+ def custom_task?
+ load("Rakefile") if File.exist?("Rakefile")
+ Rake::Task.task_defined?("deploy:assets")
+ end
+
def git_dirty?
`git diff --exit-code`
!$?.success?
View
61 spec/kumade/deployer_spec.rb
@@ -218,6 +218,34 @@
subject.package_assets
end
end
+
+ context "with custom rake task installed" do
+ before do
+ subject.stub(:jammit_installed? => false,
+ :more_installed? => false,
+ :invoke_custom_task => nil,
+ :custom_task? => true)
+ end
+
+ it "invokes custom task" do
+ subject.should_receive(:invoke_custom_task)
+ subject.package_assets
+ end
+ end
+
+ context "with custom rake task not installed" do
+ before do
+ subject.stub(:jammit_installed? => false,
+ :more_installed? => false,
+ :invoke_custom_task => nil,
+ :custom_task? => false)
+ end
+
+ it "does not invoke custom task" do
+ subject.should_not_receive(:invoke_custom_task)
+ subject.package_assets
+ end
+ end
end
describe Kumade::Deployer, "#package_with_jammit" do
@@ -261,6 +289,20 @@
end
end
+describe Kumade::Deployer, "#invoke_custom_task" do
+ before do
+ Rake::Task.stub(:[] => task)
+ end
+
+ let(:task) { stub('task', :invoke => nil) }
+
+ it "calls deploy task" do
+ Rake::Task.should_receive(:[]).with("deploy:assets")
+ task.should_receive(:invoke)
+ subject.invoke_custom_task
+ end
+end
+
describe Kumade::Deployer, "#package_with_more" do
before do
subject.stub(:git_add_and_commit_all_assets_in => true,
@@ -403,6 +445,25 @@ class More
end
end
+describe Kumade::Deployer, "#custom_task?" do
+ before do
+ Rake::Task.clear
+ end
+
+ it "returns true if it task found" do
+ namespace :deploy do
+ task :assets do
+
+ end
+ end
+ Kumade::Deployer.new.custom_task?.should be_true
+ end
+
+ it "returns false if task not found" do
+ Kumade::Deployer.new.custom_task?.should be_false
+ end
+end
+
describe Kumade::Deployer, "#heroku_migrate" do
let(:environment){ 'staging' }
let(:app_name){ 'sushi' }

0 comments on commit 9dda7ee

Please sign in to comment.
Something went wrong with that request. Please try again.