Skip to content

Commit 5c07cd8

Browse files
authored
Update Dependencies and Cleanup (#5)
Update Dependencies and Cleanup - minimum PHP version now 8.2 - minimum Laravel version now 11 - cleaned up formatting throughout
1 parent e67f0ae commit 5c07cd8

34 files changed

+596
-644
lines changed

.github/workflows/lint.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Fix Code Style
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
php: [8.4]
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php }}
21+
extensions: json, dom, curl, libxml, mbstring
22+
coverage: none
23+
24+
- name: Install Pint
25+
run: composer global require laravel/pint
26+
27+
- name: Run Pint
28+
run: pint
29+
30+
- name: Commit linted files
31+
uses: stefanzweifel/git-auto-commit-action@v5

.github/workflows/phpstan.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: PHPStan
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
phpstan:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Setup PHP
15+
uses: shivammathur/setup-php@v2
16+
with:
17+
php-version: '8.4'
18+
coverage: none
19+
tools: composer
20+
21+
- name: Get Composer cache directory
22+
id: composer-cache
23+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
24+
25+
- name: Setup cache
26+
uses: actions/cache@v4
27+
with:
28+
path: ${{ steps.composer-cache.outputs.dir }}
29+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
30+
restore-keys: ${{ runner.os }}-composer-
31+
32+
- name: Install dependencies
33+
run:
34+
composer install --prefer-dist --no-suggest --no-progress
35+
36+
- name: Run PHPStan
37+
run: ./vendor/bin/phpstan analyse

.github/workflows/run_tests.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-latest]
12-
php: [7.4, 8.0]
13-
laravel: [8.*, 7.*]
12+
php: [8.3, 8.4]
13+
laravel: [11.*]
1414
dependency-version: [prefer-lowest, prefer-stable]
1515
include:
16-
- laravel: 8.*
17-
testbench: 6.*
18-
- laravel: 7.*
19-
testbench: 5.*
16+
- laravel: 11.*
17+
testbench: 9.*
2018

2119
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
2220

@@ -28,7 +26,7 @@ jobs:
2826
uses: shivammathur/setup-php@v2
2927
with:
3028
php-version: ${{ matrix.php }}
31-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
29+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
3230
coverage: none
3331

3432
- name: Install dependencies

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ The purpose of this package is to introduce local zero-downtime deployments into
77

88
## Requirements
99

10-
* Laravel 7 | 8
11-
* PHP ^7.4 | ^8.0
10+
* Laravel >= 11.x+
11+
* PHP >= 8.3
1212

1313
## Installation
1414

composer.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.4|^8.0"
14+
"php": "^8.3"
1515
},
1616
"require-dev": {
17-
"laravel/framework": "^8.12",
18-
"mockery/mockery": "^1.4",
19-
"phpunit/phpunit": "^9.3.3",
20-
"orchestra/testbench": "^6.9"
17+
"laravel/framework": "^11.0",
18+
"mockery/mockery": "^1.6.10",
19+
"phpunit/phpunit": "^10.5.35|^11.3.6",
20+
"orchestra/testbench": "^9.0",
21+
"laravel/pint": "^1.20",
22+
"phpstan/phpstan": "^2.1"
2123
},
2224
"autoload": {
2325
"psr-4": {

phpstan.neon

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
3+
paths:
4+
- src
5+
6+
# The level 9 is the highest level
7+
level: 5
8+
9+
universalObjectCratesClasses:
10+
- Illuminate\Http\Resources\Json\JsonResource

phpunit.xml

+21-25
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
colors="true">
6-
<testsuites>
7-
<testsuite name="Unit">
8-
<directory suffix="Test.php">./tests/Unit</directory>
9-
</testsuite>
10-
<testsuite name="Integration">
11-
<directory suffix="Test.php">./tests/Integration</directory>
12-
</testsuite>
13-
</testsuites>
14-
<coverage processUncoveredFiles="true">
15-
<include>
16-
<directory suffix=".php">./app</directory>
17-
</include>
18-
</coverage>
19-
<php>
20-
<env name="APP_ENV" value="testing"/>
21-
<env name="DB_DATABASE" value="sqlite"/>
22-
23-
<env name="ATM_DEPLOYMENT_LINK" value="deployment-link"/>
24-
<env name="ATM_BUILD" value="build"/>
25-
<env name="ATM_DEPLOYMENTS" value="deployments"/>
26-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
3+
<testsuites>
4+
<testsuite name="Unit">
5+
<directory suffix="Test.php">./tests/Unit</directory>
6+
</testsuite>
7+
<testsuite name="Feature">
8+
<directory suffix="Test.php">./tests/Feature</directory>
9+
</testsuite>
10+
</testsuites>
11+
<php>
12+
<env name="APP_ENV" value="testing"/>
13+
<env name="DB_DATABASE" value="sqlite"/>
14+
<env name="ATM_DEPLOYMENT_LINK" value="deployment-link"/>
15+
<env name="ATM_BUILD" value="build"/>
16+
<env name="ATM_DEPLOYMENTS" value="deployments"/>
17+
</php>
18+
<source>
19+
<include>
20+
<directory suffix=".php">./app</directory>
21+
</include>
22+
</source>
2723
</phpunit>

src/AtomicDeploymentsServiceProvider.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
class AtomicDeploymentsServiceProvider extends ServiceProvider
1212
{
13-
public function boot()
13+
public function boot(): void
1414
{
1515
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
1616
}
1717

18-
public function register()
18+
public function register(): void
1919
{
2020
$this->mergeConfigFrom(__DIR__.'/../config/atomic-deployments.php', 'atomic-deployments');
2121
$this->registerPublishables();
@@ -24,7 +24,7 @@ public function register()
2424
$this->app->bind(DeploymentInterface::class, config('atomic-deployments.deployment-class'));
2525

2626
$this->app->bind(AtomicDeploymentService::class, function ($app, $params) {
27-
if (empty($params) || (count($params) && !is_a($params[0], DeploymentInterface::class))) {
27+
if (empty($params) || (count($params) && ! is_a($params[0], DeploymentInterface::class))) {
2828
array_unshift($params, $app->make(DeploymentInterface::class));
2929
}
3030

src/Commands/DeployCommand.php

+59-41
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,82 @@
88
use JTMcC\AtomicDeployments\Services\AtomicDeploymentService;
99
use JTMcC\AtomicDeployments\Services\Deployment;
1010
use JTMcC\AtomicDeployments\Services\Output;
11+
use Throwable;
1112

1213
class DeployCommand extends BaseCommand
1314
{
14-
protected $signature = 'atomic-deployments:deploy
15-
{--hash= : Specify a previous deployments commit hash/deploy-dir to deploy }
16-
{--directory= : Define your deploy folder name. Defaults to current HEAD hash }
17-
{--dry-run : Test and log deployment steps }';
15+
protected $signature = 'atomic-deployments:deploy
16+
{--hash= : Specify a previous deployments commit hash/deploy-dir to deploy }
17+
{--directory= : Define your deploy folder name. Defaults to current HEAD hash }
18+
{--dry-run : Test and log deployment steps }';
1819

1920
protected $description = 'Deploy a clone of your latest build and attach symlink';
2021

21-
public function handle()
22+
public function handle(): void
2223
{
2324
Output::alert('Running Atomic Deployment');
2425

2526
$migrate = config('atomic-deployments.migrate', []);
2627
$dryRun = $this->option('dry-run');
2728

2829
if ($hash = $this->option('hash')) {
29-
Output::info("Updating symlink to previous build: {$hash}");
30-
31-
$deploymentModel = AtomicDeployment::successful()->where('commit_hash', $hash)->first();
32-
33-
if (!$deploymentModel || !$deploymentModel->hasDeployment) {
34-
Output::warn("Build not found for hash: {$hash}");
35-
} else {
36-
$atomicDeployment = AtomicDeploymentService::create(
37-
new Deployment($deploymentModel),
38-
$migrate,
39-
$dryRun
40-
);
41-
42-
try {
43-
$atomicDeployment->getDeployment()->link();
44-
$atomicDeployment->confirmSymbolicLink();
45-
DeploymentSuccessful::dispatch($atomicDeployment, $deploymentModel);
46-
} catch (\Throwable $e) {
47-
$atomicDeployment->fail();
48-
Output::throwable($e);
49-
}
50-
}
30+
$this->deployPreviousBuild($hash, $migrate, $dryRun);
5131
} else {
52-
$atomicDeployment = AtomicDeploymentService::create($migrate, $dryRun);
53-
54-
Output::info('Running Deployment...');
55-
56-
try {
57-
if ($deployDir = trim($this->option('directory'))) {
58-
Output::info("Deployment directory option set - Deployment will use directory: {$deployDir} ");
59-
$atomicDeployment->getDeployment()->setDirectory($deployDir);
60-
}
61-
$atomicDeployment->deploy(fn () => $atomicDeployment->cleanBuilds(config('atomic-deployments.build-limit')));
62-
} catch (\Throwable $e) {
63-
$atomicDeployment->fail();
64-
Output::throwable($e);
65-
}
32+
$this->deployCurrentBuild($migrate, $dryRun);
6633
}
6734

6835
Output::info('Finished');
6936
ConsoleOutput::line('');
7037
}
38+
39+
private function deployPreviousBuild(string $hash, array $migrate, bool $dryRun): void
40+
{
41+
Output::info("Updating symlink to previous build: {$hash}");
42+
43+
/** @var null|AtomicDeployment $deploymentModel */
44+
$deploymentModel = AtomicDeployment::successful()->where('commit_hash', $hash)->first();
45+
46+
if (! $deploymentModel?->has_deployment) {
47+
Output::warn("Build not found for hash: {$hash}");
48+
49+
return;
50+
}
51+
52+
$atomicDeployment = AtomicDeploymentService::create(
53+
new Deployment($deploymentModel),
54+
$migrate,
55+
$dryRun
56+
);
57+
58+
try {
59+
$atomicDeployment->getDeployment()->link();
60+
$atomicDeployment->confirmSymbolicLink();
61+
DeploymentSuccessful::dispatch($atomicDeployment, $deploymentModel);
62+
} catch (Throwable $e) {
63+
$atomicDeployment->fail();
64+
Output::throwable($e);
65+
}
66+
}
67+
68+
private function deployCurrentBuild(array $migrate, bool $dryRun): void
69+
{
70+
$atomicDeployment = AtomicDeploymentService::create($migrate, $dryRun);
71+
72+
Output::info('Running Deployment...');
73+
74+
try {
75+
if ($deployDir = trim($this->option('directory'))) {
76+
Output::info("Deployment directory option set - Deployment will use directory: {$deployDir}");
77+
$atomicDeployment->getDeployment()->setDirectory($deployDir);
78+
}
79+
80+
$atomicDeployment
81+
->deploy(
82+
fn () => $atomicDeployment->cleanBuilds(config('atomic-deployments.build-limit'))
83+
);
84+
} catch (Throwable $e) {
85+
$atomicDeployment->fail();
86+
Output::throwable($e);
87+
}
88+
}
7189
}

src/Commands/ListCommand.php

+20-17
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,44 @@
44

55
use JTMcC\AtomicDeployments\Helpers\ConsoleOutput;
66
use JTMcC\AtomicDeployments\Models\AtomicDeployment;
7-
use JTMcC\AtomicDeployments\Models\Enums\DeploymentStatus;
87

98
class ListCommand extends BaseCommand
109
{
1110
protected $signature = 'atomic-deployments:list';
1211

1312
protected $description = 'List currently available deployments';
1413

15-
public function handle()
14+
public function handle(): void
1615
{
1716
ConsoleOutput::line('');
1817
ConsoleOutput::alert('Available Deployments');
1918

20-
$deployments = AtomicDeployment::select(
21-
'id',
22-
'commit_hash',
23-
'deployment_path',
24-
'deployment_link',
25-
'deployment_status',
26-
'created_at',
27-
)->get()->map(function ($deployment) {
28-
$deployment->append('isCurrentlyDeployed');
29-
$deployment->deployment_status = DeploymentStatus::getNameFromValue($deployment->deployment_status);
30-
31-
return $deployment;
32-
});
33-
34-
if (!$deployments->count()) {
19+
$deployments = AtomicDeployment::query()
20+
->select([
21+
'id',
22+
'commit_hash',
23+
'deployment_path',
24+
'deployment_link',
25+
'deployment_status',
26+
'created_at',
27+
])
28+
->get()
29+
// @phpstan-ignore-next-line
30+
->map(function (AtomicDeployment $deployment) {
31+
$deployment->append('is_currently_deployed');
32+
33+
return $deployment;
34+
});
35+
36+
if (! $deployments->count()) {
3537
ConsoleOutput::info('No deployments found');
3638

3739
return;
3840
}
3941

4042
$titles = ['ID', 'Commit Hash', 'Path', 'SymLink', 'Status', 'Created', 'Live'];
4143

44+
// @phpstan-ignore-next-line
4245
ConsoleOutput::table($titles, $deployments);
4346
ConsoleOutput::line('');
4447
}

0 commit comments

Comments
 (0)