blade-sauce_labs_plugin 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e381b6eff5f2e879de4c37cb3310798c6b62fbdd
4
- data.tar.gz: 31539f745916aa6ca7d3501995fbcbec4850ffe6
3
+ metadata.gz: 397a14f391a37332e45ae9dd8a3e8f0d131d3b13
4
+ data.tar.gz: d1c7d0c7354eb14d946d79324fae80d627fe404b
5
5
  SHA512:
6
- metadata.gz: aa7369d1a69b1f4d70de7e9cded70bd04b7afc579c3dd41bb5422b266b1768ec2edaa7b3103f28c56af15024cd177566f655fb16a6a936cc0a471ba6414bca8e
7
- data.tar.gz: d22697d3f880bdecdcaff08aa5e1b7d6520dbbd9fa204a247703028d7022002d47c0ecb4244b956896d3cef2bacbf5a592601df318ec5a29cc1fa65c2ae48fef
6
+ metadata.gz: 3947a1c89e2a0ef6a2630c1da9ded0487f2b3af9e30ab02d253331ab4ee8c3f3ef2ae1ba8bc87887caad932c299b56654bb7c172f916c510f78fc618c2c2423d
7
+ data.tar.gz: 96409e51d49c3afc38f9cebd6c9afacedd7bfbcb4ee8cbef0ed78a620d6bc72adbb10114180ef6c139ed00cf658e015f0889e2eaaa7719f229ad3b3579e2b81c
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency "blade"
26
26
  spec.add_dependency "faraday"
27
+ spec.add_dependency "childprocess"
27
28
  end
@@ -39,28 +39,83 @@ module Blade::SauceLabsPlugin
39
39
  config.access_key || ENV["SAUCE_ACCESS_KEY"]
40
40
  end
41
41
 
42
+ def debug(message)
43
+ if debug?
44
+ STDERR.puts message
45
+ end
46
+ end
47
+
48
+ def debug?
49
+ config.debug == true
50
+ end
51
+
42
52
  private
43
53
  def test_params
44
- { url: Blade.url, platforms: Client.platforms, framework: Blade.config.framework, tunnelIdentifier: Tunnel.identifier }.merge(default_test_config).merge(test_config)
54
+ camelize_keys(combined_test_config)
55
+ end
56
+
57
+ def combined_test_config
58
+ default_test_config.merge(env_test_config).merge(test_config)
59
+ end
60
+
61
+ def test_config
62
+ config.test_config || {}
45
63
  end
46
64
 
47
65
  def default_test_config
48
- { build: rev, maxDuration: 300 }
66
+ {
67
+ url: Blade.url,
68
+ platforms: Client.platforms,
69
+ framework: Blade.config.framework,
70
+ tunnel_identifier: Tunnel.identifier,
71
+ max_duration: 300,
72
+ name: "Blade Runner CI",
73
+ build: default_build
74
+ }
75
+ end
76
+
77
+ def env_test_config
78
+ {}.tap do |config|
79
+ if build = get_env_value(:build_number)
80
+ config[:build] = build
81
+ end
82
+
83
+ tags = []
84
+
85
+ [:commit, :repo_slug, :pull_request].each do |key|
86
+ if tag = tag_from_env(key)
87
+ tags << tag
88
+ end
89
+ end
90
+
91
+ config[:tags] = tags if tags.any?
92
+ end
93
+ end
94
+
95
+ def tag_from_env(key)
96
+ if value = get_env_value(key)
97
+ [key, value].join(":")
98
+ end
99
+ end
100
+
101
+ def get_env_value(key)
102
+ key = key.to_s.upcase
103
+ ENV[key].presence || ENV["TRAVIS_#{key}"].presence
104
+ end
105
+
106
+ def default_build
107
+ [rev, Time.now.utc.to_i].select(&:present?).join("-")
49
108
  end
50
109
 
51
110
  def rev
52
- @rev ||= `git rev-parse HEAD`.chomp
111
+ @rev ||= `git rev-parse HEAD 2>/dev/null`.chomp
53
112
  end
54
113
 
55
- def test_config
56
- if config.test_config
57
- {}.tap do |result|
58
- config.test_config.each do |key, value|
59
- result[key.to_s.camelize(:lower)] = value
60
- end
114
+ def camelize_keys(hash)
115
+ {}.tap do |result|
116
+ hash.each do |key, value|
117
+ result[key.to_s.camelize(:lower)] = value
61
118
  end
62
- else
63
- {}
64
119
  end
65
120
  end
66
121
  end
@@ -10,7 +10,7 @@ module Blade::SauceLabsPlugin::Client
10
10
  }
11
11
 
12
12
  extend Forwardable
13
- def_delegators Blade::SauceLabsPlugin, :config, :username, :access_key
13
+ def_delegators Blade::SauceLabsPlugin, :config, :username, :access_key, :debug?
14
14
 
15
15
  def request(method, path, params = {})
16
16
  connection.send(method) do |req|
@@ -113,7 +113,11 @@ module Blade::SauceLabsPlugin::Client
113
113
 
114
114
  private
115
115
  def connection
116
- @connnection ||= Faraday.new("https://#{username}:#{access_key}@saucelabs.com/")
116
+ @connnection ||= Faraday.new("https://#{username}:#{access_key}@saucelabs.com/") do |faraday|
117
+ faraday.adapter Faraday.default_adapter
118
+ faraday.request :url_encoded
119
+ faraday.response :logger if debug?
120
+ end
117
121
  end
118
122
 
119
123
  def available_platforms
@@ -1,17 +1,17 @@
1
+ require "childprocess"
1
2
  require "securerandom"
2
- require "shellwords"
3
3
 
4
4
  module Blade::SauceLabsPlugin::Tunnel
5
5
  extend self
6
6
 
7
7
  extend Forwardable
8
- def_delegators Blade::SauceLabsPlugin, :username, :access_key
8
+ def_delegators Blade::SauceLabsPlugin, :username, :access_key, :config, :debug, :debug?
9
9
 
10
- attr_reader :identifier, :pid
10
+ attr_reader :identifier, :process
11
11
 
12
12
  def start
13
13
  @identifier = SecureRandom.hex(10)
14
- @pid = EM::DeferrableChildProcess.open(command).get_pid
14
+ @process = create_child_process
15
15
 
16
16
  timer = EM::PeriodicTimer.new(1) do
17
17
  if ready_file_exists?
@@ -22,14 +22,23 @@ module Blade::SauceLabsPlugin::Tunnel
22
22
  end
23
23
 
24
24
  def stop
25
- signal = ready_file_exists? ? "INT" : "KILL"
26
- remove_ready_file
27
- Process.kill(signal, pid) rescue nil
25
+ begin
26
+ process.poll_for_exit(10)
27
+ rescue ChildProcess::TimeoutError
28
+ process.stop
29
+ rescue
30
+ nil
31
+ end
28
32
  end
29
33
 
30
34
  private
31
- def command
32
- [tunnel_command, tunnel_args].join(" ")
35
+ def create_child_process
36
+ ChildProcess.build(tunnel_command, *tunnel_args).tap do |process|
37
+ process.leader = true
38
+ process.io.inherit! if debug?
39
+ process.start
40
+ debug process.inspect
41
+ end
33
42
  end
34
43
 
35
44
  def tunnel_command
@@ -37,7 +46,7 @@ module Blade::SauceLabsPlugin::Tunnel
37
46
  end
38
47
 
39
48
  def tunnel_args
40
- ["--user", username, "--api-key", access_key, "--tunnel-identifier", identifier, "--readyfile", ready_file_path].shelljoin
49
+ ["--user", username, "--api-key", access_key, "--tunnel-identifier", identifier, "--readyfile", ready_file_path]
41
50
  end
42
51
 
43
52
  def ready_file_path
@@ -1,5 +1,5 @@
1
1
  module Blade
2
2
  module SauceLabsPlugin
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blade-sauce_labs_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-11 00:00:00.000000000 Z
11
+ date: 2015-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: childprocess
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description:
84
98
  email:
85
99
  - javan@javan.us