forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci.rb
48 lines (43 loc) · 1.36 KB
/
ci.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'uri'
require 'net/http'
require 'digest/md5'
require 'json'
require 'pathname'
def net_http
http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
if http_proxy
http_proxy = "http://#{http_proxy}" unless http_proxy.start_with?("http://")
proxy_uri = URI.parse(http_proxy)
Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port)
else
Net::HTTP
end
end
namespace :ci do
task :upload_to_sauce do
upload_path = ENV["UPLOAD_PATH"]
username = ENV["SAUCE_USERNAME"]
apikey = ENV["SAUCE_APIKEY"]
upload_filename = Pathname.new(upload_path).basename
upload_url = "http://saucelabs.com/rest/v1/storage/#{username}/#{upload_filename}"
body = nil
File.open(find_file(upload_path), "r") do |infile|
body = infile.read
end
uri = URI.parse(upload_url)
request = Net::HTTP::Post.new(uri.request_uri)
request.basic_auth(username, apikey)
request["Content-Type"] = "application/octet-stream"
request.body = body
http = net_http.new(uri.host, uri.port)
http.read_timeout = 60 * 5 # 5 min
response = http.request(request)
metadata = JSON.parse(response.body)
local_digest = Digest::MD5.hexdigest(body)
if metadata['md5'] == local_digest
puts "file successfully uploaded: #{metadata['filename']}"
else
puts "issues uploading file: #{response.code} - #{response.body}"
end
end
end