Skip to content

Commit b0efa19

Browse files
authored
Add Playwright (#3)
1 parent 088be46 commit b0efa19

File tree

9 files changed

+1245
-1
lines changed

9 files changed

+1245
-1
lines changed

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"CoenraadS.bracket-pair-colorizer"
2020
],
2121
"remoteUser": "sail",
22-
"postCreateCommand": "chown -R 1000:1000 /var/www/html && composer install && php artisan key:generate && echo \"ASSET_URL=https://${CODESPACE_NAME}-80.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}\" >> .env",
22+
"postCreateCommand": "chown -R 1000:1000 /var/www/html && npm install && npx playwright install && composer install && php artisan key:generate && echo \"ASSET_URL=https://${CODESPACE_NAME}-80.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}\" >> .env",
2323
"forwardPorts": [80]
2424
// "runServices": [],
2525
// "shutdownAction": "none",

app/Console/Commands/Playwright.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Workflows\Playwright\CheckConsoleErrorsWorkflow;
6+
use Illuminate\Console\Command;
7+
use Workflow\WorkflowStub;
8+
9+
class Playwright extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'app:playwright';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Runs a workflow';
24+
25+
/**
26+
* Execute the console command.
27+
*/
28+
public function handle()
29+
{
30+
$workflow = WorkflowStub::make(CheckConsoleErrorsWorkflow::class);
31+
$workflow->start('https://example.com');
32+
while ($workflow->running());
33+
$this->info($workflow->output()['mp4']);
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Workflows\Playwright;
4+
5+
use Workflow\Activity;
6+
use Illuminate\Support\Facades\Log;
7+
use Symfony\Component\Process\Process;
8+
use Symfony\Component\Process\Exception\ProcessFailedException;
9+
10+
class CheckConsoleErrorsActivity extends Activity
11+
{
12+
public function execute(string $url)
13+
{
14+
$process = new Process(['node', base_path('playwright-script.js'), $url]);
15+
$process->run();
16+
17+
if (! $process->isSuccessful()) {
18+
throw new ProcessFailedException($process);
19+
}
20+
21+
return json_decode($process->getOutput(), true);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Workflows\Playwright;
4+
5+
use Exceoption;
6+
use Workflow\ActivityStub;
7+
use Workflow\Workflow;
8+
9+
class CheckConsoleErrorsWorkflow extends Workflow
10+
{
11+
public function execute(string $url)
12+
{
13+
$result = yield ActivityStub::make(CheckConsoleErrorsActivity::class, $url);
14+
15+
$mp4 = yield ActivityStub::make(ConvertVideoActivity::class, $result['video']);
16+
17+
return [
18+
'errors' => $result['errors'],
19+
'mp4' => $mp4,
20+
];
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Workflows\Playwright;
4+
5+
use Workflow\Activity;
6+
use Illuminate\Support\Facades\Log;
7+
use Symfony\Component\Process\Process;
8+
use Symfony\Component\Process\Exception\ProcessFailedException;
9+
10+
class ConvertVideoActivity extends Activity
11+
{
12+
public function execute(string $webm)
13+
{
14+
$mp4 = str_replace('.webm', '.mp4', $webm);
15+
16+
$process = new Process(['ffmpeg', '-i', $webm, '-c:v', 'libx264', '-preset', 'fast', '-crf', '23', '-c:a', 'aac', '-b:a', '128k', $mp4]);
17+
$process->run();
18+
19+
if (! $process->isSuccessful()) {
20+
throw new ProcessFailedException($process);
21+
}
22+
23+
unlink($webm);
24+
25+
return $mp4;
26+
}
27+
}

docker/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ RUN apt-get update \
3939
&& apt-get install -y yarn \
4040
&& apt-get install -y mysql-client \
4141
&& apt-get install -y postgresql-client-$POSTGRES_VERSION \
42+
&& npx playwright install --with-deps \
4243
&& apt-get -y autoremove \
4344
&& apt-get clean \
4445
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

0 commit comments

Comments
 (0)