diff --git a/README.markdown b/README.markdown index 6a27900..f785bdd 100644 --- a/README.markdown +++ b/README.markdown @@ -19,7 +19,6 @@ strategy. No hooks, very little behind-the-scenes magic - it just does what you require 'gitploy/script' configure do |c| - c.repo = 'git@github.com:myuser/fooapp.git' c.path = '/var/www/fooapp' stage :staging do @@ -65,6 +64,5 @@ Gitploy is super alpha - don't use it yet, unless you're just that baller. Are y ### Known issues -* No tests :( * Not enough documentation -* DSL implementation is pretty dumb and needs refactoring \ No newline at end of file +* DSL implementation is pretty dumb and needs refactoring diff --git a/VERSION b/VERSION index 0ea3a94..0c62199 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +0.2.1 diff --git a/features/gitploy.feature b/features/gitploy.feature new file mode 100644 index 0000000..abb00b5 --- /dev/null +++ b/features/gitploy.feature @@ -0,0 +1,63 @@ +Feature: gitploy + + Scenario Outline: Missing options + Given an invalid configuration file + When I run "gitploy " + Then the output should contain: + """ + The following configuration options are missing for the 'staging' stage: path, user, host + """ + Examples: + | arguments | + | staging setup | + | staging | + + Scenario Outline: Pretend execution + Given a valid configuration file + When I run "gitploy " + Then the output should contain "(pretend)" + Examples: + | arguments | + | staging setup --pretend | + | staging setup -p | + | staging --pretend | + | staging -p | + + Scenario: Setup on staging + Given a valid configuration file + When I run "gitploy staging setup --pretend" + Then the output should contain "Setup local" + And the output should contain "ssh staging@staging.gitploy.foo" + And the output should contain "mkdir -p /var/www/fooapp" + And the output should contain "cd /var/www/fooapp && git init" + But the output should not contain "Deploy local" + And the output should not contain "ssh production@gitploy.foo" + And the output should not contain "bundle install" + + Scenario: Deploy on staging + Given a valid configuration file + When I run "gitploy staging --pretend" + Then the output should contain "git push" + And the output should contain "Deploy local" + And the output should contain "cd /var/www/fooapp" + And the output should contain "git reset --hard" + But the output should not contain "Setup local" + And the output should not contain "ssh production@gitploy.foo" + + Scenario: Setup on production + Given a valid configuration file + When I run "gitploy production setup --pretend" + Then the output should contain "Setup local" + And the output should contain "production@gitploy.foo" + But the output should not contain "Deploy local" + And the output should not contain "staging@staging.gitploy.foo" + And the output should not contain "git push" + + Scenario: Deploy on production + Given a valid configuration file + When I run "gitploy production --pretend" + Then the output should contain "Deploy local" + And the output should contain "production@gitploy.foo" + And the output should contain "git push" + But the output should not contain "Setup local" + And the output should not contain "staging@staging.gitploy.foo" diff --git a/features/step_definitions/gitploy_steps.rb b/features/step_definitions/gitploy_steps.rb new file mode 100644 index 0000000..e9b65fb --- /dev/null +++ b/features/step_definitions/gitploy_steps.rb @@ -0,0 +1,58 @@ +Given /^an invalid configuration file$/ do + Given %{a file named "config/deploy.rb" with:}, + """ + require 'gitploy/script' + configure do |c| + stage :staging do + end + end + """ +end + +Given /^a valid configuration file$/ do + Given %{a file named "config/deploy.rb" with:}, + <<-CODE + require 'gitploy/script' + + configure do |c| + c.path = '/var/www/fooapp' + c.local_branch = 'master' + c.remote_branch = 'master' + + stage :staging do + c.host = 'staging.gitploy.foo' + c.user = 'staging' + end + + stage :production do + c.host = 'gitploy.foo' + c.user = 'production' + end + end + + setup do + local do + run "echo 'Setup local'" + end + remote do + run "mkdir -p /var/www/fooapp" + run "cd /var/www/fooapp && git init" + run "git config --bool receive.denyNonFastForwards false" + run "git config receive.denyCurrentBranch ignore" + end + end + + deploy do + push! + local do + run "echo 'Deploy local'" + end + remote do + run "cd /var/www/fooapp" + run "git reset --hard" + run "bundle install --deployment" + run "touch tmp/restart.txt" + end + end + CODE +end diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..3073131 --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,15 @@ +require 'rubygems' +require 'aruba' +require 'fileutils' + +Before do + FileUtils.rm_rf("tmp") + FileUtils.mkdir("tmp") +end + +PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze +BIN_PATH = File.join(PROJECT_ROOT, 'bin').freeze +LIB_PATH = File.join(PROJECT_ROOT, 'lib').freeze + +ENV['PATH'] = [BIN_PATH, ENV['PATH']].join(':') +ENV['RUBYLIB'] = LIB_PATH diff --git a/gitploy.gemspec b/gitploy.gemspec index 6079ac8..0a7028b 100644 --- a/gitploy.gemspec +++ b/gitploy.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{gitploy} - s.version = "0.2.0" + s.version = "0.2.1" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Brent Dillingham"] - s.date = %q{2010-09-14} + s.date = %q{2010-09-29} s.default_executable = %q{gitploy} s.description = %q{Dead-simple deployments. No, for real this time.} s.email = %q{brentdillingham@gmail.com} diff --git a/lib/gitploy.rb b/lib/gitploy.rb index 08161a3..455ee6b 100644 --- a/lib/gitploy.rb +++ b/lib/gitploy.rb @@ -3,7 +3,7 @@ module Gitploy attr_accessor :config class Config - REQUIRED_OPTIONS = [:repo, :path, :user, :host] + REQUIRED_OPTIONS = [:path, :user, :host] attr_accessor *REQUIRED_OPTIONS attr_accessor :local_branch, :remote_branch @@ -41,7 +41,7 @@ def stage(name) end def deploy - yield if action.nil? || action == 'deploy' + yield unless action == 'setup' end def setup @@ -81,12 +81,13 @@ def pretty_run(title, cmd) print_bar(100, title) puts "> #{cmd}" puts - Kernel.system(cmd) + Kernel.system(cmd) unless pretend? print_bar(100) end def print_bar(width, title=nil) if title + title += " (pretend)" if pretend? half_width = (width / 2) - (title.length / 2) - 2 left_bar = '=' * half_width right_bar = '=' * (title.length % 2 == 0 ? half_width : half_width - 1) # TODO: lame. @@ -113,4 +114,9 @@ def current_branch 'master' end end + + def pretend? + pretend = %w(-p --pretend) + ARGV.any? { |v| pretend.include? v } + end end