Skip to content

Commit

Permalink
Hardcode download URLs
Browse files Browse the repository at this point in the history
When working on cucumber/cucumber-rails#378, we would sometimes see that the builds would be unable to connect to the Geckodriver. On further investigation, this seems to be caused by the Geckodriver not being downloaded in the first place. I think that this is due to GitHub's API rate limiting certain build machines from accessing their API.

A better approach would be to hardcode the URLs for the assets -- since they're easily predicatable -- and then to bump this gem whenever a new release comes out.
  • Loading branch information
Ryan Bigg committed Apr 21, 2018
1 parent 1419283 commit 940b353
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 82 deletions.
1 change: 1 addition & 0 deletions geckodriver-helper.gemspec
Expand Up @@ -20,6 +20,7 @@ described by the WebDriver protocol to communicate with Gecko browsers, such as

s.add_development_dependency "rspec", "~> 3.0"
s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "http", "~> 3.0"

s.add_runtime_dependency "archive-zip", "~> 0.7"
end
38 changes: 23 additions & 15 deletions lib/geckodriver/helper.rb
@@ -1,5 +1,4 @@
require 'geckodriver/helper/version'
require 'geckodriver/helper/gecko_release_page_parser'
require 'fileutils'
require 'rbconfig'
require 'open-uri'
Expand All @@ -9,6 +8,7 @@

module Geckodriver
class Helper
DRIVER_VERSION = "v0.20.1".freeze

def run *args
download
Expand Down Expand Up @@ -48,15 +48,18 @@ def update
end

def download_url
GeckoReleasePageParser.new(platform).latest_release
extension = platform.include?('win') ? 'zip' : 'tar.gz'
"https://github.com/mozilla/geckodriver/releases/download/#{DRIVER_VERSION}/geckodriver-#{DRIVER_VERSION}-#{platform}.#{extension}"
end

def binary_path
if platform == 'win'
File.join platform_install_dir, 'geckodriver.exe'
else
File.join platform_install_dir, 'geckodriver'
end
exe = if platform.include?('win')
'geckodriver.exe'
else
'geckodriver'
end

File.join platform_install_dir, exe
end

def platform_install_dir
Expand All @@ -72,19 +75,25 @@ def install_dir
end

def platform
cfg = RbConfig::CONFIG
case cfg['host_os']
when /linux/ then
cfg['host_cpu'] =~ /x86_64|amd64/ ? 'linux64' : 'linux32'
when /darwin/ then
'mac'
@platform ||= begin
cfg = RbConfig::CONFIG
case cfg['host_os']
when /linux/
append_64_or_32('linux', cfg)
when /darwin/
'macos'
else
'win'
append_64_or_32('win', cfg)
end
end
end

private

def append_64_or_32(platform)
cfg['host_cpu'] =~ /x86_64|amd64/ ? "#{platform}64" : "#{platform}32"
end

def unzip(zipfile)
Archive::Zip.extract(zipfile, '.', :overwrite => :all)
end
Expand All @@ -106,6 +115,5 @@ def untar(io)
end
end
end

end
end
35 changes: 0 additions & 35 deletions lib/geckodriver/helper/gecko_release_page_parser.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/geckodriver/helper/version.rb
@@ -1,5 +1,5 @@
module Geckodriver
class Helper
VERSION = '0.0.5'
VERSION = '0.20.1'
end
end
1 change: 0 additions & 1 deletion spec/assets/gecko-releases.json

This file was deleted.

26 changes: 0 additions & 26 deletions spec/gecko_release_page_parser_spec.rb

This file was deleted.

33 changes: 29 additions & 4 deletions spec/helper_spec.rb
@@ -1,21 +1,46 @@
require 'spec_helper'
require 'http'

describe Geckodriver::Helper do
let(:helper) { Geckodriver::Helper.new }

RSpec::Matchers.define :be_reachable do
match do |download_url|
response = HTTP.head download_url
location = response["Location"]
expect(response["Location"]).to include("github-production-release-asset")
expect(response["Location"]).to include("s3.amazonaws.com")
end
end

describe '#binary_path' do
context 'on a linux platform' do
context 'on a linux32 platform' do
before { allow(helper).to receive(:platform) { 'linux32' } }
it { expect(helper.download_url).to be_reachable }
it { expect(helper.binary_path).to match(/geckodriver$/) }
end

context 'on a linux64 platform' do
before { allow(helper).to receive(:platform) { 'linux64' } }
it { expect(helper.download_url).to be_reachable }
it { expect(helper.binary_path).to match(/geckodriver$/) }
end

context 'on a mac platform' do
before { allow(helper).to receive(:platform) { 'mac' } }
before { allow(helper).to receive(:platform) { 'macos' } }
it { expect(helper.download_url).to be_reachable }
it { expect(helper.binary_path).to match(/geckodriver$/) }
end

context 'on a windows platform' do
before { allow(helper).to receive(:platform) { 'win' } }
context 'on a windows32 platform' do
before { allow(helper).to receive(:platform) { 'win32' } }
it { expect(helper.download_url).to be_reachable }
it { expect(helper.binary_path).to match(/geckodriver\.exe$/) }
end

context 'on a windows64 platform' do
before { allow(helper).to receive(:platform) { 'win64' } }
it { expect(helper.download_url).to be_reachable }
it { expect(helper.binary_path).to match(/geckodriver\.exe$/) }
end
end
Expand Down

0 comments on commit 940b353

Please sign in to comment.