Skip to content

Commit

Permalink
Merge pull request #67 from spatie/chore/update-github-actions
Browse files Browse the repository at this point in the history
Update github actions + run Pint
  • Loading branch information
Nielsvanpach authored Jun 12, 2024
2 parents 826e7aa + 2de24b4 commit 7909241
Show file tree
Hide file tree
Showing 61 changed files with 164 additions and 130 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Fix PHP code style issues

on:
push:
paths:
- '**.php'
- '.github/workflows/fix-php-code-style-issues.yml'

permissions:
contents: write

jobs:
php-code-styling:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/[email protected]

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
23 changes: 0 additions & 23 deletions .github/workflows/php-cs-fixer.yml

This file was deleted.

28 changes: 21 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
name: run-tests

on: [push]
on:
push:
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'

jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.2]
laravel: [10.*, 11.*]
dependency-version: [prefer-lowest, prefer-stable]
laravel: [11.*, 10.*]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install sed
run: sudo apt-get install sed
Expand All @@ -36,10 +45,15 @@ jobs:
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
8 changes: 6 additions & 2 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ on:
release:
types: [released]

permissions:
contents: write

jobs:
update:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: main

Expand All @@ -21,7 +25,7 @@ jobs:
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: Update CHANGELOG
Expand Down
1 change: 0 additions & 1 deletion config/backup-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
],
],


/*
* Here you can specify on which connection the backup server jobs will be dispatched.
* Leave empty to use the app default's env('QUEUE_CONNECTION')
Expand Down
8 changes: 4 additions & 4 deletions src/BackupServerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function boot()

public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../config/backup-server.php', 'backup-server');
$this->mergeConfigFrom(__DIR__.'/../config/backup-server.php', 'backup-server');

$this->app['events']->subscribe(EventHandler::class);

Expand Down Expand Up @@ -87,16 +87,16 @@ protected function bootGate(): self
protected function bootPublishables(): self
{
$this->publishes([
__DIR__ . '/../config/backup-server.php' => config_path('backup-server.php'),
__DIR__.'/../config/backup-server.php' => config_path('backup-server.php'),
], 'backup-server-config');

$this->publishes([
__DIR__ . '/../resources/views' => resource_path('views/vendor/backup-server'),
__DIR__.'/../resources/views' => resource_path('views/vendor/backup-server'),
], 'backup-server-views');

if (! class_exists('CreateBackupServerTables')) {
$this->publishes([
__DIR__ . '/../database/migrations/create_backup_server_tables.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_backup_server_tables.php'),
__DIR__.'/../database/migrations/create_backup_server_tables.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_backup_server_tables.php'),
], 'backup-server-migrations');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/CreateBackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function handle()
$this->info("Creating new backup for {$sourceName}...");

$writeLogItemsToConsole = function (Backup $backup) {
Event::listen('eloquent.saving: ' . BackupLogItem::class, function (BackupLogItem $backupLogItem) use ($backup) {
Event::listen('eloquent.saving: '.BackupLogItem::class, function (BackupLogItem $backupLogItem) use ($backup) {
if ($backupLogItem->backup_id !== $backup->id) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/FindContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public function handle()
});

$this->comment('');
$this->comment($this->resultCounter. ' ' . Str::plural('search result', $this->resultCounter) . ' found.');
$this->comment($this->resultCounter.' '.Str::plural('search result', $this->resultCounter).' found.');
}

protected function handleFoundContent(Collection $contentSearchResults)
{
$contentSearchResults->each(function (ContentSearchResult $contentSearchResult) {
$this->resultCounter++;

$this->info($contentSearchResult->getAbsolutePath() . ':' . $contentSearchResult->lineNumber());
$this->info($contentSearchResult->getAbsolutePath().':'.$contentSearchResult->lineNumber());
});
}
}
2 changes: 1 addition & 1 deletion src/Commands/FindFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function handle()

$this->info('');

$this->info($this->resultCounter. ' ' . Str::plural('search result', $this->resultCounter) . ' found.');
$this->info($this->resultCounter.' '.Str::plural('search result', $this->resultCounter).' found.');

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/ListDestinationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function handle()

$columnStyles = collect($headers)
->map(function (string $header) {
if (in_array($header, ['Total Backup Size', 'Used Storage', 'Free Space', 'Capacity Used', 'Inode Usage',])) {
if (in_array($header, ['Total Backup Size', 'Used Storage', 'Free Space', 'Capacity Used', 'Inode Usage'])) {
return new AlignRightTableStyle();
}

Expand Down Expand Up @@ -61,8 +61,8 @@ protected function convertToRow(Destination $destination)
if ($destination->reachable()) {
return array_merge($rowValues, [
'free_space' => Format::KbToHumanReadableSize($destination->getFreeSpaceInKb()),
'capacity_used' => $destination->getUsedSpaceInPercentage() . '%',
'inode_usage' => $destination->getInodeUsagePercentage() . '%',
'capacity_used' => $destination->getUsedSpaceInPercentage().'%',
'inode_usage' => $destination->getInodeUsagePercentage().'%',
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ListSourcesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function convertToRow(Source $source): Collection
]);
}

protected function getFormattedBackupDate(Backup $backup = null)
protected function getFormattedBackupDate(?Backup $backup = null)
{
return is_null($backup)
? 'No backups present'
Expand Down
14 changes: 9 additions & 5 deletions src/Models/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@

class Backup extends Model
{
use LogsActivity;
use HasAsyncDelete;
use HasFactory;
use LogsActivity;

public $table = 'backup_server_backups';

public $guarded = [];

public const STATUS_PENDING = 'pending';

public const STATUS_IN_PROGRESS = 'in_progress';

public const STATUS_COMPLETED = 'completed';

public const STATUS_FAILED = 'failed';

public const STATUS_DELETING = 'deleting';

protected $casts = [
Expand Down Expand Up @@ -182,7 +186,7 @@ protected function addMessageToLog(string $task, string $level, string $message)
public function recalculateBackupSize(): Backup
{
$process = Process::fromShellCommandline(
"du -kd 0",
'du -kd 0',
$this->destinationLocation()->getFullPath(),
null,
null,
Expand All @@ -195,7 +199,7 @@ public function recalculateBackupSize(): Backup

$sizeInKb = Str::before($output, ' ');

$this->update(['size_in_kb' => (int)trim($sizeInKb)]);
$this->update(['size_in_kb' => (int) trim($sizeInKb)]);

return $this;
}
Expand Down Expand Up @@ -227,7 +231,7 @@ public function recalculateRealBackupSize(): Backup

$sizeInKb = Str::before($directoryLine, "\t");

$this->update(['real_size_in_kb' => (int)trim($sizeInKb)]);
$this->update(['real_size_in_kb' => (int) trim($sizeInKb)]);

return $this;
}
Expand Down Expand Up @@ -314,6 +318,6 @@ public function fileList(string $relativeDirectory = '/'): FileList

public function name(): string
{
return $this->source->name . '-' . optional($this->completed_at)->format('Y-m-d-His');
return $this->source->name.'-'.optional($this->completed_at)->format('Y-m-d-His');
}
}
17 changes: 9 additions & 8 deletions src/Models/Destination.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

class Destination extends Model
{
use LogsActivity;
use HasBackupRelation;
use HasAsyncDelete;
use HasBackupRelation;
use HasFactory;
use LogsActivity;

public $table = 'backup_server_destinations';

public const STATUS_ACTIVE = 'active';

public const STATUS_DELETING = 'deleting';

public $guarded = [];
Expand Down Expand Up @@ -88,36 +89,36 @@ public function getInodeUsagePercentage(): int
{
$rawOutput = $this->getDfOutput(8, 'ipcent');

return (int)Str::before($rawOutput, '%');
return (int) Str::before($rawOutput, '%');
}

public function getFreeSpaceInKb(): int
{
$rawOutput = $this->getDfOutput(4, 'avail');

return (int)$rawOutput;
return (int) $rawOutput;
}

public function getUsedSpaceInPercentage(): int
{
$rawOutput = $this->getDfOutput(5, 'pcent');

return (int)Str::before($rawOutput, '%');
return (int) Str::before($rawOutput, '%');
}

protected function getDfOutput(int $macOsColumnNumber, $linuxOutputFormat)
{
$command = PHP_OS === 'Darwin'
? 'df -k "$PWD" | awk \'{print $' . $macOsColumnNumber . '}\''
: 'df -k --output=' . $linuxOutputFormat . ' "$PWD"';
? 'df -k "$PWD" | awk \'{print $'.$macOsColumnNumber.'}\''
: 'df -k --output='.$linuxOutputFormat.' "$PWD"';

$diskRootPath = $this->disk()->path('');

$process = Process::fromShellCommandline("cd {$diskRootPath}; {$command}");
$process->run();

if (! $process->isSuccessful()) {
throw new Exception("Could not determine inode count");
throw new Exception('Could not determine inode count');
}

$lines = explode(PHP_EOL, $process->getOutput());
Expand Down
5 changes: 3 additions & 2 deletions src/Models/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@

class Source extends Model
{
use LogsActivity;
use HasBackupRelation;
use HasAsyncDelete;
use HasBackupRelation;
use HasFactory;
use LogsActivity;

public $table = 'backup_server_sources';

public $guarded = [];

public const STATUS_ACTIVE = 'active';

public const STATUS_DELETING = 'deleting';

public $casts = [
Expand Down
2 changes: 1 addition & 1 deletion src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

class User extends Authenticatable
{
use Notifiable;
use HasFactory;
use Notifiable;

public $table = 'backup_server_users';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function toSlack(): SlackMessage
->fields([
'Source' => $this->event->backup->source->name,
'Destination' => $this->event->backup->destination->name,
'Duration' => $this->event->backup->rsync_time_in_seconds . ' seconds',
'Duration' => $this->event->backup->rsync_time_in_seconds.' seconds',
'Average speed' => $this->event->backup->rsync_average_transfer_speed_in_MB_per_second,
'Size' => Format::KbToHumanReadableSize($this->event->backup->size_in_kb),
])
Expand Down
Loading

0 comments on commit 7909241

Please sign in to comment.