capistrano-campout 0.0.1 → 0.0.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.
data/README.md CHANGED
@@ -11,7 +11,7 @@ post-deployment success or failure. Event sounds are also supported.
11
11
 
12
12
  ## Design goals
13
13
 
14
- Capistrano::Campout is insipred by and borrows concepts (and in some cases code)
14
+ Capistrano::Campout is inspired by and borrows concepts (and in some cases code)
15
15
  from two projects: [capistrano-mountaintop](https://github.com/technicalpickles/capistrano-mountaintop) and [capfire](https://github.com/pjaspers/capfire).
16
16
 
17
17
  I created my own instead of forking either for the following reasons
@@ -2,8 +2,13 @@
2
2
  # Copyright (c) 2012 Jason Adam Young
3
3
  # === LICENSE:
4
4
  # see LICENSE file
5
+
6
+
5
7
  module Capistrano
6
- module Campout
8
+ module Campout
9
+ class TemplateError < NameError
10
+ end
11
+
7
12
  class Core
8
13
  attr_accessor :settings, :campfire, :room
9
14
 
@@ -64,7 +69,7 @@ module Capistrano
64
69
  end
65
70
 
66
71
  def pre_announce(options = {})
67
- self.speak(ERB.new(settings.pre_deploy.message).result(options[:binding]))
72
+ self.speak(erberize(settings.pre_deploy.message,'pre_deploy message',options[:binding]))
68
73
  if(!settings.suppress_sounds and settings.pre_deploy.play)
69
74
  self.play(settings.pre_deploy.play)
70
75
  end
@@ -72,7 +77,7 @@ module Capistrano
72
77
  end
73
78
 
74
79
  def post_announce_success(options = {})
75
- message = ERB.new(settings.post_deploy_success.message).result(options[:binding])
80
+ message = erberize(settings.post_deploy_success.message,'post_deploy_success message',options[:binding])
76
81
  if(!settings.suppress_deploy_time and @pre_announce_time)
77
82
  message += " (#{time_period_to_s(Time.now - @pre_announce_time)})"
78
83
  end
@@ -112,7 +117,7 @@ module Capistrano
112
117
  end
113
118
 
114
119
  def post_announce_failure(options = {})
115
- message = ERB.new(settings.post_deploy_failure.message).result(options[:binding])
120
+ message = erberize(settings.post_deploy_failure.message,'post_deploy_failure message',options[:binding])
116
121
  self.speak(message)
117
122
  if(!settings.suppress_sounds and settings.post_deploy_failure.play)
118
123
  self.play(settings.post_deploy_failure.play)
@@ -133,7 +138,7 @@ module Capistrano
133
138
 
134
139
  def will_do(options = {})
135
140
  puts "Before Deployment:"
136
- puts "Message: #{ERB.new(settings.pre_deploy.message).result(options[:binding])}"
141
+ puts "Message: #{erberize(settings.pre_deploy.message,'pre_deploy message',options[:binding])}"
137
142
  if(!settings.suppress_sounds and settings.pre_deploy.play)
138
143
  puts "Will play sound: #{settings.pre_deploy.play}"
139
144
  else
@@ -142,7 +147,7 @@ module Capistrano
142
147
 
143
148
  puts "\n"
144
149
  puts "After Successful Deployment:"
145
- puts "Message: #{ERB.new(settings.post_deploy_success.message).result(options[:binding])}"
150
+ puts "Message: #{erberize(settings.post_deploy_success.message,'post_deploy_success message',options[:binding])}"
146
151
  if(!settings.suppress_sounds and settings.post_deploy_success.play)
147
152
  puts "Will play sound: #{settings.post_deploy_success.play}"
148
153
  else
@@ -157,7 +162,7 @@ module Capistrano
157
162
 
158
163
  puts "\n"
159
164
  puts "After Failed Deployment:"
160
- puts "Message: #{ERB.new(settings.post_deploy_failure.message).result(options[:binding])}"
165
+ puts "Message: #{erberize(settings.post_deploy_failure.message,'post_deploy_failure message',options[:binding])}"
161
166
  if(!settings.suppress_sounds and settings.post_deploy_failure.play)
162
167
  puts "Will play sound: #{settings.post_deploy_failure.play}"
163
168
  else
@@ -170,6 +175,23 @@ module Capistrano
170
175
  end
171
176
  end
172
177
 
178
+ def whereto(capistrano_namespace)
179
+ default_value = ENV['SERVER'] || 'production'
180
+ capistrano_namespace.fetch(:stage,default_value)
181
+ end
182
+
183
+ protected
184
+
185
+
186
+ def erberize(string,context,binding)
187
+ begin
188
+ ERB.new(string).result(binding)
189
+ rescue NameError => error
190
+ raise TemplateError, "Your #{context} message references an undefined value: #{error.name}. Set this in your capistrano deploy script"
191
+ end
192
+ end
193
+
194
+
173
195
  # Takes a period of time in seconds and returns it in human-readable form (down to minutes)
174
196
  # code from http://www.postal-code.com/binarycode/2007/04/04/english-friendly-timespan/
175
197
  def time_period_to_s(time_period,abbreviated=false,defaultstring = '')
@@ -1,6 +1,22 @@
1
+ ## campfire settings
2
+ # campfire:
3
+ # domain: 'your_campfire_domain'
4
+ # room: your_room_id
5
+ # token: your_campfire_token
6
+
7
+ ## global action settings
8
+ # copy_log_to_server: false
9
+ # suppress_sounds: false
10
+ # suppress_deploy_time: false
11
+ # suppress_github_compare: false
12
+
13
+ ## deployment settings
1
14
  pre_deploy:
2
- message: "<%= campout_deployer %> is starting to deploy <%= application %> to <%= stage %>"
15
+ message: "<%= campout_deployer %> is starting to deploy <%= application %> to <%= whereto %>"
16
+ # play: 'pushit'
3
17
  post_deploy_success:
4
- message: "<%= campout_deployer %> deployed <%= application %> to <%= stage %>"
18
+ message: "<%= campout_deployer %> deployed <%= application %> to <%= whereto %>"
19
+ # play: 'yeah'
5
20
  post_deploy_failure:
6
- message: "The deploy of <%= application %> to <%= stage %> by <%= campout_deployer %> has failed."
21
+ message: "The deploy of <%= application %> to <%= whereto %> by <%= campout_deployer %> has failed."
22
+ # play: 'drama'
@@ -13,10 +13,12 @@ Capistrano::Configuration.instance(:must_exist).load do
13
13
 
14
14
  ## no descriptions for the following tasks - meant to be hooked by capistrano
15
15
  task :pre_announce do
16
+ set(:whereto,campout_core.whereto(self))
16
17
  campout_core.pre_announce(binding: binding)
17
18
  end
18
19
 
19
20
  task :post_announce_success do
21
+ set(:whereto,campout_core.whereto(self))
20
22
  campout_core.post_announce_success(binding: binding,
21
23
  repository: repository,
22
24
  previous_revision: previous_revision,
@@ -24,17 +26,21 @@ Capistrano::Configuration.instance(:must_exist).load do
24
26
  end
25
27
 
26
28
  task :post_announce_failure do
29
+ set(:whereto,campout_core.whereto(self))
27
30
  campout_core.post_announce_failure(binding: binding)
28
31
  end
29
32
 
30
33
  task :copy_log, :except => { :no_release => true} do
31
- logger = Capistrano::CampoutLogger
32
- run "mkdir -p #{shared_path}/deploy_logs"
33
- put File.open(logger.log_file_path).read, "#{shared_path}/deploy_logs/#{logger.remote_log_file_name}"
34
+ if(campout_core.settings.copy_log_to_server)
35
+ logger = Capistrano::CampoutLogger
36
+ run "mkdir -p #{shared_path}/deploy_logs"
37
+ put File.open(logger.log_file_path).read, "#{shared_path}/deploy_logs/#{logger.remote_log_file_name}"
38
+ end
34
39
  end
35
40
 
36
41
  desc "Display campfire messages and actions based on current configuration"
37
42
  task :will_do do
43
+ set(:whereto,campout_core.whereto(self))
38
44
  campout_core.will_do(binding: binding)
39
45
  end
40
46
 
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Campout
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-campout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-07 00:00:00.000000000 Z
12
+ date: 2012-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &70114418631680 !ruby/object:Gem::Requirement
16
+ requirement: &70315888091420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.11'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70114418631680
24
+ version_requirements: *70315888091420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tinder
27
- requirement: &70114418615660 !ruby/object:Gem::Requirement
27
+ requirement: &70315888075700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.8'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70114418615660
35
+ version_requirements: *70315888075700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: grit
38
- requirement: &70114418614880 !ruby/object:Gem::Requirement
38
+ requirement: &70315888074660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '2.4'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70114418614880
46
+ version_requirements: *70315888074660
47
47
  description: ! " Capistrano::Campout is a gem extension to capistrano to post/speak
48
48
  messages and paste logs from a capistrano deployment \n to a campfire room. Settings
49
49
  are configurable using ERB in a \"config/campout.yml\" or \"config/campout.local.yml\"
@@ -62,7 +62,6 @@ files:
62
62
  - Rakefile
63
63
  - capistrano-campout.gemspec
64
64
  - lib/capistrano-campout.rb
65
- - lib/capistrano-campout/cap_tasks.rb
66
65
  - lib/capistrano-campout/core.rb
67
66
  - lib/capistrano-campout/deep_merge.rb
68
67
  - lib/capistrano-campout/defaults.yml
@@ -1,50 +0,0 @@
1
- # === COPYRIGHT:
2
- # Copyright (c) 2012 Jason Adam Young
3
- # === LICENSE:
4
- # see LICENSE file
5
-
6
- Capistrano::Configuration.instance(:must_exist).load do
7
- # Don't bother users who have capfire installed but don't have a ~/.campfire file
8
-
9
- if Capfire.config_file_exists?
10
- if Capfire.valid_config?
11
- before "deploy:update_code", "capfire:check_for_push"
12
- after "deploy:update_code", "capfire:post_to_campfire"
13
- else
14
- logger.info "Not all required keys found in your .campfire file. Please regenerate."
15
- end
16
- else
17
- logger.info "Couldn't find a .campfire in your home directory."
18
- end
19
-
20
-
21
-
22
- desc <<-DESC
23
- This will post to the campfire room as specified in your ~/.campfire. \
24
- The message posted will contain a link to Github's excellent compare view, \
25
- the commiters name, the project name and the arguments supplied to cap.
26
- DESC
27
- task :post_to_campfire do
28
- begin
29
- source_repo_url = repository
30
- deployed_version = previous_revision[0,7] rescue "000000"
31
- local_version = `git rev-parse HEAD`[0,7]
32
-
33
- compare_url = Capfire.github_compare_url source_repo_url, deployed_version, local_version
34
- message = Capfire.deploy_message(ARGV.join(' '), compare_url, application)
35
- message = `cowsay "#{message}"` if Capfire.cowsay?
36
-
37
- if dry_run
38
- logger.info "Capfire would have posted:\n#{message}"
39
- else
40
- Capfire.speak message
41
- end
42
- logger.info "Posting to Campfire"
43
- rescue => e
44
- # Making sure we don't make capistrano fail.
45
- # Cause nothing sucks donkeyballs like not being able to deploy
46
- logger.important e.message
47
- end
48
- end
49
- end
50
- end