From 8f33b876df22503e5890c52c7345ba428a827294 Mon Sep 17 00:00:00 2001 From: Alex Leahy Date: Tue, 13 Aug 2024 10:18:02 +0800 Subject: [PATCH] Extract chromedriver regardless of position in archive Signed-off-by: Mior Muhammad Zaki --- .github/workflows/tests.yaml | 1 + composer.json | 1 + src/UpdateCommand.php | 22 ++++++++++++---------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 8e9303d..8c7fa79 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -105,6 +105,7 @@ jobs: - '8.0' - 8.1 - 8.2 + - 8.3 dependencies: - "highest" - "lowest" diff --git a/composer.json b/composer.json index eafd911..13a2386 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "composer-runtime-api": "^2.2", "composer/semver": "^1.5 || ^3.0", "guzzlehttp/guzzle": "^7.2", + "illuminate/support": ">=5.7.0", "symfony/console": "^4.3.4 || ^5.0 || ^6.0", "symfony/polyfill-ctype": "^1.9", "symfony/process": "^4.3.4 || ^5.0 || ^6.0" diff --git a/src/UpdateCommand.php b/src/UpdateCommand.php index 92ecb35..14092f2 100644 --- a/src/UpdateCommand.php +++ b/src/UpdateCommand.php @@ -3,6 +3,7 @@ namespace Orchestra\DuskUpdater; use Exception; +use Illuminate\Support\Str; use RuntimeException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -91,25 +92,26 @@ protected function extract(string $version, string $archive): string throw new RuntimeException("Unable to extract {$archive} without --install-dir"); } + $binary = null; + $zip = new ZipArchive(); $zip->open($archive); $zip->extractTo($this->directory); - switch (true) { - case version_compare($version, '115.0', '<'): - $index = 0; - break; - case version_compare($version, '127.0', '<'): - $index = 1; + for ($fileIndex = 0; $fileIndex < $zip->numFiles; $fileIndex++) { + $filename = $zip->getNameIndex($fileIndex); + + if (Str::startsWith(basename($filename), 'chromedriver')) { + $binary = $filename; + + $zip->extractTo($this->directory, $binary); + break; - default: - $index = 2; + } } - $binary = $zip->getNameIndex($index); - $zip->close(); unlink($archive);