gitploy 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,8 +13,7 @@ require git hooks, it just does the bare minimum. It's so minimal, in fact, that
13
13
  come with its own "recipe" - Gitploy is actually just a DSL to quickly define your own deployment
14
14
  strategy. No hooks, very little behind-the-scenes magic - it just does what you tell it to.
15
15
 
16
- ### Example config/deploy.rb
17
-
16
+ ### Example config/gitploy.rb
18
17
 
19
18
  require 'gitploy/script'
20
19
 
@@ -64,6 +63,5 @@ Gitploy is super alpha - don't use it yet, unless you're just that baller. Are y
64
63
 
65
64
  ### Known issues
66
65
 
67
- * No tests :(
68
66
  * Not enough documentation
69
- * DSL implementation is pretty dumb and needs refactoring
67
+ * DSL implementation is pretty dumb and needs refactoring
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env ruby
2
- load('config/deploy.rb')
2
+ load('config/gitploy.rb')
@@ -0,0 +1,63 @@
1
+ Feature: gitploy
2
+
3
+ Scenario Outline: Missing options
4
+ Given an invalid configuration file
5
+ When I run "gitploy <arguments>"
6
+ Then the output should contain:
7
+ """
8
+ The following configuration options are missing for the 'staging' stage: path, user, host
9
+ """
10
+ Examples:
11
+ | arguments |
12
+ | staging setup |
13
+ | staging |
14
+
15
+ Scenario Outline: Pretend execution
16
+ Given a valid configuration file
17
+ When I run "gitploy <arguments>"
18
+ Then the output should contain "(pretend)"
19
+ Examples:
20
+ | arguments |
21
+ | staging setup --pretend |
22
+ | staging setup -p |
23
+ | staging --pretend |
24
+ | staging -p |
25
+
26
+ Scenario: Setup on staging
27
+ Given a valid configuration file
28
+ When I run "gitploy staging setup --pretend"
29
+ Then the output should contain "Setup local"
30
+ And the output should contain "ssh staging@staging.gitploy.foo"
31
+ And the output should contain "mkdir -p /var/www/fooapp"
32
+ And the output should contain "cd /var/www/fooapp && git init"
33
+ But the output should not contain "Deploy local"
34
+ And the output should not contain "ssh production@gitploy.foo"
35
+ And the output should not contain "bundle install"
36
+
37
+ Scenario: Deploy on staging
38
+ Given a valid configuration file
39
+ When I run "gitploy staging --pretend"
40
+ Then the output should contain "git push"
41
+ And the output should contain "Deploy local"
42
+ And the output should contain "cd /var/www/fooapp"
43
+ And the output should contain "git reset --hard"
44
+ But the output should not contain "Setup local"
45
+ And the output should not contain "ssh production@gitploy.foo"
46
+
47
+ Scenario: Setup on production
48
+ Given a valid configuration file
49
+ When I run "gitploy production setup --pretend"
50
+ Then the output should contain "Setup local"
51
+ And the output should contain "production@gitploy.foo"
52
+ But the output should not contain "Deploy local"
53
+ And the output should not contain "staging@staging.gitploy.foo"
54
+ And the output should not contain "git push"
55
+
56
+ Scenario: Deploy on production
57
+ Given a valid configuration file
58
+ When I run "gitploy production --pretend"
59
+ Then the output should contain "Deploy local"
60
+ And the output should contain "production@gitploy.foo"
61
+ And the output should contain "git push"
62
+ But the output should not contain "Setup local"
63
+ And the output should not contain "staging@staging.gitploy.foo"
@@ -0,0 +1,58 @@
1
+ Given /^an invalid configuration file$/ do
2
+ Given %{a file named "config/deploy.rb" with:},
3
+ """
4
+ require 'gitploy/script'
5
+ configure do |c|
6
+ stage :staging do
7
+ end
8
+ end
9
+ """
10
+ end
11
+
12
+ Given /^a valid configuration file$/ do
13
+ Given %{a file named "config/deploy.rb" with:},
14
+ <<-CODE
15
+ require 'gitploy/script'
16
+
17
+ configure do |c|
18
+ c.path = '/var/www/fooapp'
19
+ c.local_branch = 'master'
20
+ c.remote_branch = 'master'
21
+
22
+ stage :staging do
23
+ c.host = 'staging.gitploy.foo'
24
+ c.user = 'staging'
25
+ end
26
+
27
+ stage :production do
28
+ c.host = 'gitploy.foo'
29
+ c.user = 'production'
30
+ end
31
+ end
32
+
33
+ setup do
34
+ local do
35
+ run "echo 'Setup local'"
36
+ end
37
+ remote do
38
+ run "mkdir -p /var/www/fooapp"
39
+ run "cd /var/www/fooapp && git init"
40
+ run "git config --bool receive.denyNonFastForwards false"
41
+ run "git config receive.denyCurrentBranch ignore"
42
+ end
43
+ end
44
+
45
+ deploy do
46
+ push!
47
+ local do
48
+ run "echo 'Deploy local'"
49
+ end
50
+ remote do
51
+ run "cd /var/www/fooapp"
52
+ run "git reset --hard"
53
+ run "bundle install --deployment"
54
+ run "touch tmp/restart.txt"
55
+ end
56
+ end
57
+ CODE
58
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'aruba'
3
+ require 'fileutils'
4
+
5
+ Before do
6
+ FileUtils.rm_rf("tmp")
7
+ FileUtils.mkdir("tmp")
8
+ end
9
+
10
+ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
11
+ BIN_PATH = File.join(PROJECT_ROOT, 'bin').freeze
12
+ LIB_PATH = File.join(PROJECT_ROOT, 'lib').freeze
13
+
14
+ ENV['PATH'] = [BIN_PATH, ENV['PATH']].join(':')
15
+ ENV['RUBYLIB'] = LIB_PATH
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gitploy}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brent Dillingham"]
12
- s.date = %q{2010-09-29}
12
+ s.date = %q{2011-03-17}
13
13
  s.default_executable = %q{gitploy}
14
14
  s.description = %q{Dead-simple deployments. No, for real this time.}
15
15
  s.email = %q{brentdillingham@gmail.com}
@@ -23,15 +23,26 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "bin/gitploy",
26
+ "features/gitploy.feature",
27
+ "features/step_definitions/gitploy_steps.rb",
28
+ "features/support/env.rb",
26
29
  "gitploy.gemspec",
27
30
  "lib/gitploy.rb",
28
- "lib/gitploy/script.rb"
31
+ "lib/gitploy/script.rb",
32
+ "spec/gitploy_config_spec.rb",
33
+ "spec/gitploy_spec.rb",
34
+ "spec/spec_helper.rb"
29
35
  ]
30
36
  s.homepage = %q{http://github.com/brentd/gitploy}
31
37
  s.rdoc_options = ["--charset=UTF-8"]
32
38
  s.require_paths = ["lib"]
33
39
  s.rubygems_version = %q{1.3.7}
34
40
  s.summary = %q{Deployment DSL created with git in mind}
41
+ s.test_files = [
42
+ "spec/gitploy_config_spec.rb",
43
+ "spec/gitploy_spec.rb",
44
+ "spec/spec_helper.rb"
45
+ ]
35
46
 
36
47
  if s.respond_to? :specification_version then
37
48
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -41,7 +41,7 @@ module Gitploy
41
41
  end
42
42
 
43
43
  def deploy
44
- yield if action.nil? || action == 'deploy'
44
+ yield unless action == 'setup'
45
45
  end
46
46
 
47
47
  def setup
@@ -76,17 +76,20 @@ module Gitploy
76
76
 
77
77
  private
78
78
 
79
+ #FIXME move to representation class
79
80
  def pretty_run(title, cmd)
80
81
  puts
81
82
  print_bar(100, title)
82
83
  puts "> #{cmd}"
83
84
  puts
84
- Kernel.system(cmd)
85
+ Kernel.system(cmd) unless pretend?
85
86
  print_bar(100)
86
87
  end
87
88
 
89
+ #FIXME move to representation class
88
90
  def print_bar(width, title=nil)
89
91
  if title
92
+ title += " (pretend)" if pretend?
90
93
  half_width = (width / 2) - (title.length / 2) - 2
91
94
  left_bar = '=' * half_width
92
95
  right_bar = '=' * (title.length % 2 == 0 ? half_width : half_width - 1) # TODO: lame.
@@ -113,4 +116,9 @@ module Gitploy
113
116
  'master'
114
117
  end
115
118
  end
119
+
120
+ def pretend?
121
+ pretend = %w(-p --pretend)
122
+ ARGV.any? { |v| pretend.include? v }
123
+ end
116
124
  end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/gitploy")
3
+
4
+ describe 'Gitploy::Config' do
5
+ context 'initialization' do
6
+ it 'can be created' do
7
+ Gitploy::Config.new.should_not be_nil
8
+ end
9
+ end
10
+ context 'attribute storing' do
11
+ before :each do
12
+ @config = Gitploy::Config.new
13
+ end
14
+ it 'stores path' do
15
+ @config.path = 'test'
16
+ @config.path.should eql 'test'
17
+ end
18
+ it 'stores user' do
19
+ @config.user = 'test'
20
+ @config.user.should eql 'test'
21
+ end
22
+ it 'stores host' do
23
+ @config.host = 'test'
24
+ @config.host.should eql 'test'
25
+ end
26
+ it 'stores local_branch' do
27
+ @config.local_branch = 'test'
28
+ @config.local_branch.should eql 'test'
29
+ end
30
+ it 'stores remote_branch' do
31
+ @config.remote_branch = 'test'
32
+ @config.remote_branch.should eql 'test'
33
+ end
34
+ end
35
+ context 'attribute checking' do
36
+ it 'returns missing options' do
37
+ config = Gitploy::Config.new
38
+ config.user = 'test'
39
+ config.host = 'test'
40
+ config.missing_options.should eql [:path]
41
+ end
42
+ it 'raises error when checked' do
43
+ Gitploy.stub!(:current_stage).and_return('test')
44
+ config = Gitploy::Config.new
45
+ config.user = 'test'
46
+ config.host = 'test'
47
+ lambda {config.check!}.should raise_error(RuntimeError, "The following configuration options are missing for the 'test' stage: path")
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,171 @@
1
+ require 'spec_helper'
2
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/gitploy")
3
+ include Gitploy
4
+
5
+ describe 'Giploy' do
6
+ context 'setting arguments' do
7
+ it 'returns current stage from ARGV[0]' do
8
+ ARGV[0] = 'test'
9
+ current_stage.should == 'test'
10
+ end
11
+ it 'returns current action from ARGV[1]' do
12
+ ARGV[1] = 'setup'
13
+ action.should == 'setup'
14
+ end
15
+ end
16
+ context 'consuming config' do
17
+ it 'yields block for current stage' do
18
+ ARGV[0] = 'test'
19
+ lambda do
20
+ stage :test do
21
+ raise 'Error'
22
+ end
23
+ end.should raise_error
24
+ end
25
+ it 'does not yield block for other stage' do
26
+ ARGV[0] = 'test'
27
+ lambda do
28
+ stage :staging do
29
+ raise 'Error'
30
+ end
31
+ end.should_not raise_error
32
+ end
33
+ it 'yields block for deploy when action is not set' do
34
+ ARGV[1] = nil
35
+ lambda do
36
+ deploy do
37
+ raise 'Error'
38
+ end
39
+ end.should raise_error
40
+ end
41
+ it 'yields block for deploy when action is set to deploy' do
42
+ ARGV[1] = 'deploy'
43
+ lambda do
44
+ deploy do
45
+ raise 'Error'
46
+ end
47
+ end.should raise_error
48
+ end
49
+ it 'yields block for setup when action is set to setup' do
50
+ ARGV[1] = 'setup'
51
+ lambda do
52
+ setup do
53
+ raise 'Error'
54
+ end
55
+ end.should raise_error
56
+ end
57
+ it 'does not yield block for setup when action is set to deploy' do
58
+ ARGV[1] = 'deploy'
59
+ lambda do
60
+ setup do
61
+ raise 'Error'
62
+ end
63
+ end.should_not raise_error
64
+ end
65
+ it 'is configured in block with required options set' do
66
+ ARGV[0] = 'test'
67
+ configure do |config|
68
+ config.path = '/var/apps'
69
+ stage :test do
70
+ config.host = 'example.org'
71
+ config.user = 'deploy'
72
+ end
73
+ end
74
+ end
75
+ it 'raises error when option is missing' do
76
+ ARGV[0] = 'test'
77
+ lambda do
78
+ configure do |config|
79
+ config.path = '/var/apps'
80
+ stage :test do
81
+ config.host = 'example.org'
82
+ end
83
+ end
84
+ end.should raise_error
85
+ end
86
+ end
87
+ context 'running queue' do
88
+ it 'adds command to queue' do
89
+ run 'test'
90
+ run 'test'
91
+ instance_variable_get(:@run_queue).should == ['test', 'test']
92
+ end
93
+ it 'adds sudo commands to queue' do
94
+ sudo 'test'
95
+ sudo 'test'
96
+ instance_variable_get(:@run_queue).should == ['sudo test', 'sudo test']
97
+ end
98
+ it 'adds rake commands to queue' do
99
+ rake 'test'
100
+ rake 'test'
101
+ instance_variable_get(:@run_queue).should == ['rake test', 'rake test']
102
+ end
103
+ it 'flushes command queue' do
104
+ run 'test'
105
+ run 'test'
106
+ send(:flush_run_queue)
107
+ instance_variable_get(:@run_queue).should == []
108
+ end
109
+ it 'returns all added commands joined for execution when flushing queue' do
110
+ run 'test'
111
+ run 'test'
112
+ send(:flush_run_queue).should == 'test && test'
113
+ end
114
+ end
115
+ context 'remote and local evaluating' do
116
+ before :each do
117
+ ARGV[0] = 'test'
118
+ @config = configure do |config|
119
+ config.path = '/var/apps'
120
+ stage :test do
121
+ config.host = 'example.org'
122
+ config.user = 'deploy'
123
+ config.local_branch = 'master'
124
+ end
125
+ end
126
+ end
127
+ it 'flushes run queue after running remote block' do
128
+ stub!(:pretty_run).and_return(nil)
129
+ remote do
130
+ run 'test'
131
+ run 'test'
132
+ end
133
+ instance_variable_get(:@run_queue).should == []
134
+ end
135
+ it 'executes remote command from block' do
136
+ should_receive(:pretty_run).with("example.org", "ssh deploy@example.org 'test && test'")
137
+ remote do
138
+ run 'test'
139
+ run 'test'
140
+ end
141
+ end
142
+ it 'flushes run queue after running local block' do
143
+ should_receive(:pretty_run).and_return(nil)
144
+ local do
145
+ run 'test'
146
+ run 'test'
147
+ end
148
+ instance_variable_get(:@run_queue).should == []
149
+ end
150
+ it 'executes local command from block' do
151
+ stub!(:pretty_run).and_return(nil)
152
+ local do
153
+ run 'test'
154
+ run 'test'
155
+ end
156
+ end
157
+ it 'pushes local changes' do
158
+ should_receive(:pretty_run).with("LOCAL",
159
+ "git push deploy@example.org:/var/apps/.git master:master")
160
+ deploy do
161
+ push!
162
+ end
163
+ end
164
+ end
165
+ context 'detecting environment' do
166
+ it 'returns current git branch' do
167
+ should_receive(:`).with('git symbolic-ref HEAD').and_return('refs/heads/test')
168
+ send(:current_branch).should == 'test'
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitploy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brent Dillingham
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-29 00:00:00 -04:00
18
+ date: 2011-03-17 00:00:00 -04:00
19
19
  default_executable: gitploy
20
20
  dependencies: []
21
21
 
@@ -33,9 +33,15 @@ files:
33
33
  - Rakefile
34
34
  - VERSION
35
35
  - bin/gitploy
36
+ - features/gitploy.feature
37
+ - features/step_definitions/gitploy_steps.rb
38
+ - features/support/env.rb
36
39
  - gitploy.gemspec
37
40
  - lib/gitploy.rb
38
41
  - lib/gitploy/script.rb
42
+ - spec/gitploy_config_spec.rb
43
+ - spec/gitploy_spec.rb
44
+ - spec/spec_helper.rb
39
45
  has_rdoc: true
40
46
  homepage: http://github.com/brentd/gitploy
41
47
  licenses: []
@@ -70,5 +76,7 @@ rubygems_version: 1.3.7
70
76
  signing_key:
71
77
  specification_version: 3
72
78
  summary: Deployment DSL created with git in mind
73
- test_files: []
74
-
79
+ test_files:
80
+ - spec/gitploy_config_spec.rb
81
+ - spec/gitploy_spec.rb
82
+ - spec/spec_helper.rb