Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
- run: vendor/bin/phpcs --warning-severity=0
e2e:
runs-on: ${{ matrix.os }}
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ For a full list of available commands, run `bdi list`.
* google-chrome
* chromium
* firefox

### Environment variables
* `GITHUB_TOKEN` - Geckodriver version resolver fetches the latest version from GitHub. You can set this environment variable to avoid rate limiting in CI environments.
20 changes: 18 additions & 2 deletions src/Driver/GeckoDriver/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use RuntimeException;
use Symfony\Contracts\HttpClient\HttpClientInterface;

use function getenv;
use function krsort;
use function Safe\json_decode;
use function sprintf;
Expand All @@ -19,9 +20,15 @@ final class VersionResolver implements VersionResolverInterface
{
private const LATEST_VERSION_ENDPOINT = 'https://api.github.com/repos/mozilla/geckodriver/releases/latest';

private const MIN_REQUIRED_BROWSER_VERSION_FOR_LATEST = 60;
private const MIN_REQUIRED_BROWSER_VERSION_FOR_LATEST = 128;

private const MIN_REQUIRED_BROWSER_VERSIONS = [
128 => '0.36.0',
115 => '0.35.0',
102 => '0.33.0',
91 => '0.31.0',
78 => '0.30.0',
60 => '0.26.0',
57 => '0.25.0',
55 => '0.20.1',
53 => '0.18.0',
Expand Down Expand Up @@ -57,7 +64,16 @@ public function fromBrowser(Browser $browser): Version

public function latest(): Version
{
$response = $this->httpClient->request('GET', self::LATEST_VERSION_ENDPOINT);
$options = [];

$token = getenv('GITHUB_TOKEN');
if ($token !== false && $token !== '') {
$options['headers'] = [
'Authorization' => sprintf('Bearer %s', $token),
];
}

$response = $this->httpClient->request('GET', self::LATEST_VERSION_ENDPOINT, $options);

/** @var array<scalar> $data */
$data = json_decode($response->getContent(), true);
Expand Down
6 changes: 3 additions & 3 deletions tests/Driver/GeckoDriver/VersionResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ static function (string $method, string $url): MockResponse {
},
);
$this->versionResolver = new VersionResolver($this->httpClient);
$this->chrome = new Browser(BrowserName::GOOGLE_CHROME, Version::fromString('86.0.4240.80'), OperatingSystem::MACOS);
$this->firefox = new Browser(BrowserName::FIREFOX, Version::fromString('81.0.2'), OperatingSystem::MACOS);
$this->chrome = new Browser(BrowserName::GOOGLE_CHROME, Version::fromString('142.0.7444.60'), OperatingSystem::MACOS);
$this->firefox = new Browser(BrowserName::FIREFOX, Version::fromString('144.0.2'), OperatingSystem::MACOS);
}

public function testDoesNotSupportChrome(): void
Expand All @@ -53,7 +53,7 @@ public function testLatestVersionForRecentBrowser(): void
{
$geckoVersion = $this->versionResolver->fromBrowser($this->firefox);

self::assertEquals(Version::fromString('0.28.0'), $geckoVersion);
self::assertEquals(Version::fromString('0.36.0'), $geckoVersion);
}

public function testVersionForOldBrowser(): void
Expand Down
Loading