Skip to content

Commit

Permalink
code style fix
Browse files Browse the repository at this point in the history
add command tests
  • Loading branch information
saeedvaziry committed Sep 2, 2023
1 parent 71f9dab commit e1eb420
Show file tree
Hide file tree
Showing 135 changed files with 1,859 additions and 135 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/style-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: style-check

on:
push:
pull_request:

jobs:
tests:
runs-on: ubuntu-20.04

services:
mysql:
image: mysql
env:
MYSQL_DATABASE: test_db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: true
matrix:
php: [ 8.1 ]

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: php artisan test
env:
DB_HOST: 127.0.0.1
DB_DATABASE: test_db
DB_USERNAME: user
DB_PASSWORD: password
23 changes: 2 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,11 @@ name: tests
on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
tests:
runs-on: ubuntu-20.04

services:
mysql:
image: mysql
env:
MYSQL_DATABASE: test_db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: true
matrix:
Expand All @@ -47,10 +33,5 @@ jobs:
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: php artisan test
env:
DB_HOST: 127.0.0.1
DB_DATABASE: test_db
DB_USERNAME: user
DB_PASSWORD: password
- name: Run pint
run: ./vendor/bin/pint --test
2 changes: 1 addition & 1 deletion app/Actions/Database/CreateBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function validate($type, Server $server, array $input): void
'0 0 * * *',
'0 0 * * 0',
'0 0 1 * *',
'custom'
'custom',
]),
],
];
Expand Down
1 change: 0 additions & 1 deletion app/Actions/FirewallRule/CreateRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Models\FirewallRule;
use App\Models\Server;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;

class CreateRule
Expand Down
10 changes: 5 additions & 5 deletions app/Actions/SourceControl/ConnectSourceControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function connect(array $input): void
$sourceControl = new SourceControl([
'provider' => $input['provider'],
'profile' => $input['name'],
'access_token' => $input['token']
'access_token' => $input['token'],
]);

if (! $sourceControl->provider()->connect()) {
Expand All @@ -24,7 +24,7 @@ public function connect(array $input): void
),
]);
}

$sourceControl->save();
}

Expand All @@ -36,14 +36,14 @@ private function validate(array $input): void
$rules = [
'provider' => [
'required',
Rule::in(\App\Enums\SourceControl::getValues())
Rule::in(\App\Enums\SourceControl::getValues()),
],
'name' => [
'required',
],
'token' => [
'required'
]
'required',
],
];
Validator::make($input, $rules)->validate();
}
Expand Down
12 changes: 6 additions & 6 deletions app/Actions/StorageProvider/CreateStorageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public function create(User $user, array $input): void
'provider' => $input['provider'],
'profile' => $input['name'],
'credentials' => [
'token' => $input['token']
]
'token' => $input['token'],
],
]);
if (! $storageProvider->provider()->connect()) {
throw ValidationException::withMessages([
'token' => __("Couldn't connect to the provider")
'token' => __("Couldn't connect to the provider"),
]);
}
$storageProvider->save();;
$storageProvider->save();
}

private function validate(User $user, array $input): void
Expand All @@ -45,8 +45,8 @@ private function validate(User $user, array $input): void
Rule::unique('storage_providers', 'profile')->where('user_id', $user->id),
],
'token' => [
'required'
]
'required',
],
])->validate();
}
}
3 changes: 1 addition & 2 deletions app/Console/Commands/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class CreateUserCommand extends Command
{
Expand All @@ -20,6 +19,6 @@ public function handle(): void
'password' => bcrypt($this->argument('password')),
]);

$this->info("User created with password");
$this->info('User created with password');
}
}
1 change: 0 additions & 1 deletion app/Contracts/StorageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Contracts;

use App\Models\Server;
use Symfony\Component\HttpFoundation\RedirectResponse;

interface StorageProvider
{
Expand Down
1 change: 1 addition & 0 deletions app/Enums/ServerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
final class ServerType extends Enum
{
const REGULAR = 'regular';

const DATABASE = 'database';
}
6 changes: 3 additions & 3 deletions app/Helpers/SSH.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public function connect(bool $sftp = false): void
$login = $this->connection->login($this->user, $this->privateKey);

if (! $login) {
throw new SSHAuthenticationError("Error authenticating");
throw new SSHAuthenticationError('Error authenticating');
}
} catch (Throwable $e) {
Log::error("Error connecting", [
"msg" => $e->getMessage()
Log::error('Error connecting', [
'msg' => $e->getMessage(),
]);
throw $e;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ class Kernel extends HttpKernel
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'server-is-ready' => ServerIsReadyMiddleware::class
'server-is-ready' => ServerIsReadyMiddleware::class,
];
}
6 changes: 3 additions & 3 deletions app/Http/Livewire/Databases/DatabaseBackupFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class DatabaseBackupFiles extends Component

public Backup $backup;

public string $restoreId = "";
public string $restoreId = '';

public string $restoreDatabaseId = "";
public string $restoreDatabaseId = '';

public int $deleteId;

Expand Down Expand Up @@ -61,7 +61,7 @@ public function delete(): void
public function render(): View
{
return view('livewire.databases.database-backup-files', [
'files' => $this->backup->files()->orderByDesc('id')->simplePaginate(10)
'files' => $this->backup->files()->orderByDesc('id')->simplePaginate(10),
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Livewire/Databases/DatabaseBackups.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function render(): View
return view('livewire.databases.database-backups', [
'backups' => $this->server->backups,
'databases' => $this->server->databases,
'files' => $this->files
'files' => $this->files,
]);
}
}
2 changes: 2 additions & 0 deletions app/Jobs/Installation/ContinueInstallation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function handle(): void
{
if ($this->server->provider()->isRunning()) {
$this->server->install();

return;
}

Expand All @@ -33,6 +34,7 @@ public function handle(): void
'server' => $this->server,
])
);

return;
}

Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/Installation/UninstallPHPMyAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Jobs\Job;
use App\Models\FirewallRule;
use App\Models\Service;
use App\SSHCommands\PHPMyAdmin\DeleteNginxPHPMyAdminVHost;
use App\SSHCommands\PHPMyAdmin\DeleteNginxPHPMyAdminVHostCommand;
use Exception;
use Throwable;

Expand Down Expand Up @@ -48,7 +48,7 @@ private function removeFirewallRule(): void
private function deleteVHost(): void
{
$this->service->server->ssh()->exec(
new DeleteNginxPHPMyAdminVHost('/home/vito/phpmyadmin'),
new DeleteNginxPHPMyAdminVHostCommand('/home/vito/phpmyadmin'),
'delete-phpmyadmin-vhost'
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/Site/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Helpers\SSH;
use App\Jobs\Job;
use App\Models\Deployment;
use App\SSHCommands\System\RunScript;
use App\SSHCommands\System\RunScriptCommand;
use Throwable;

class Deploy extends Job
Expand All @@ -34,7 +34,7 @@ public function handle(): void
{
$this->ssh = $this->deployment->site->server->ssh();
$this->ssh->exec(
new RunScript($this->path, $this->script),
new RunScriptCommand($this->path, $this->script),
'deploy',
$this->deployment->site_id
);
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Site/DeployKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function handle(): void
);
$this->site->save();
$this->site->sourceControl()->provider()->deployKey(
$this->site->domain.'-key-' . $this->site->id,
$this->site->domain.'-key-'.$this->site->id,
$this->site->repository,
$this->site->ssh_key
);
Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/BroadcastListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function handle(Broadcast $event): void
{
Cache::set('broadcast', [
'type' => $event->type,
'data' => $event->data
'data' => $event->data,
], now()->addMinutes(5));
}
}
2 changes: 1 addition & 1 deletion app/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function boot(): void
static::created(function (Site $site) {
$site->deploymentScript()->create([
'name' => 'default',
'content' => ''
'content' => '',
]);
});
}
Expand Down
1 change: 0 additions & 1 deletion app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;

class EventServiceProvider extends ServiceProvider
{
Expand Down
2 changes: 1 addition & 1 deletion app/SSHCommands/Database/BackupDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $databa

public function file(): string
{
return File::get(resource_path(sprintf("commands/database/%s/backup.sh", $this->provider)));
return File::get(resource_path(sprintf('commands/database/%s/backup.sh', $this->provider)));
}

public function content(): string
Expand Down
2 changes: 1 addition & 1 deletion app/SSHCommands/Database/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $name)

public function file(): string
{
return File::get(resource_path(sprintf("commands/database/%s/create.sh", $this->provider)));
return File::get(resource_path(sprintf('commands/database/%s/create.sh', $this->provider)));
}

public function content(): string
Expand Down
2 changes: 1 addition & 1 deletion app/SSHCommands/Database/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(

public function file(): string
{
return File::get(resource_path(sprintf("commands/database/%s/create-user.sh", $this->provider)));
return File::get(resource_path(sprintf('commands/database/%s/create-user.sh', $this->provider)));
}

public function content(): string
Expand Down
2 changes: 1 addition & 1 deletion app/SSHCommands/Database/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $name)

public function file(): string
{
return File::get(resource_path(sprintf("commands/database/%s/delete.sh", $this->provider)));
return File::get(resource_path(sprintf('commands/database/%s/delete.sh', $this->provider)));
}

public function content(): string
Expand Down
2 changes: 1 addition & 1 deletion app/SSHCommands/Database/DeleteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $userna

public function file(): string
{
return File::get(resource_path(sprintf("commands/database/%s/delete-user.sh", $this->provider)));
return File::get(resource_path(sprintf('commands/database/%s/delete-user.sh', $this->provider)));
}

public function content(): string
Expand Down
Loading

0 comments on commit e1eb420

Please sign in to comment.