-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from 21TORR/hooks
- Loading branch information
Showing
14 changed files
with
258 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Torr\Hosting\Command; | ||
|
||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Torr\Hosting\Deployment\HookRunners; | ||
use Torr\Hosting\Deployment\TaskCli; | ||
|
||
#[AsCommand( | ||
"hosting:hook:build", | ||
description: "Runs the hooks for 'after the build finished'", | ||
aliases: ["hosting:run-tasks:post-build"], | ||
)] | ||
final class BuildHooksCommand extends Command | ||
{ | ||
private HookRunners $runners; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function __construct(HookRunners $runners) | ||
{ | ||
parent::__construct(); | ||
$this->runners = $runners; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function execute (InputInterface $input, OutputInterface $output) : int | ||
{ | ||
$io = new TaskCli($input, $output); | ||
$io->title("Run Build Hooks"); | ||
|
||
// @todo remove code block + alias in v4 | ||
if ("hosting:hook:build" !== $input->getFirstArgument()) | ||
{ | ||
$message = sprintf( | ||
"The command `%s` was deprecated. Use `hosting:hook:build` instead.", | ||
$input->getFirstArgument(), | ||
); | ||
trigger_deprecation( | ||
"21torr/hosting", | ||
"3.1.0", | ||
$message, | ||
); | ||
$io->caution($message); | ||
} | ||
|
||
$this->runners->runBuildHooks($io); | ||
|
||
$io->newLine(); | ||
$io->success("Ran all build hooks."); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Torr\Hosting\Command; | ||
|
||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Torr\Hosting\Deployment\HookRunners; | ||
use Torr\Hosting\Deployment\TaskCli; | ||
|
||
#[AsCommand( | ||
"hosting:hook:deploy", | ||
description: "Runs the hooks for 'after the deployment finished'", | ||
aliases: ["hosting:run-tasks:post-deploy"], | ||
)] | ||
final class DeployHooksCommand extends Command | ||
{ | ||
private HookRunners $runners; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function __construct(HookRunners $runners) | ||
{ | ||
parent::__construct(); | ||
$this->runners = $runners; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) : int | ||
{ | ||
$io = new TaskCli($input, $output); | ||
$io->title("Run Deploy Hooks"); | ||
|
||
// @todo remove code block + alias in v4 | ||
if ("hosting:hook:build" !== $input->getFirstArgument()) | ||
{ | ||
$message = sprintf( | ||
"The command `%s` was deprecated. Use `hosting:hook:deploy` instead.", | ||
$input->getFirstArgument(), | ||
); | ||
trigger_deprecation( | ||
"21torr/hosting", | ||
"3.1.0", | ||
$message, | ||
); | ||
$io->caution($message); | ||
} | ||
|
||
$this->runners->runDeployHooks($io); | ||
|
||
$io->newLine(); | ||
$io->success("Ran all deploy hooks."); | ||
|
||
return 0; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Torr\Hosting\Deployment; | ||
|
||
interface BuildHookInterface | ||
{ | ||
/** | ||
* Returns the label of the hook | ||
*/ | ||
public function getLabel () : string; | ||
|
||
/** | ||
* Runs the build hook | ||
*/ | ||
public function runPostBuild (TaskCli $io) : void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Torr\Hosting\Deployment; | ||
|
||
interface DeployHookInterface | ||
{ | ||
/** | ||
* Returns the label of the hook | ||
*/ | ||
public function getLabel () : string; | ||
|
||
/** | ||
* Runs the post deployment hook | ||
*/ | ||
public function runPostDeployment (TaskCli $io) : void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Torr\Hosting\Deployment; | ||
|
||
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; | ||
|
||
final readonly class HookRunners | ||
{ | ||
public const string TAG_BUILD_HOOK = "hosting.hook.build"; | ||
public const string TAG_DEPLOY_HOOK = "hosting.hook.deploy"; | ||
|
||
/** | ||
*/ | ||
public function __construct ( | ||
/** @var BuildHookInterface[] */ | ||
#[AutowireIterator(tag: self::TAG_BUILD_HOOK)] | ||
private iterable $buildHooks, | ||
/** @var DeployHookInterface[] */ | ||
#[AutowireIterator(tag: self::TAG_DEPLOY_HOOK)] | ||
private iterable $deployHooks, | ||
) {} | ||
|
||
/** | ||
*/ | ||
public function runBuildHooks (TaskCli $io) : void | ||
{ | ||
$first = true; | ||
|
||
foreach ($this->buildHooks as $runner) | ||
{ | ||
if ($first) | ||
{ | ||
$first = false; | ||
} | ||
else | ||
{ | ||
$io->newLine(2); | ||
} | ||
|
||
$io->section("Run Build Hook: <fg=magenta>{$runner->getLabel()}</>"); | ||
$runner->runPostBuild($io); | ||
} | ||
} | ||
|
||
/** | ||
*/ | ||
public function runDeployHooks (TaskCli $io) : void | ||
{ | ||
$first = true; | ||
|
||
foreach ($this->deployHooks as $runner) | ||
{ | ||
if ($first) | ||
{ | ||
$first = false; | ||
} | ||
else | ||
{ | ||
$io->newLine(2); | ||
} | ||
|
||
$io->section("Run Deploy Hook: <fg=magenta>{$runner->getLabel()}</>"); | ||
$runner->runPostDeployment($io); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.