hydraulic_brake 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +7 -0
- data/Gemfile +1 -14
- data/README.md +16 -22
- data/VERSION +1 -1
- data/hydraulic_brake.gemspec +39 -50
- data/lib/hydraulic_brake.rb +12 -3
- data/lib/hydraulic_brake/async_sender.rb +39 -0
- data/lib/hydraulic_brake/configuration.rb +14 -1
- data/lib/hydraulic_brake/sender.rb +39 -11
- data/test/async_sender_test.rb +105 -0
- data/test/configuration_test.rb +23 -15
- data/test/helper.rb +11 -3
- data/test/logger_test.rb +1 -1
- data/test/notifier_test.rb +18 -1
- data/test/sender_test.rb +40 -18
- metadata +33 -92
- data/.rbenv-version +0 -1
- data/features/rake.feature +0 -27
- data/features/step_definitions/rake_steps.rb +0 -17
- data/features/support/matchers.rb +0 -35
- data/features/support/rake/Rakefile +0 -61
- data/features/support/terminal.rb +0 -107
- data/lib/hydraulic_brake/hook.rb +0 -53
- data/lib/hydraulic_brake_tasks.rb +0 -63
- data/script/deploy_integration_test.rb +0 -25
data/.rbenv-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.9.3-p194
|
data/features/rake.feature
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
Feature: Use the Gem to catch errors in a Rake application
|
2
|
-
Background:
|
3
|
-
Given I have built and installed the "airbrake" gem
|
4
|
-
|
5
|
-
Scenario: Catching exceptions in Rake
|
6
|
-
When I run rake with airbrake
|
7
|
-
Then Airbrake should catch the exception
|
8
|
-
|
9
|
-
Scenario: Falling back to default handler before Airbrake is configured
|
10
|
-
When I run rake with airbrake not yet configured
|
11
|
-
Then Airbrake should not catch the exception
|
12
|
-
|
13
|
-
Scenario: Disabling Rake exception catcher
|
14
|
-
When I run rake with airbrake disabled
|
15
|
-
Then Airbrake should not catch the exception
|
16
|
-
|
17
|
-
Scenario: Autodetect, running from terminal
|
18
|
-
When I run rake with airbrake autodetect from terminal
|
19
|
-
Then Airbrake should not catch the exception
|
20
|
-
|
21
|
-
Scenario: Autodetect, not running from terminal
|
22
|
-
When I run rake with airbrake autodetect not from terminal
|
23
|
-
Then Airbrake should catch the exception
|
24
|
-
|
25
|
-
Scenario: Sending the correct component name
|
26
|
-
When I run rake with airbrake
|
27
|
-
Then Airbrake should send the rake command line as the component name
|
@@ -1,17 +0,0 @@
|
|
1
|
-
When /I run rake with (.+)/ do |command|
|
2
|
-
@rake_command = "rake #{command.gsub(' ','_')}"
|
3
|
-
@rake_result = `cd features/support/rake && GEM_HOME=#{BUILT_GEM_ROOT} #{@rake_command} 2>&1`
|
4
|
-
end
|
5
|
-
|
6
|
-
Then /Airbrake should (|not) ?catch the exception/ do |condition|
|
7
|
-
if condition=='not'
|
8
|
-
@rake_result.should_not =~ /^airbrake/
|
9
|
-
else
|
10
|
-
@rake_result.should =~ /^airbrake/
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
Then /Airbrake should send the rake command line as the component name/ do
|
15
|
-
component = @rake_result.match(/^airbrake (.*)$/)[1]
|
16
|
-
component.should == @rake_command
|
17
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :have_content do |xpath, content|
|
2
|
-
match do |document|
|
3
|
-
@elements = document.search(xpath)
|
4
|
-
|
5
|
-
if @elements.empty?
|
6
|
-
false
|
7
|
-
else
|
8
|
-
element_with_content = document.at("#{xpath}[contains(.,'#{content}')]")
|
9
|
-
|
10
|
-
if element_with_content.nil?
|
11
|
-
@found = @elements.collect { |element| element.content }
|
12
|
-
|
13
|
-
false
|
14
|
-
else
|
15
|
-
true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
failure_message_for_should do |document|
|
21
|
-
if @elements.empty?
|
22
|
-
"In XML:\n#{document}\nNo element at #{xpath}"
|
23
|
-
else
|
24
|
-
"In XML:\n#{document}\nGot content #{@found.inspect} at #{xpath} instead of #{content.inspect}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
failure_message_for_should_not do |document|
|
29
|
-
unless @elements.empty?
|
30
|
-
"In XML:\n#{document}\nExpcted no content #{content.inspect} at #{xpath}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
World(RSpec::Matchers)
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# A test harness for RakeHandler
|
2
|
-
#
|
3
|
-
require 'rake'
|
4
|
-
require 'rubygems'
|
5
|
-
require 'hydraulic_brake'
|
6
|
-
require 'hydraulic_brake/rake_handler'
|
7
|
-
|
8
|
-
HydraulicBrake.configure do |c|
|
9
|
-
end
|
10
|
-
|
11
|
-
# Should catch exception
|
12
|
-
task :hydraulic_brake do
|
13
|
-
HydraulicBrake.configuration.rescue_rake_exceptions = true
|
14
|
-
stub_tty_output(true)
|
15
|
-
raise_exception
|
16
|
-
end
|
17
|
-
|
18
|
-
# Should not catch exception
|
19
|
-
task :hydraulic_brake_disabled do
|
20
|
-
HydraulicBrake.configuration.rescue_rake_exceptions = false
|
21
|
-
stub_tty_output(true)
|
22
|
-
raise_exception
|
23
|
-
end
|
24
|
-
|
25
|
-
# Should not catch exception as tty_output is true
|
26
|
-
task :hydraulic_brake_autodetect_from_terminal do
|
27
|
-
HydraulicBrake.configuration.rescue_rake_exceptions = nil
|
28
|
-
stub_tty_output(true)
|
29
|
-
raise_exception
|
30
|
-
end
|
31
|
-
|
32
|
-
# Should catch exception as tty_output is false
|
33
|
-
task :hydraulic_brake_autodetect_not_from_terminal do
|
34
|
-
HydraulicBrake.configuration.rescue_rake_exceptions = nil
|
35
|
-
stub_tty_output(false)
|
36
|
-
raise_exception
|
37
|
-
end
|
38
|
-
|
39
|
-
task :hydraulic_brake_not_yet_configured do
|
40
|
-
HydraulicBrake.configuration.rescue_rake_exceptions = true
|
41
|
-
stub_tty_output(true)
|
42
|
-
stub_empty_sender
|
43
|
-
raise_exception
|
44
|
-
end
|
45
|
-
|
46
|
-
def stub_empty_sender
|
47
|
-
HydraulicBrake.sender = nil
|
48
|
-
end
|
49
|
-
|
50
|
-
def stub_tty_output(value)
|
51
|
-
Rake.application.instance_eval do
|
52
|
-
@tty_output_stub = value
|
53
|
-
def tty_output?
|
54
|
-
@tty_output_stub
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def raise_exception
|
60
|
-
raise 'TEST'
|
61
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
Before do
|
4
|
-
@terminal = Terminal.new
|
5
|
-
end
|
6
|
-
|
7
|
-
After do |story|
|
8
|
-
if story.failed?
|
9
|
-
# puts @terminal.output
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Terminal
|
14
|
-
attr_reader :output, :status
|
15
|
-
attr_accessor :environment_variables, :invoke_heroku_rake_tasks_locally
|
16
|
-
|
17
|
-
def initialize
|
18
|
-
@cwd = FileUtils.pwd
|
19
|
-
@output = ""
|
20
|
-
@status = 0
|
21
|
-
@logger = Logger.new(File.join(TEMP_DIR, 'terminal.log'))
|
22
|
-
|
23
|
-
@invoke_heroku_rake_tasks_locally = false
|
24
|
-
|
25
|
-
@environment_variables = {
|
26
|
-
"GEM_HOME" => LOCAL_GEM_ROOT,
|
27
|
-
"GEM_PATH" => "#{LOCAL_GEM_ROOT}:#{BUILT_GEM_ROOT}",
|
28
|
-
"PATH" => "#{gem_bin_path}:#{ENV['PATH']}"
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def cd(directory)
|
33
|
-
@cwd = directory
|
34
|
-
end
|
35
|
-
|
36
|
-
def run(command)
|
37
|
-
command = optionally_invoke_heroku_rake_tasks_locally(command)
|
38
|
-
|
39
|
-
output << "#{command}\n"
|
40
|
-
FileUtils.cd(@cwd) do
|
41
|
-
# The ; forces ruby to shell out so the env settings work right
|
42
|
-
cmdline = "#{environment_settings} #{command} 2>&1 ; "
|
43
|
-
logger.debug(cmdline)
|
44
|
-
result = `#{cmdline}`
|
45
|
-
logger.debug(result)
|
46
|
-
output << result
|
47
|
-
end
|
48
|
-
@status = $?
|
49
|
-
end
|
50
|
-
|
51
|
-
def optionally_invoke_heroku_rake_tasks_locally(command)
|
52
|
-
if invoke_heroku_rake_tasks_locally
|
53
|
-
command.sub(/^heroku /, '')
|
54
|
-
else
|
55
|
-
command
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def echo(string)
|
60
|
-
logger.debug(string)
|
61
|
-
end
|
62
|
-
|
63
|
-
def flush!
|
64
|
-
@output = ""
|
65
|
-
end
|
66
|
-
|
67
|
-
def build_and_install_gem(gemspec)
|
68
|
-
pkg_dir = File.join(TEMP_DIR, 'pkg')
|
69
|
-
FileUtils.mkdir_p(pkg_dir)
|
70
|
-
output = `gem build #{gemspec} 2>&1`
|
71
|
-
gem_file = Dir.glob("*.gem").first
|
72
|
-
unless gem_file
|
73
|
-
raise "Gem didn't build:\n#{output}"
|
74
|
-
end
|
75
|
-
target = File.join(pkg_dir, gem_file)
|
76
|
-
FileUtils.mv(gem_file, target)
|
77
|
-
install_gem_to(LOCAL_GEM_ROOT, target)
|
78
|
-
end
|
79
|
-
|
80
|
-
def install_gem(gem)
|
81
|
-
install_gem_to(LOCAL_GEM_ROOT, gem)
|
82
|
-
end
|
83
|
-
|
84
|
-
def uninstall_gem(gem)
|
85
|
-
`gem uninstall -i #{LOCAL_GEM_ROOT} #{gem}`
|
86
|
-
end
|
87
|
-
|
88
|
-
def prepend_path(path)
|
89
|
-
@environment_variables['PATH'] = path + ":" + @environment_variables['PATH']
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
|
-
|
94
|
-
def install_gem_to(root, gem)
|
95
|
-
`gem install -i #{root} --no-ri --no-rdoc #{gem}`
|
96
|
-
end
|
97
|
-
|
98
|
-
def environment_settings
|
99
|
-
@environment_variables.map { |key, value| "#{key}=#{value}" }.join(' ')
|
100
|
-
end
|
101
|
-
|
102
|
-
def gem_bin_path
|
103
|
-
File.join(LOCAL_GEM_ROOT, "bin")
|
104
|
-
end
|
105
|
-
|
106
|
-
attr_reader :logger
|
107
|
-
end
|
data/lib/hydraulic_brake/hook.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
module HydraulicBrake
|
5
|
-
module Hook
|
6
|
-
|
7
|
-
# Alerts Airbrake of a deploy.
|
8
|
-
#
|
9
|
-
# @param [Hash] opts Data about the deploy that is set to Airbrake
|
10
|
-
#
|
11
|
-
# @option opts [String] :api_key Api key of you Airbrake application
|
12
|
-
# @option opts [String] :scm_revision The given revision/sha that is being deployed
|
13
|
-
# @option opts [String] :scm_repository Address of your repository to help with code lookups
|
14
|
-
# @option opts [String] :local_username Who is deploying
|
15
|
-
def self.deploy(opts = {})
|
16
|
-
api_key = opts.delete(:api_key) || HydraulicBrake.configuration.api_key
|
17
|
-
if api_key.empty?
|
18
|
-
puts "I don't seem to be configured with an API key. Please check your configuration."
|
19
|
-
return false
|
20
|
-
end
|
21
|
-
|
22
|
-
params = {'api_key' => api_key}
|
23
|
-
opts.each {|k,v| params["deploy[#{k}]"] = v }
|
24
|
-
|
25
|
-
host = HydraulicBrake.configuration.host
|
26
|
-
port = HydraulicBrake.configuration.port
|
27
|
-
|
28
|
-
proxy = Net::HTTP.Proxy(HydraulicBrake.configuration.proxy_host,
|
29
|
-
HydraulicBrake.configuration.proxy_port,
|
30
|
-
HydraulicBrake.configuration.proxy_user,
|
31
|
-
HydraulicBrake.configuration.proxy_pass)
|
32
|
-
http = proxy.new(host, port)
|
33
|
-
|
34
|
-
# Handle Security
|
35
|
-
if HydraulicBrake.configuration.secure?
|
36
|
-
http.use_ssl = true
|
37
|
-
http.ca_file = HydraulicBrake.configuration.ca_bundle_path
|
38
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
39
|
-
end
|
40
|
-
|
41
|
-
post = Net::HTTP::Post.new("/deploys.txt")
|
42
|
-
post.set_form_data(params)
|
43
|
-
|
44
|
-
response = http.request(post)
|
45
|
-
|
46
|
-
puts response.body
|
47
|
-
return Net::HTTPSuccess === response
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
module HydraulicBrakeTasks
|
5
|
-
|
6
|
-
# Alerts Airbrake of a deploy.
|
7
|
-
#
|
8
|
-
# @param [Hash] opts Data about the deploy that is set to Airbrake
|
9
|
-
#
|
10
|
-
# @option opts [String] :api_key Api key of you Airbrake application
|
11
|
-
# @option opts [String] :env Environment of the deploy (production, staging)
|
12
|
-
# @option opts [String] :scm_revision The given revision/sha that is being deployed
|
13
|
-
# @option opts [String] :scm_repository Address of your repository to help with code lookups
|
14
|
-
# @option opts [String] :local_username Who is deploying
|
15
|
-
def self.deploy(opts = {})
|
16
|
-
api_key = opts.delete(:api_key) || HydraulicBrake.configuration.api_key
|
17
|
-
if api_key.empty?
|
18
|
-
puts "I don't seem to be configured with an API key. Please check your configuration."
|
19
|
-
return false
|
20
|
-
end
|
21
|
-
|
22
|
-
if opts[:env].empty?
|
23
|
-
puts "I don't know to which environment you are deploying (use the TO=production option)."
|
24
|
-
return false
|
25
|
-
end
|
26
|
-
|
27
|
-
dry_run = opts.delete(:dry_run)
|
28
|
-
params = {'api_key' => api_key}
|
29
|
-
opts.each {|k,v| params["deploy[#{k}]"] = v }
|
30
|
-
|
31
|
-
host = HydraulicBrake.configuration.host
|
32
|
-
port = HydraulicBrake.configuration.port
|
33
|
-
|
34
|
-
proxy = Net::HTTP.Proxy(HydraulicBrake.configuration.proxy_host,
|
35
|
-
HydraulicBrake.configuration.proxy_port,
|
36
|
-
HydraulicBrake.configuration.proxy_user,
|
37
|
-
HydraulicBrake.configuration.proxy_pass)
|
38
|
-
http = proxy.new(host, port)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# Handle Security
|
43
|
-
if HydraulicBrake.configuration.secure?
|
44
|
-
http.use_ssl = true
|
45
|
-
http.ca_file = HydraulicBrake.configuration.ca_bundle_path
|
46
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
47
|
-
end
|
48
|
-
|
49
|
-
post = Net::HTTP::Post.new("/deploys.txt")
|
50
|
-
post.set_form_data(params)
|
51
|
-
|
52
|
-
if dry_run
|
53
|
-
puts http.inspect, params.inspect
|
54
|
-
return true
|
55
|
-
else
|
56
|
-
response = http.request(post)
|
57
|
-
|
58
|
-
puts response.body
|
59
|
-
return Net::HTTPSuccess === response
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
-
require 'hydraulic_brake'
|
5
|
-
|
6
|
-
fail "Please supply an API Key as the first argument" if ARGV.empty?
|
7
|
-
|
8
|
-
host = ARGV[1]
|
9
|
-
|
10
|
-
secure = (ARGV[2] == "secure")
|
11
|
-
|
12
|
-
HydraulicBrake.configure do |config|
|
13
|
-
config.secure = secure
|
14
|
-
config.host = host
|
15
|
-
config.api_key = ARGV.first
|
16
|
-
end
|
17
|
-
|
18
|
-
HydraulicBrake::Hook.deploy({
|
19
|
-
:api_key => ARGV.first,
|
20
|
-
:scm_revision => "cd6b969f66ad0794c7117d5030f926b49f82b038",
|
21
|
-
:scm_repository => "stevecrozz/hydraulic_brake",
|
22
|
-
:local_username => "stevecrozz",
|
23
|
-
:rails_env => "production", # everything is rails, right?
|
24
|
-
:message => "Another deployment hook brought to you by HydraulicBrake"
|
25
|
-
})
|