Skip to content

Commit

Permalink
[2.x] Improves version fetching (#779)
Browse files Browse the repository at this point in the history
* Uses `build-info` instead

* Fix code styling

* Dont uses const on traits

---------

Co-authored-by: nunomaduro <[email protected]>
  • Loading branch information
nunomaduro and nunomaduro authored Dec 20, 2023
1 parent 42ce8da commit 85f40cd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Commands/Concerns/InstallsFrankenPhpDependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use Laravel\Octane\FrankenPhp\Concerns\FindsFrankenPhpBinary;
use Symfony\Component\Process\Process;
use Throwable;
Expand Down Expand Up @@ -126,13 +127,24 @@ protected function downloadFrankenPhpBinary()
*/
protected function ensureFrankenPhpBinaryMeetsRequirements($frakenPhpBinary)
{
$version = tap(new Process([$frakenPhpBinary, '--version'], base_path()))
$buildInfo = tap(new Process([$frakenPhpBinary, 'build-info'], base_path()))
->run()
->getOutput();

$version = explode(' ', $version)[1] ?? null;
$lineWithVersion = collect(explode("\n", $buildInfo))
->first(function ($line) {
return str_starts_with($line, 'dep') && str_contains($line, 'github.com/dunglas/frankenphp');
});

if ($version === null || preg_match('/\d+\.\d+\.\d+/', $version) !== 1) {
if ($lineWithVersion === null) {
return $this->warn(
'Unable to determine the current FrankenPHP binary version. Please report this issue: https://github.com/laravel/octane/issues/new.',
);
}

$version = Str::of($lineWithVersion)->trim()->afterLast('v')->value();

if (preg_match('/\d+\.\d+\.\d+/', $version) !== 1) {
return $this->warn(
'Unable to determine the current FrankenPHP binary version. Please report this issue: https://github.com/laravel/octane/issues/new.',
);
Expand Down

0 comments on commit 85f40cd

Please sign in to comment.